FEATURE: add a specific flag reason when a post has been hidden

This commit is contained in:
Régis Hanol
2014-04-30 16:58:01 +02:00
parent 4b83a6f0a0
commit 11af466737
4 changed files with 25 additions and 10 deletions

View File

@ -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