FIX: don't add an automated message when *a* moderator already replied (as opposed to *the* moderator)

This commit is contained in:
Régis Hanol 2015-03-16 12:02:34 +01:00
parent ad8bf65053
commit df7c38dd51
2 changed files with 18 additions and 8 deletions

View file

@ -185,14 +185,14 @@ class PostAction < ActiveRecord::Base
def add_moderator_post_if_needed(moderator, disposition, delete_post=false) def add_moderator_post_if_needed(moderator, disposition, delete_post=false)
return if !SiteSetting.auto_respond_to_flag_actions return if !SiteSetting.auto_respond_to_flag_actions
return if related_post.nil? || related_post.topic.nil? return if related_post.nil? || related_post.topic.nil?
return if moderator_already_replied?(related_post.topic, moderator) return if staff_already_replied?(related_post.topic)
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), skip_notifications: true) related_post.topic.add_moderator_post(moderator, I18n.t(message_key), skip_notifications: true)
end end
def moderator_already_replied?(topic, moderator) def staff_already_replied?(topic)
topic.posts.where("user_id = :user_id OR post_type = :post_type", user_id: moderator.id, post_type: Post.types[:moderator_action]).exists? topic.posts.where("user_id IN (SELECT id FROM users WHERE moderator OR admin) OR post_type = :post_type", post_type: Post.types[:moderator_action]).exists?
end 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)

View file

@ -54,18 +54,28 @@ describe PostAction do
action.reload action.reload
expect(action.deleted_at).to eq(nil) expect(action.deleted_at).to eq(nil)
# Acting on the flag should post an automated status message # Acting on the flag should not post an automated status message (since a moderator already replied)
expect(topic.posts.count).to eq(2) expect(topic.posts.count).to eq(2)
PostAction.agree_flags!(post, admin) PostAction.agree_flags!(post, admin)
topic.reload topic.reload
expect(topic.posts.count).to eq(3) expect(topic.posts.count).to eq(2)
expect(topic.posts.last.post_type).to eq(Post.types[:moderator_action])
# Clearing the flags should not post another automated status message # Clearing the flags should not post an automated status message
PostAction.act(mod, post, PostActionType.types[:notify_moderators], message: "another special message") PostAction.act(mod, post, PostActionType.types[:notify_moderators], message: "another special message")
PostAction.clear_flags!(post, admin) PostAction.clear_flags!(post, admin)
topic.reload topic.reload
expect(topic.posts.count).to eq(3) expect(topic.posts.count).to eq(2)
# Acting on the flag should post an automated status message
another_post = create_post
action = PostAction.act(codinghorror, another_post, PostActionType.types[:notify_moderators], message: "foobar")
topic = action.related_post.topic
expect(topic.posts.count).to eq(1)
PostAction.agree_flags!(another_post, admin)
topic.reload
expect(topic.posts.count).to eq(2)
expect(topic.posts.last.post_type).to eq(Post.types[:moderator_action])
end end
describe 'notify_moderators' do describe 'notify_moderators' do