diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 7ec50e083a7..e17618f24f1 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -2241,6 +2241,20 @@ en: For additional guidance, please refer to our [community guidelines](%{base_url}/guidelines). + flags_agreed_and_post_deleted: + title: "Post deleted by a moderator" + subject_template: "Post deleted by a moderator due to flags" + text_body_template: | + Hello, + + This is an automated message from %{site_name} to let you know that your post was deleted. + + <%{base_url}%{url}> + + A moderator reviewed flags submitted by the community and agreed with them. + + Please review our [community guidelines](%{base_url}/guidelines) to avoid this happening again in the future. + usage_tips: text_body_template: | For a few quick tips on getting started as a new user, [check out this blog post](https://blog.discourse.org/2016/12/discourse-new-user-tips-and-tricks/). diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index 2493ba32407..bca03d45b93 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -196,6 +196,15 @@ class PostDestroyer end def agree_with_flags + if @post.is_flagged? + Jobs.enqueue( + :send_system_message, + user_id: @post.user.id, + message_type: :flags_agreed_and_post_deleted, + message_options: { url: @post.url } + ) + end + PostAction.agree_flags!(@post, @user, delete_post: true) end diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rb index 80c038777a2..59436b41af6 100644 --- a/spec/components/post_destroyer_spec.rb +++ b/spec/components/post_destroyer_spec.rb @@ -567,6 +567,8 @@ describe PostDestroyer do let!(:flag) { PostAction.act(moderator, second_post, PostActionType.types[:off_topic]) } it "should delete public post actions and agree with flags" do + SiteSetting.queue_jobs = false + second_post.expects(:update_flagged_posts_count) PostDestroyer.new(moderator, second_post).destroy @@ -580,6 +582,10 @@ describe PostDestroyer do second_post.reload expect(second_post.bookmark_count).to eq(0) expect(second_post.off_topic_count).to eq(1) + + notification = second_post.user.notifications.where(notification_type: Notification.types[:private_message]).last + expect(notification).to be_present + expect(notification.topic.title).to eq(I18n.t('system_messages.flags_agreed_and_post_deleted.subject_template')) end end diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index 07c9b49c063..0659c327682 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -233,6 +233,19 @@ describe PostAction do end end + describe "undo/redo repeatedly" do + it "doesn't create a second action for the same user/type" do + PostAction.act(codinghorror, post, PostActionType.types[:like]) + PostAction.remove_act(codinghorror, post, PostActionType.types[:like]) + PostAction.act(codinghorror, post, PostActionType.types[:like]) + expect(PostAction.where(post: post).with_deleted.count).to eq(1) + PostAction.remove_act(codinghorror, post, PostActionType.types[:like]) + + # Check that we don't lose consistency into negatives + expect(post.reload.like_count).to eq(0) + end + end + describe 'when a user likes something' do it 'should generate notifications correctly' do @@ -307,22 +320,7 @@ describe PostAction do expect(actual_count).to eq(1), "Expected likes_given to be 1 when removing '#{type_name}', but got #{actual_count}" end end - end - describe "undo/redo repeatedly" do - it "doesn't create a second action for the same user/type" do - PostAction.act(codinghorror, post, PostActionType.types[:like]) - PostAction.remove_act(codinghorror, post, PostActionType.types[:like]) - PostAction.act(codinghorror, post, PostActionType.types[:like]) - expect(PostAction.where(post: post).with_deleted.count).to eq(1) - PostAction.remove_act(codinghorror, post, PostActionType.types[:like]) - - # Check that we don't lose consistency into negatives - expect(post.reload.like_count).to eq(0) - end - end - - describe 'when a user likes something' do it 'should increase the like counts when a user votes' do expect { PostAction.act(codinghorror, post, PostActionType.types[:like])