From 11af466737c0090b7f0730eb479af210a4b17352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= <regis@hanol.fr> Date: Wed, 30 Apr 2014 16:58:01 +0200 Subject: [PATCH] FEATURE: add a specific flag reason when a post has been hidden --- app/controllers/admin/flags_controller.rb | 4 +++- app/models/post_action.rb | 22 ++++++++++++++-------- config/locales/server.en.yml | 7 +++++++ spec/models/post_action_spec.rb | 2 +- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/flags_controller.rb b/app/controllers/admin/flags_controller.rb index 99cc7d26e..f77474140 100644 --- a/app/controllers/admin/flags_controller.rb +++ b/app/controllers/admin/flags_controller.rb @@ -23,8 +23,9 @@ class Admin::FlagsController < Admin::AdminController def agree p = Post.find(params[:id]) + post_action_type = PostAction.post_action_type_for_post(p.id) PostAction.defer_flags!(p, current_user.id) - PostAction.hide_post!(p) + PostAction.hide_post!(p, post_action_type) render nothing: true end @@ -33,4 +34,5 @@ class Admin::FlagsController < Admin::AdminController PostAction.defer_flags!(p, current_user.id) render nothing: true end + end diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 03d977ae5..261b3dd58 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -77,8 +77,7 @@ class PostAction < ActiveRecord::Base actions = PostAction.where( defer: nil, post_id: post.id, - post_action_type_id: - PostActionType.flag_types.values, + post_action_type_id: PostActionType.flag_types.values, deleted_at: nil ) @@ -284,13 +283,13 @@ class PostAction < ActiveRecord::Base old_flags, new_flags = PostAction.flag_counts_for(post.id) if new_flags >= SiteSetting.flags_required_to_hide_post - hide_post!(post, guess_hide_reason(old_flags)) + hide_post!(post, post_action_type, guess_hide_reason(old_flags)) end end end - def self.hide_post!(post, reason=nil) + def self.hide_post!(post, post_action_type, reason=nil) return if post.hidden unless reason @@ -304,10 +303,12 @@ class PostAction < ActiveRecord::Base # inform user if post.user - SystemMessage.create(post.user, - :post_hidden, - url: post.url, - edit_delay: SiteSetting.cooldown_minutes_after_hiding_posts) + options = { + url: post.url, + edit_delay: SiteSetting.cooldown_minutes_after_hiding_posts, + flag_reason: I18n.t("flag_reasons.#{post_action_type}"), + } + SystemMessage.create(post.user, :post_hidden, options) end end @@ -317,6 +318,11 @@ class PostAction < ActiveRecord::Base Post.hidden_reasons[:flag_threshold_reached] end + def self.post_action_type_for_post(post_id) + post_action = PostAction.where(defer: nil, post_id: post_id, post_action_type_id: PostActionType.flag_types.values, deleted_at: nil).first + PostActionType.types[post_action.post_action_type_id] + end + protected def self.target_moderators diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index d186e0eda..5bea864a4 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1092,6 +1092,11 @@ en: one: "1 flag is waiting to be handled" other: "%{count} flags are waiting to be handled" + flag_reasons: + off_topic: "Your post was flagged as **off-topic**: the community thinks it does not fit into the topic, as currently defined by the title and the first post." + inappropriate: "Your post was flagged as **inappropriate**: the community thinks it is offensive, abusive, or a violation of [the community guidelines](/faq)." + spam: "Your post was flagged as **spam**: the community thinks it is an advertisement, not useful or relevant to the topic, but promotional in nature." + system_messages: post_hidden: subject_template: "Post hidden due to community flagging" @@ -1104,6 +1109,8 @@ en: ... was hidden due to community flagging. + %{flag_reason} + Keep in mind that multiple community members flagged this post before it was hidden, so **please consider how you might revise your post to reflect their feedback.** You can edit your post after %{edit_delay} minutes, and it will be automatically unhidden. This will increase your trust level. However, if the post is hidden by the community a second time, the moderators will be notified -- and there may be further action, including the possible suspension of your account. diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index 94f15074b..82cc5c0df 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -95,7 +95,7 @@ describe PostAction do post.reload post.hidden.should be_false - PostAction.hide_post!(post) + PostAction.hide_post!(post, PostActionType.types[:off_topic]) post.reload post.hidden.should be_true end