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;
},
@computed("model.has_title_badges")
canSelectTitle(hasTitleBadges) {
return this.siteSettings.enable_badges && hasTitleBadges;
@computed("model.allow_title", "model.has_badge", "model")
canSelectTitle(hasTitleBadges, hasBadge) {
return this.siteSettings.enable_badges && hasTitleBadges && hasBadge;
},
actions: {

View File

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

View File

@ -47,6 +47,9 @@ class BadgesController < ApplicationController
if user_badge && user_badge.notification
user_badge.notification.update_attributes read: true
end
if user_badge
@badge.has_badge = true
end
end
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
AutobiographerMinBioLength = 10
# used by serializer
attr_accessor :has_badge
def self.trigger_hash
Hash[*(
Badge::Trigger.constants.map { |k|

View File

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