A platform for community discussion. Free, open, simple.
add checks for staff and system user before sending flags_agreed_and_post_deleted message
Neil Lalonde417bcf7d2e3b
diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rbindex bca03d45b93..7d70b8ecb73 100644--- a/lib/post_destroyer.rb+++ b/lib/post_destroyer.rb@@ -196,7 +196,7 @@ class PostDestroyerenddef agree_with_flags- if @post.is_flagged?+ if @post.is_flagged? && @user.id > 0 && @user.staff?Jobs.enqueue(:send_system_message,user_id: @post.user.id,diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rbindex 59436b41af6..9c81366a0d1 100644--- a/spec/components/post_destroyer_spec.rb+++ b/spec/components/post_destroyer_spec.rb@@ -566,9 +566,11 @@ describe PostDestroyer dolet!(:bookmark) { PostAction.act(moderator, second_post, PostActionType.types[:bookmark]) }let!(:flag) { PostAction.act(moderator, second_post, PostActionType.types[:off_topic]) }- it "should delete public post actions and agree with flags" do+ before doSiteSetting.queue_jobs = false+ end+ it "should delete public post actions and agree with flags" dosecond_post.expects(:update_flagged_posts_count)PostDestroyer.new(moderator, second_post).destroy@@ -587,6 +589,23 @@ describe PostDestroyer doexpect(notification).to be_presentexpect(notification.topic.title).to eq(I18n.t('system_messages.flags_agreed_and_post_deleted.subject_template'))end++ it "should not send the flags_agreed_and_post_deleted message if it was deleted by system" do+ second_post.expects(:update_flagged_posts_count)+ PostDestroyer.new(Discourse.system_user, second_post).destroy+ expect(+ Topic.where(title: I18n.t('system_messages.flags_agreed_and_post_deleted.subject_template')).exists?+ ).to eq(false)+ end++ it "should not send the flags_agreed_and_post_deleted message if it was deleted by author" do+ SiteSetting.delete_removed_posts_after = 0+ second_post.expects(:update_flagged_posts_count)+ PostDestroyer.new(second_post.user, second_post).destroy+ expect(+ Topic.where(title: I18n.t('system_messages.flags_agreed_and_post_deleted.subject_template')).exists?+ ).to eq(false)+ endenddescribe "user actions" do