2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-04 08:47:37 +08:00

FIX: badge selector showing up for anon

This commit is contained in:
Sam 2017-10-30 16:21:05 +11:00
parent 0abc5f90cd
commit fab3e25101
5 changed files with 27 additions and 14 deletions

View file

@ -25,9 +25,9 @@ export default Ember.Controller.extend(BadgeSelectController, {
return username ? userCount : modelCount; return username ? userCount : modelCount;
}, },
@computed("model.has_title_badges") @computed("model.allow_title", "model.has_badge", "model")
canSelectTitle(hasTitleBadges) { canSelectTitle(hasTitleBadges, hasBadge) {
return this.siteSettings.enable_badges && hasTitleBadges; return this.siteSettings.enable_badges && hasTitleBadges && hasBadge;
}, },
actions: { actions: {

View file

@ -9,17 +9,13 @@
{{badge-card badge=model size="large" count=userBadges.grant_count}} {{badge-card badge=model size="large" count=userBadges.grant_count}}
<div class='badge-grant-info {{if hiddenSetTitle '' 'hidden'}}'> <div class='badge-grant-info {{if hiddenSetTitle '' 'hidden'}}'>
<div> <div>
{{#if model.allow_title}} {{#if canSelectTitle}}
<div class='grant-info-item'> <div class='grant-info-item'>
{{i18n 'badges.allow_title'}} {{i18n 'badges.allow_title'}}
{{#if userBadges}} {{d-button
{{#if model.allow_title}}
{{d-button
class='btn btn-small pad-left no-text' class='btn btn-small pad-left no-text'
action='toggleSetUserTitle' action='toggleSetUserTitle'
icon='pencil'}} icon='pencil'}}
{{/if}}
{{/if}}
</div> </div>
{{/if}} {{/if}}
{{#if model.multiple_grant}} {{#if model.multiple_grant}}
@ -29,10 +25,13 @@
{{/if}} {{/if}}
</div> </div>
</div> </div>
<div class='badge-set-title {{if hiddenSetTitle 'hidden' ''}}'>
{{badge-title selectableUserBadges=selectableUserBadges user=user}} {{#if canSelectTitle}}
<button class='btn btn-default close-btn' {{action "toggleSetUserTitle"}}>{{i18n 'close'}}</button> <div class='badge-set-title {{if hiddenSetTitle 'hidden' ''}}'>
</div> {{badge-title selectableUserBadges=selectableUserBadges user=user}}
<button class='btn btn-default close-btn' {{action "toggleSetUserTitle"}}>{{i18n 'close'}}</button>
</div>
{{/if}}
</div> </div>
{{#if userBadges}} {{#if userBadges}}

View file

@ -47,6 +47,9 @@ class BadgesController < ApplicationController
if user_badge && user_badge.notification if user_badge && user_badge.notification
user_badge.notification.update_attributes read: true user_badge.notification.update_attributes read: true
end end
if user_badge
@badge.has_badge = true
end
end end
serialized = MultiJson.dump(serialize_data(@badge, BadgeSerializer, root: "badge", include_long_description: true)) serialized = MultiJson.dump(serialize_data(@badge, BadgeSerializer, root: "badge", include_long_description: true))

View file

@ -65,6 +65,9 @@ class Badge < ActiveRecord::Base
# other consts # other consts
AutobiographerMinBioLength = 10 AutobiographerMinBioLength = 10
# used by serializer
attr_accessor :has_badge
def self.trigger_hash def self.trigger_hash
Hash[*( Hash[*(
Badge::Trigger.constants.map { |k| Badge::Trigger.constants.map { |k|

View file

@ -1,10 +1,18 @@
class BadgeSerializer < ApplicationSerializer class BadgeSerializer < ApplicationSerializer
attributes :id, :name, :description, :grant_count, :allow_title, attributes :id, :name, :description, :grant_count, :allow_title,
:multiple_grant, :icon, :image, :listable, :enabled, :badge_grouping_id, :multiple_grant, :icon, :image, :listable, :enabled, :badge_grouping_id,
:system, :long_description, :slug :system, :long_description, :slug, :has_badge
has_one :badge_type has_one :badge_type
def include_has_badge?
object.has_badge
end
def has_badge
true
end
def system def system
object.system? object.system?
end end