From a9f718fe57ce29bb4865ed25593b4a1edf45a555 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 19 Oct 2017 14:27:38 -0400 Subject: [PATCH] FIX: Custom flags didn't work when flagging a topic --- .../discourse/controllers/flag.js.es6 | 18 ++++++++---------- app/serializers/site_serializer.rb | 4 ++-- app/serializers/topic_flag_type_serializer.rb | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/flag.js.es6 b/app/assets/javascripts/discourse/controllers/flag.js.es6 index 947c8fe153b..00627a2ef80 100644 --- a/app/assets/javascripts/discourse/controllers/flag.js.es6 +++ b/app/assets/javascripts/discourse/controllers/flag.js.es6 @@ -53,19 +53,17 @@ export default Ember.Controller.extend(ModalFunctionality, { return flagsAvailable; } else { // flagging topic - const self = this, - lookup = Em.Object.create(); - - _.each(this.get("model.actions_summary"),function(a) { - a.flagTopic = self.get('model'); - a.actionType = self.site.topicFlagTypeById(a.id); - const actionSummary = ActionSummary.create(a); - lookup.set(a.actionType.get('name_key'), actionSummary); + let lookup = Em.Object.create(); + let model = this.get('model'); + model.get('actions_summary').forEach(a => { + a.flagTopic = model; + a.actionType = this.site.topicFlagTypeById(a.id); + lookup.set(a.actionType.get('name_key'), ActionSummary.create(a)); }); this.set('topicActionByName', lookup); - return this.site.get('topic_flag_types').filter(function(item) { - return _.any(self.get("model.actions_summary"), function(a) { + return this.site.get('topic_flag_types').filter(item => { + return _.any(this.get("model.actions_summary"), a => { return (a.id === item.get('id') && a.can_act); }); }); diff --git a/app/serializers/site_serializer.rb b/app/serializers/site_serializer.rb index 6216711d523..850a8dd8dd3 100644 --- a/app/serializers/site_serializer.rb +++ b/app/serializers/site_serializer.rb @@ -59,8 +59,8 @@ class SiteSerializer < ApplicationSerializer def topic_flag_types cache_fragment("post_action_flag_types_#{I18n.locale}") do - flags = PostActionType.ordered.where(id: PostActionType.topic_flag_types.values) - ActiveModel::ArraySerializer.new(flags, each_serializer: TopicFlagTypeSerializer).as_json + types = PostActionType.topic_flag_types.values.map { |id| PostActionType.new(id: id) } + ActiveModel::ArraySerializer.new(types, each_serializer: TopicFlagTypeSerializer).as_json end end diff --git a/app/serializers/topic_flag_type_serializer.rb b/app/serializers/topic_flag_type_serializer.rb index ee81618448b..c0ac6951bd0 100644 --- a/app/serializers/topic_flag_type_serializer.rb +++ b/app/serializers/topic_flag_type_serializer.rb @@ -3,7 +3,7 @@ class TopicFlagTypeSerializer < PostActionTypeSerializer protected def i18n(field, vars = nil) - key = "topic_flag_types.#{object.name_key}.#{field}" + key = "topic_flag_types.#{name_key}.#{field}" vars ? I18n.t(key, vars) : I18n.t(key) end