mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
FEATURE: add a specific flag reason when a post has been hidden
This commit is contained in:
@ -23,8 +23,9 @@ class Admin::FlagsController < Admin::AdminController
|
|||||||
|
|
||||||
def agree
|
def agree
|
||||||
p = Post.find(params[:id])
|
p = Post.find(params[:id])
|
||||||
|
post_action_type = PostAction.post_action_type_for_post(p.id)
|
||||||
PostAction.defer_flags!(p, current_user.id)
|
PostAction.defer_flags!(p, current_user.id)
|
||||||
PostAction.hide_post!(p)
|
PostAction.hide_post!(p, post_action_type)
|
||||||
render nothing: true
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -33,4 +34,5 @@ class Admin::FlagsController < Admin::AdminController
|
|||||||
PostAction.defer_flags!(p, current_user.id)
|
PostAction.defer_flags!(p, current_user.id)
|
||||||
render nothing: true
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -77,8 +77,7 @@ class PostAction < ActiveRecord::Base
|
|||||||
actions = PostAction.where(
|
actions = PostAction.where(
|
||||||
defer: nil,
|
defer: nil,
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
post_action_type_id:
|
post_action_type_id: PostActionType.flag_types.values,
|
||||||
PostActionType.flag_types.values,
|
|
||||||
deleted_at: nil
|
deleted_at: nil
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -284,13 +283,13 @@ class PostAction < ActiveRecord::Base
|
|||||||
old_flags, new_flags = PostAction.flag_counts_for(post.id)
|
old_flags, new_flags = PostAction.flag_counts_for(post.id)
|
||||||
|
|
||||||
if new_flags >= SiteSetting.flags_required_to_hide_post
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.hide_post!(post, reason=nil)
|
def self.hide_post!(post, post_action_type, reason=nil)
|
||||||
return if post.hidden
|
return if post.hidden
|
||||||
|
|
||||||
unless reason
|
unless reason
|
||||||
@ -304,10 +303,12 @@ class PostAction < ActiveRecord::Base
|
|||||||
|
|
||||||
# inform user
|
# inform user
|
||||||
if post.user
|
if post.user
|
||||||
SystemMessage.create(post.user,
|
options = {
|
||||||
:post_hidden,
|
|
||||||
url: post.url,
|
url: post.url,
|
||||||
edit_delay: SiteSetting.cooldown_minutes_after_hiding_posts)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -317,6 +318,11 @@ class PostAction < ActiveRecord::Base
|
|||||||
Post.hidden_reasons[:flag_threshold_reached]
|
Post.hidden_reasons[:flag_threshold_reached]
|
||||||
end
|
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
|
protected
|
||||||
|
|
||||||
def self.target_moderators
|
def self.target_moderators
|
||||||
|
@ -1092,6 +1092,11 @@ en:
|
|||||||
one: "1 flag is waiting to be handled"
|
one: "1 flag is waiting to be handled"
|
||||||
other: "%{count} flags are 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:
|
system_messages:
|
||||||
post_hidden:
|
post_hidden:
|
||||||
subject_template: "Post hidden due to community flagging"
|
subject_template: "Post hidden due to community flagging"
|
||||||
@ -1104,6 +1109,8 @@ en:
|
|||||||
|
|
||||||
... was hidden due to community flagging.
|
... 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.
|
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.
|
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.
|
||||||
|
@ -95,7 +95,7 @@ describe PostAction do
|
|||||||
post.reload
|
post.reload
|
||||||
post.hidden.should be_false
|
post.hidden.should be_false
|
||||||
|
|
||||||
PostAction.hide_post!(post)
|
PostAction.hide_post!(post, PostActionType.types[:off_topic])
|
||||||
post.reload
|
post.reload
|
||||||
post.hidden.should be_true
|
post.hidden.should be_true
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user