mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FIX: only allow badge title selection if it exists
This commit is contained in:
parent
e32e96dabb
commit
8fcc019ff8
4 changed files with 15 additions and 4 deletions
|
@ -32,7 +32,7 @@ export default Discourse.ObjectController.extend({
|
|||
canEditName: Discourse.computed.setting('enable_names'),
|
||||
|
||||
canSelectTitle: function() {
|
||||
return Discourse.SiteSettings.enable_badges && this.get('model.badge_count') > 0;
|
||||
return Discourse.SiteSettings.enable_badges && this.get('model.has_title_badges');
|
||||
}.property('model.badge_count'),
|
||||
|
||||
availableLocales: function() {
|
||||
|
|
|
@ -24,6 +24,7 @@ class User < ActiveRecord::Base
|
|||
has_many :user_actions, dependent: :destroy
|
||||
has_many :post_actions, dependent: :destroy
|
||||
has_many :user_badges, dependent: :destroy
|
||||
has_many :badges, through: :user_badges
|
||||
has_many :email_logs, dependent: :destroy
|
||||
has_many :post_timings
|
||||
has_many :topic_allowed_users, dependent: :destroy
|
||||
|
|
|
@ -42,7 +42,8 @@ class UserSerializer < BasicUserSerializer
|
|||
:suspend_reason,
|
||||
:suspended_till,
|
||||
:uploaded_avatar_id,
|
||||
:badge_count
|
||||
:badge_count,
|
||||
:has_title_badges
|
||||
|
||||
has_one :invited_by, embed: :object, serializer: BasicUserSerializer
|
||||
has_many :custom_groups, embed: :object, serializer: BasicGroupSerializer
|
||||
|
@ -75,7 +76,8 @@ class UserSerializer < BasicUserSerializer
|
|||
:disable_jump_reply,
|
||||
:gravatar_avatar_upload_id,
|
||||
:custom_avatar_upload_id,
|
||||
:custom_fields
|
||||
:custom_fields,
|
||||
:has_title_badges
|
||||
|
||||
###
|
||||
### ATTRIBUTES
|
||||
|
@ -230,4 +232,8 @@ class UserSerializer < BasicUserSerializer
|
|||
object.user_avatar.try(:custom_upload_id)
|
||||
end
|
||||
|
||||
def has_title_badges
|
||||
object.badges.where(allow_title: true).count > 0
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -11,8 +11,12 @@ describe UsersController do
|
|||
let!(:user) { log_in }
|
||||
|
||||
it 'returns success' do
|
||||
xhr :get, :show, username: user.username
|
||||
xhr :get, :show, username: user.username, format: :json
|
||||
response.should be_success
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
json["user"]["has_title_badges"].should == false
|
||||
|
||||
end
|
||||
|
||||
it "returns not found when the username doesn't exist" do
|
||||
|
|
Loading…
Reference in a new issue