From 838568cbc3706b9ceb0833cf5ce5b61dd685f697 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 17 Oct 2017 13:31:45 -0400 Subject: [PATCH] Refactor flag types for more customization --- .../admin/components/flag-counts.js.es6 | 10 --- .../admin/helpers/post-action-title.js.es6 | 12 +++ .../templates/components/flag-counts.hbs | 2 - .../templates/components/flagged-post.hbs | 2 +- .../admin/templates/flags-topics-index.hbs | 5 +- .../discourse/models/post-action-type.js.es6 | 8 +- app/models/post.rb | 4 +- app/models/post_action.rb | 25 ++++-- app/models/post_action_type.rb | 86 ++++++++++++++++--- app/models/report.rb | 2 +- app/models/user.rb | 4 +- .../flagged_topic_summary_serializer.rb | 2 +- .../post_action_type_serializer.rb | 24 +++++- app/serializers/post_serializer.rb | 2 +- app/serializers/site_serializer.rb | 5 +- app/services/spam_rule/auto_block.rb | 2 +- config/locales/client.en.yml | 22 ++--- lib/badge_queries.rb | 2 +- lib/flag_settings.rb | 42 +++++++++ lib/guardian/post_guardian.rb | 10 +-- lib/plugin/instance.rb | 9 ++ lib/post_revisor.rb | 2 +- plugins/discourse-narrative-bot/plugin.rb | 2 +- spec/components/flag_settings_spec.rb | 46 ++++++++++ spec/models/post_action_spec.rb | 2 +- spec/serializers/post_serializer_spec.rb | 3 +- 26 files changed, 253 insertions(+), 82 deletions(-) delete mode 100644 app/assets/javascripts/admin/components/flag-counts.js.es6 create mode 100644 app/assets/javascripts/admin/helpers/post-action-title.js.es6 create mode 100644 lib/flag_settings.rb create mode 100644 spec/components/flag_settings_spec.rb diff --git a/app/assets/javascripts/admin/components/flag-counts.js.es6 b/app/assets/javascripts/admin/components/flag-counts.js.es6 deleted file mode 100644 index 040207e6955..00000000000 --- a/app/assets/javascripts/admin/components/flag-counts.js.es6 +++ /dev/null @@ -1,10 +0,0 @@ -import computed from 'ember-addons/ember-computed-decorators'; - -export default Ember.Component.extend({ - classNames: ['flag-counts'], - - @computed('details.flag_type_id') - title(id) { - return I18n.t(`admin.flags.summary.action_type_${id}`, { count: 1 }); - } -}); diff --git a/app/assets/javascripts/admin/helpers/post-action-title.js.es6 b/app/assets/javascripts/admin/helpers/post-action-title.js.es6 new file mode 100644 index 00000000000..ced180d8bb8 --- /dev/null +++ b/app/assets/javascripts/admin/helpers/post-action-title.js.es6 @@ -0,0 +1,12 @@ +function postActionTitle([id, nameKey]) { + let title = I18n.t(`admin.flags.short_names.${nameKey}`, { defaultValue: null }); + + // TODO: We can remove this once other translations have been updated + if (!title) { + return I18n.t(`admin.flags.summary.action_type_${id}`, { count: 1 }); + } + + return title; +} + +export default Ember.Helper.helper(postActionTitle); diff --git a/app/assets/javascripts/admin/templates/components/flag-counts.hbs b/app/assets/javascripts/admin/templates/components/flag-counts.hbs index ff1f0118258..e69de29bb2d 100644 --- a/app/assets/javascripts/admin/templates/components/flag-counts.hbs +++ b/app/assets/javascripts/admin/templates/components/flag-counts.hbs @@ -1,2 +0,0 @@ -{{title}} -x{{details.count}} diff --git a/app/assets/javascripts/admin/templates/components/flagged-post.hbs b/app/assets/javascripts/admin/templates/components/flagged-post.hbs index 98ac4bf5e0b..4a832771a89 100644 --- a/app/assets/javascripts/admin/templates/components/flagged-post.hbs +++ b/app/assets/javascripts/admin/templates/components/flagged-post.hbs @@ -73,7 +73,7 @@ {{#each flaggedPost.post_actions as |postAction|}} {{#flag-user user=postAction.user date=postAction.created_at}}
- {{i18n (concat "admin.flags.summary.action_type_" postAction.post_action_type_id) count=1}} + {{post-action-title postAction.post_action_type_id postAction.name_key}}
{{/flag-user}} {{/each}} diff --git a/app/assets/javascripts/admin/templates/flags-topics-index.hbs b/app/assets/javascripts/admin/templates/flags-topics-index.hbs index 61ef340129d..d9fdf87066e 100644 --- a/app/assets/javascripts/admin/templates/flags-topics-index.hbs +++ b/app/assets/javascripts/admin/templates/flags-topics-index.hbs @@ -19,7 +19,10 @@ {{#each ft.flag_counts as |fc|}} - {{flag-counts details=fc}} +
+ {{post-action-title fc.post_action_type_id fc.name_key}} + x{{fc.count}} +
{{/each}} diff --git a/app/assets/javascripts/discourse/models/post-action-type.js.es6 b/app/assets/javascripts/discourse/models/post-action-type.js.es6 index 94a82ff5cb7..fb3125f0fa4 100644 --- a/app/assets/javascripts/discourse/models/post-action-type.js.es6 +++ b/app/assets/javascripts/discourse/models/post-action-type.js.es6 @@ -1,9 +1,7 @@ import RestModel from 'discourse/models/rest'; -const PostActionType = RestModel.extend({ - notCustomFlag: Em.computed.not('is_custom_flag') -}); - export const MAX_MESSAGE_LENGTH = 500; -export default PostActionType; +export default RestModel.extend({ + notCustomFlag: Em.computed.not('is_custom_flag') +}); diff --git a/app/models/post.rb b/app/models/post.rb index a70c69a915a..4a0f7df3916 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -411,11 +411,11 @@ class Post < ActiveRecord::Base end def is_flagged? - post_actions.where(post_action_type_id: PostActionType.flag_types.values, deleted_at: nil).count != 0 + post_actions.where(post_action_type_id: PostActionType.flag_types_without_custom.values, deleted_at: nil).count != 0 end def has_active_flag? - post_actions.active.where(post_action_type_id: PostActionType.flag_types.values).count != 0 + post_actions.active.where(post_action_type_id: PostActionType.flag_types_without_custom.values).count != 0 end def unhide! diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 2ee784f7af0..c5306c39495 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -44,7 +44,7 @@ class PostAction < ActiveRecord::Base def self.flag_count_by_date(start_date, end_date, category_id = nil) result = where('post_actions.created_at >= ? AND post_actions.created_at <= ?', start_date, end_date) - result = result.where(post_action_type_id: PostActionType.flag_types.values) + result = result.where(post_action_type_id: PostActionType.flag_types_without_custom.values) result = result.joins(post: :topic).where("topics.category_id = ?", category_id) if category_id result.group('date(post_actions.created_at)') .order('date(post_actions.created_at)') @@ -164,7 +164,7 @@ SQL if moderator.id == Discourse::SYSTEM_USER_ID PostActionType.auto_action_flag_types.values else - PostActionType.flag_types.values + PostActionType.flag_types_without_custom.values end actions = PostAction.where(post_id: post.id) @@ -179,8 +179,13 @@ SQL end # reset all cached counters - f = action_type_ids.map { |t| ["#{PostActionType.types[t]}_count", 0] } - Post.with_deleted.where(id: post.id).update_all(Hash[*f.flatten]) + cached = {} + action_type_ids.each do |atid| + column = "#{PostActionType.types[atid]}_count" + cached[column] = 0 if ActiveRecord::Base.connection.column_exists?(:posts, column) + end + + Post.with_deleted.where(id: post.id).update_all(cached) update_flagged_posts_count end @@ -188,7 +193,7 @@ SQL def self.defer_flags!(post, moderator, delete_post = false) actions = PostAction.active .where(post_id: post.id) - .where(post_action_type_id: PostActionType.flag_types.values) + .where(post_action_type_id: PostActionType.flag_types_without_custom.values) actions.each do |action| action.deferred_at = Time.zone.now @@ -355,7 +360,7 @@ SQL end def is_flag? - PostActionType.flag_types.values.include?(post_action_type_id) + !!PostActionType.flag_types[post_action_type_id] end def is_private_message? @@ -387,7 +392,7 @@ SQL end before_create do - post_action_type_ids = is_flag? ? PostActionType.flag_types.values : post_action_type_id + post_action_type_ids = is_flag? ? PostActionType.flag_types_without_custom.values : post_action_type_id raise AlreadyActed if PostAction.where(user_id: user_id) .where(post_id: post_id) .where(post_action_type_id: post_action_type_ids) @@ -445,7 +450,9 @@ SQL .sum("CASE WHEN users.moderator OR users.admin THEN #{SiteSetting.staff_like_weight} ELSE 1 END") Post.where(id: post_id).update_all ["like_count = :count, like_score = :score", count: count, score: score] else - Post.where(id: post_id).update_all ["#{column} = ?", count] + if ActiveRecord::Base.connection.column_exists?(:posts, column) + Post.where(id: post_id).update_all ["#{column} = ?", count] + end end topic_id = Post.with_deleted.where(id: post_id).pluck(:topic_id).first @@ -583,7 +590,7 @@ SQL end def self.post_action_type_for_post(post_id) - post_action = PostAction.find_by(deferred_at: nil, post_id: post_id, post_action_type_id: PostActionType.flag_types.values, deleted_at: nil) + post_action = PostAction.find_by(deferred_at: nil, post_id: post_id, post_action_type_id: PostActionType.flag_types_without_custom.values, deleted_at: nil) PostActionType.types[post_action.post_action_type_id] end diff --git a/app/models/post_action_type.rb b/app/models/post_action_type.rb index 6af07c53af6..9bb75363b74 100644 --- a/app/models/post_action_type.rb +++ b/app/models/post_action_type.rb @@ -1,5 +1,6 @@ require_dependency 'enum' require_dependency 'distributed_cache' +require_dependency 'flag_settings' class PostActionType < ActiveRecord::Base after_save :expire_cache @@ -14,23 +15,72 @@ class PostActionType < ActiveRecord::Base class << self + def flag_settings + unless @flag_settings + @flag_settings = FlagSettings.new + @flag_settings.add( + 3, + :off_topic, + notify_type: true, + auto_action_type: true + ) + @flag_settings.add( + 4, + :inappropriate, + topic_type: true, + notify_type: true, + auto_action_type: true + ) + @flag_settings.add( + 8, + :spam, + topic_type: true, + notify_type: true, + auto_action_type: true + ) + @flag_settings.add( + 6, + :notify_user, + topic_type: true, + notify_type: true, + custom_type: true + ) + @flag_settings.add( + 7, + :notify_moderators, + topic_type: true, + notify_type: true, + custom_type: true + ) + end + + @flag_settings + end + + def replace_flag_settings(settings) + @flag_settings = settings + @types = nil + end + def ordered order('position asc') end def types - @types ||= Enum.new(bookmark: 1, - like: 2, - off_topic: 3, - inappropriate: 4, - vote: 5, - notify_user: 6, - notify_moderators: 7, - spam: 8) + unless @types + @types = Enum.new( + bookmark: 1, + like: 2, + vote: 5 + ) + @types.merge!(flag_settings.flag_types) + end + + @types end def auto_action_flag_types - @auto_action_flag_types ||= flag_types.except(:notify_user, :notify_moderators) + flag_settings.auto_action_types end def public_types @@ -41,17 +91,29 @@ class PostActionType < ActiveRecord::Base @public_type_ids ||= public_types.values end + def flag_types_without_custom + flag_settings.without_custom_types + end + def flag_types - @flag_types ||= types.only(:off_topic, :spam, :inappropriate, :notify_moderators) + flag_settings.flag_types end # flags resulting in mod notifications def notify_flag_type_ids - @notify_flag_type_ids ||= types.only(:off_topic, :spam, :inappropriate, :notify_moderators).values + notify_flag_types.values + end + + def notify_flag_types + flag_settings.notify_types end def topic_flag_types - @topic_flag_types ||= types.only(:spam, :inappropriate, :notify_moderators) + flag_settings.topic_flag_types + end + + def custom_types + flag_settings.custom_types end def is_flag?(sym) diff --git a/app/models/report.rb b/app/models/report.rb index 8144df648b9..83f046cc36d 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -175,7 +175,7 @@ class Report # Post action counts: def self.report_flags(report) basic_report_about report, PostAction, :flag_count_by_date, report.start_date, report.end_date, report.category_id - countable = PostAction.where(post_action_type_id: PostActionType.flag_types.values) + countable = PostAction.where(post_action_type_id: PostActionType.flag_types_without_custom.values) countable = countable.joins(post: :topic).where("topics.category_id = ?", report.category_id) if report.category_id add_counts report, countable, 'post_actions.created_at' end diff --git a/app/models/user.rb b/app/models/user.rb index c70890af63e..c52b456ce45 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -615,7 +615,7 @@ class User < ActiveRecord::Base end def flags_given_count - PostAction.where(user_id: id, post_action_type_id: PostActionType.flag_types.values).count + PostAction.where(user_id: id, post_action_type_id: PostActionType.flag_types_without_custom.values).count end def warnings_received_count @@ -623,7 +623,7 @@ class User < ActiveRecord::Base end def flags_received_count - posts.includes(:post_actions).where('post_actions.post_action_type_id' => PostActionType.flag_types.values).count + posts.includes(:post_actions).where('post_actions.post_action_type_id' => PostActionType.flag_types_without_custom.values).count end def private_topics_count diff --git a/app/serializers/flagged_topic_summary_serializer.rb b/app/serializers/flagged_topic_summary_serializer.rb index de770fef25b..f29c365a468 100644 --- a/app/serializers/flagged_topic_summary_serializer.rb +++ b/app/serializers/flagged_topic_summary_serializer.rb @@ -15,7 +15,7 @@ class FlaggedTopicSummarySerializer < ActiveModel::Serializer def flag_counts object.flag_counts.map do |k, v| - { flag_type_id: k, count: v } + { post_action_type_id: k, count: v, name_key: PostActionType.types[k] } end end diff --git a/app/serializers/post_action_type_serializer.rb b/app/serializers/post_action_type_serializer.rb index e0bf6f7c971..718c84a5b7e 100644 --- a/app/serializers/post_action_type_serializer.rb +++ b/app/serializers/post_action_type_serializer.rb @@ -2,13 +2,25 @@ require_dependency 'configurable_urls' class PostActionTypeSerializer < ApplicationSerializer - attributes :name_key, :name, :description, :short_description, :long_form, :is_flag, :icon, :id, :is_custom_flag + attributes( + :id, + :name_key, + :name, + :description, + :short_description, + :long_form, + :is_flag, + :is_custom_flag + ) include ConfigurableUrls def is_custom_flag - object.id == PostActionType.types[:notify_user] || - object.id == PostActionType.types[:notify_moderators] + !!PostActionType.custom_types[object.id] + end + + def is_flag + !!PostActionType.flag_types[object.id] end def name @@ -27,10 +39,14 @@ class PostActionTypeSerializer < ApplicationSerializer i18n('short_description', tos_url: tos_path) end + def name_key + PostActionType.types[object.id] + end + protected def i18n(field, vars = nil) - key = "post_action_types.#{object.name_key}.#{field}" + key = "post_action_types.#{name_key}.#{field}" vars ? I18n.t(key, vars) : I18n.t(key) end diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index e06617b0f16..d756ee1dd31 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -246,7 +246,7 @@ class PostSerializer < BasicPostSerializer # The following only applies if you're logged in if summary[:can_act] && scope.current_user.present? summary[:can_defer_flags] = true if scope.is_staff? && - PostActionType.flag_types.values.include?(id) && + PostActionType.flag_types_without_custom.values.include?(id) && active_flags.present? && active_flags.has_key?(id) && active_flags[id].count > 0 end diff --git a/app/serializers/site_serializer.rb b/app/serializers/site_serializer.rb index ecd93e02ae9..6216711d523 100644 --- a/app/serializers/site_serializer.rb +++ b/app/serializers/site_serializer.rb @@ -52,13 +52,14 @@ class SiteSerializer < ApplicationSerializer def post_action_types cache_fragment("post_action_types_#{I18n.locale}") do - ActiveModel::ArraySerializer.new(PostActionType.ordered).as_json + types = PostActionType.types.values.map { |id| PostActionType.new(id: id) } + ActiveModel::ArraySerializer.new(types).as_json end end def topic_flag_types cache_fragment("post_action_flag_types_#{I18n.locale}") do - flags = PostActionType.ordered.where(name_key: ['inappropriate', 'spam', 'notify_moderators']) + flags = PostActionType.ordered.where(id: PostActionType.topic_flag_types.values) ActiveModel::ArraySerializer.new(flags, each_serializer: TopicFlagTypeSerializer).as_json end diff --git a/app/services/spam_rule/auto_block.rb b/app/services/spam_rule/auto_block.rb index bf855bea87e..fd2cb3357fe 100644 --- a/app/services/spam_rule/auto_block.rb +++ b/app/services/spam_rule/auto_block.rb @@ -66,7 +66,7 @@ class SpamRule::AutoBlock def flagged_post_ids Post.where(user_id: @user.id) - .where('spam_count > ? OR off_topic_count > ? OR inappropriate_count > ?', 0, 0, 0) + .where('spam_count > 0 OR off_topic_count > 0 OR inappropriate_count > 0') .pluck(:id) end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index d5e17d752d7..422283e4008 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -2666,22 +2666,12 @@ en: users: "Users" last_flagged: "Last Flagged" - summary: - action_type_3: - one: "off-topic" - other: "off-topic x{{count}}" - action_type_4: - one: "inappropriate" - other: "inappropriate x{{count}}" - action_type_6: - one: "custom" - other: "custom x{{count}}" - action_type_7: - one: "custom" - other: "custom x{{count}}" - action_type_8: - one: "spam" - other: "spam x{{count}}" + short_names: + off_topic: "off-topic" + inappropriate: "inappropriate" + spam: "spam" + notify_user: "custom" + notify_moderators: "custom" groups: primary: "Primary Group" diff --git a/lib/badge_queries.rb b/lib/badge_queries.rb index dd70192c08b..9bba4dca8c0 100644 --- a/lib/badge_queries.rb +++ b/lib/badge_queries.rb @@ -70,7 +70,7 @@ SQL SELECT pa.user_id, min(pa.id) id FROM post_actions pa JOIN badge_posts p on p.id = pa.post_id - WHERE post_action_type_id IN (#{PostActionType.flag_types.values.join(",")}) AND + WHERE post_action_type_id IN (#{PostActionType.flag_types_without_custom.values.join(",")}) AND (:backfill OR pa.post_id IN (:post_ids) ) GROUP BY pa.user_id ) x diff --git a/lib/flag_settings.rb b/lib/flag_settings.rb new file mode 100644 index 00000000000..3fb700d7cc6 --- /dev/null +++ b/lib/flag_settings.rb @@ -0,0 +1,42 @@ +class FlagSettings + + attr_reader( + :without_custom_types, + :notify_types, + :topic_flag_types, + :auto_action_types, + :custom_types + ) + + def initialize + @all_flag_types = Enum.new + @topic_flag_types = Enum.new + @notify_types = Enum.new + @auto_action_types = Enum.new + @custom_types = Enum.new + @without_custom_types = Enum.new + end + + def add(id, name, details = nil) + details ||= {} + + @all_flag_types[name] = id + @topic_flag_types[name] = id if !!details[:topic_type] + @notify_types[name] = id if !!details[:notify_type] + @auto_action_types[name] = id if !!details[:auto_action_type] + if !!details[:custom_type] + @custom_types[name] = id + else + @without_custom_types[name] = id + end + end + + def is_flag?(key) + @all_flag_types.valid?(key) + end + + def flag_types + @all_flag_types + end + +end diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb index cd274e0d056..83139fc8519 100644 --- a/lib/guardian/post_guardian.rb +++ b/lib/guardian/post_guardian.rb @@ -10,13 +10,14 @@ module PostGuardian return false if (action_key == :notify_user && !is_staff? && opts[:is_warning].present? && opts[:is_warning] == 'true') taken = opts[:taken_actions].try(:keys).to_a - is_flag = PostActionType.is_flag?(action_key) + is_flag = PostActionType.flag_types_without_custom[action_key] already_taken_this_action = taken.any? && taken.include?(PostActionType.types[action_key]) - already_did_flagging = taken.any? && (taken & PostActionType.flag_types.values).any? + already_did_flagging = taken.any? && (taken & PostActionType.flag_types_without_custom.values).any? result = if authenticated? && post && !@user.anonymous? - return false if action_key == :notify_moderators && !SiteSetting.enable_private_messages + return false if [:notify_user, :notify_moderators].include?(action_key) && + !SiteSetting.enable_private_messages? # we allow flagging for trust level 1 and higher # always allowed for private messages @@ -37,9 +38,6 @@ module PostGuardian # new users can't notify_user because they are not allowed to send private messages not(action_key == :notify_user && !@user.has_trust_level?(SiteSetting.min_trust_to_send_messages)) && - # can't send private messages if they're disabled globally - not(action_key == :notify_user && !SiteSetting.enable_private_messages) && - # no voting more than once on single vote topics not(action_key == :vote && opts[:voted_in_topic] && post.topic.has_meta_data_boolean?(:single_vote)) end diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb index db1c866baf1..721441229f8 100644 --- a/lib/plugin/instance.rb +++ b/lib/plugin/instance.rb @@ -90,6 +90,15 @@ class Plugin::Instance end end + def replace_flags + settings = ::FlagSettings.new + yield settings + + reloadable_patch do |plugin| + ::PostActionType.replace_flag_settings(settings) if plugin.enabled? + end + end + def whitelist_staff_user_custom_field(field) reloadable_patch do |plugin| ::User.register_plugin_staff_custom_field(field, plugin) if plugin.enabled? diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index f443a64d93b..01f14a1f80a 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -316,7 +316,7 @@ class PostRevisor def remove_flags_and_unhide_post return unless editing_a_flagged_and_hidden_post? - @post.post_actions.where(post_action_type_id: PostActionType.flag_types.values).each do |action| + @post.post_actions.where(post_action_type_id: PostActionType.flag_types_without_custom.values).each do |action| action.remove_act!(Discourse.system_user) end @post.unhide! diff --git a/plugins/discourse-narrative-bot/plugin.rb b/plugins/discourse-narrative-bot/plugin.rb index efca56e7e83..1f2d04984d2 100644 --- a/plugins/discourse-narrative-bot/plugin.rb +++ b/plugins/discourse-narrative-bot/plugin.rb @@ -184,7 +184,7 @@ after_initialize do if self.user.enqueue_narrative_bot_job? input = case self.post_action_type_id - when *PostActionType.flag_types.values + when *PostActionType.flag_types_without_custom.values :flag when PostActionType.types[:like] :like diff --git a/spec/components/flag_settings_spec.rb b/spec/components/flag_settings_spec.rb new file mode 100644 index 00000000000..e82d5728140 --- /dev/null +++ b/spec/components/flag_settings_spec.rb @@ -0,0 +1,46 @@ +require 'rails_helper' +require 'flag_settings' + +RSpec.describe FlagSettings do + + let(:settings) { FlagSettings.new } + + describe 'add' do + it 'will add a type' do + settings.add(3, :off_topic) + expect(settings.flag_types).to include(:off_topic) + expect(settings.is_flag?(:off_topic)).to eq(true) + expect(settings.is_flag?(:vote)).to eq(false) + + expect(settings.topic_flag_types).to be_empty + expect(settings.notify_types).to be_empty + expect(settings.auto_action_types).to be_empty + end + + it 'will add a topic type' do + settings.add(4, :inappropriate, topic_type: true) + expect(settings.flag_types).to include(:inappropriate) + expect(settings.topic_flag_types).to include(:inappropriate) + expect(settings.without_custom_types).to include(:inappropriate) + end + + it 'will add a notify type' do + settings.add(3, :off_topic, notify_type: true) + expect(settings.flag_types).to include(:off_topic) + expect(settings.notify_types).to include(:off_topic) + end + + it 'will add an auto action type' do + settings.add(7, :notify_moderators, auto_action_type: true) + expect(settings.flag_types).to include(:notify_moderators) + expect(settings.auto_action_types).to include(:notify_moderators) + end + + it 'will add a custom type' do + settings.add(7, :notify_user, custom_type: true) + expect(settings.flag_types).to include(:notify_user) + expect(settings.custom_types).to include(:notify_user) + expect(settings.without_custom_types).to be_empty + end + end +end diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index d1463b22c3c..d54df929130 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -532,7 +532,7 @@ describe PostAction do it "prevents user to act twice at the same time" do # flags are already being tested - all_types_except_flags = PostActionType.types.except(PostActionType.flag_types) + all_types_except_flags = PostActionType.types.except(PostActionType.flag_types_without_custom) all_types_except_flags.values.each do |action| expect do PostAction.act(eviltrout, post, action) diff --git a/spec/serializers/post_serializer_spec.rb b/spec/serializers/post_serializer_spec.rb index 50f9f08c659..5e75727cfce 100644 --- a/spec/serializers/post_serializer_spec.rb +++ b/spec/serializers/post_serializer_spec.rb @@ -9,8 +9,7 @@ describe PostSerializer do let(:admin) { Fabricate(:admin) } let(:acted_ids) { PostActionType.public_types.values - .concat([:notify_user, :spam] - .map { |k| PostActionType.types[k] }) + .concat([:notify_user, :spam].map { |k| PostActionType.types[k] }) } def visible_actions_for(user)