mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FIX: don't add an automated message when *a* moderator already replied (as opposed to *the* moderator)
This commit is contained in:
parent
ad8bf65053
commit
df7c38dd51
2 changed files with 18 additions and 8 deletions
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue