FIX: only allow badge title selection if it exists

This commit is contained in:
Sam 2014-07-09 15:31:49 +10:00
parent e32e96dabb
commit 8fcc019ff8
4 changed files with 15 additions and 4 deletions

View file

@ -32,7 +32,7 @@ export default Discourse.ObjectController.extend({
canEditName: Discourse.computed.setting('enable_names'), canEditName: Discourse.computed.setting('enable_names'),
canSelectTitle: function() { 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'), }.property('model.badge_count'),
availableLocales: function() { availableLocales: function() {

View file

@ -24,6 +24,7 @@ class User < ActiveRecord::Base
has_many :user_actions, dependent: :destroy has_many :user_actions, dependent: :destroy
has_many :post_actions, dependent: :destroy has_many :post_actions, dependent: :destroy
has_many :user_badges, dependent: :destroy has_many :user_badges, dependent: :destroy
has_many :badges, through: :user_badges
has_many :email_logs, dependent: :destroy has_many :email_logs, dependent: :destroy
has_many :post_timings has_many :post_timings
has_many :topic_allowed_users, dependent: :destroy has_many :topic_allowed_users, dependent: :destroy

View file

@ -42,7 +42,8 @@ class UserSerializer < BasicUserSerializer
:suspend_reason, :suspend_reason,
:suspended_till, :suspended_till,
:uploaded_avatar_id, :uploaded_avatar_id,
:badge_count :badge_count,
:has_title_badges
has_one :invited_by, embed: :object, serializer: BasicUserSerializer has_one :invited_by, embed: :object, serializer: BasicUserSerializer
has_many :custom_groups, embed: :object, serializer: BasicGroupSerializer has_many :custom_groups, embed: :object, serializer: BasicGroupSerializer
@ -75,7 +76,8 @@ class UserSerializer < BasicUserSerializer
:disable_jump_reply, :disable_jump_reply,
:gravatar_avatar_upload_id, :gravatar_avatar_upload_id,
:custom_avatar_upload_id, :custom_avatar_upload_id,
:custom_fields :custom_fields,
:has_title_badges
### ###
### ATTRIBUTES ### ATTRIBUTES
@ -230,4 +232,8 @@ class UserSerializer < BasicUserSerializer
object.user_avatar.try(:custom_upload_id) object.user_avatar.try(:custom_upload_id)
end end
def has_title_badges
object.badges.where(allow_title: true).count > 0
end
end end

View file

@ -11,8 +11,12 @@ describe UsersController do
let!(:user) { log_in } let!(:user) { log_in }
it 'returns success' do it 'returns success' do
xhr :get, :show, username: user.username xhr :get, :show, username: user.username, format: :json
response.should be_success response.should be_success
json = JSON.parse(response.body)
json["user"]["has_title_badges"].should == false
end end
it "returns not found when the username doesn't exist" do it "returns not found when the username doesn't exist" do