FEATURE: acting on a flag should not post an automated status message if you already replied to it

This commit is contained in:
Régis Hanol 2014-08-18 17:00:14 +02:00
parent 0d72b670f8
commit d7b1313d5e
2 changed files with 9 additions and 5 deletions

View file

@ -155,13 +155,19 @@ class PostAction < ActiveRecord::Base
end end
def add_moderator_post_if_needed(moderator, disposition, delete_post=false) def add_moderator_post_if_needed(moderator, disposition, delete_post=false)
return unless related_post return if related_post.nil?
return if related_post.topic.posts.where(post_type: Post.types[:moderator_action]).exists? return if moderator_already_replied?(related_post.topic, moderator)
message_key = "flags_dispositions.#{disposition}" message_key = "flags_dispositions.#{disposition}"
message_key << "_and_deleted" if delete_post message_key << "_and_deleted" if delete_post
related_post.topic.add_moderator_post(moderator, I18n.t(message_key)) related_post.topic.add_moderator_post(moderator, I18n.t(message_key))
end end
def moderator_already_replied?(topic, moderator)
topic.posts
.where("user_id = :user_id OR post_type = :post_type", user_id: moderator.id, post_type: Post.types[:moderator_action])
.exists?
end
def self.create_message_for_post_action(user, post, post_action_type_id, opts) def self.create_message_for_post_action(user, post, post_action_type_id, opts)
post_action_type = PostActionType.types[post_action_type_id] post_action_type = PostActionType.types[post_action_type_id]

View file

@ -43,9 +43,7 @@ describe PostAction do
topic.topic_users(true).map(&:notification_level).uniq.should == [TopicUser.notification_levels[:watching]] topic.topic_users(true).map(&:notification_level).uniq.should == [TopicUser.notification_levels[:watching]]
# reply to PM should not clear flag # reply to PM should not clear flag
p = PostCreator.new(mod, topic_id: posts[0].topic_id, raw: "This is my test reply to the user, it should clear flags") PostCreator.new(mod, topic_id: posts[0].topic_id, raw: "This is my test reply to the user, it should clear flags").create
p.create
action.reload action.reload
action.deleted_at.should be_nil action.deleted_at.should be_nil