Revert "FIX: do not agree flags by default when deleting posts"

This reverts commit cb6fc8057b.
This commit is contained in:
Arpit Jalan 2018-11-28 10:21:11 +05:30
parent 6acabec423
commit 851ef14096
3 changed files with 27 additions and 36 deletions

View File

@ -86,7 +86,8 @@ class Admin::FlagsController < Admin::AdminController
restore_post = params[:action_on_post] == "restore" restore_post = params[:action_on_post] == "restore"
if delete_post if delete_post
destroy_post(post, agree_flags: true) # PostDestroy calls PostAction.agree_flags!
destroy_post(post)
elsif restore_post elsif restore_post
PostAction.agree_flags!(post, current_user, delete_post) PostAction.agree_flags!(post, current_user, delete_post)
PostDestroyer.new(current_user, post).recover PostDestroyer.new(current_user, post).recover
@ -137,12 +138,12 @@ class Admin::FlagsController < Admin::AdminController
private private
def destroy_post(post, agree_flags: false) def destroy_post(post)
if post.is_first_post? if post.is_first_post?
topic = Topic.find_by(id: post.topic_id) topic = Topic.find_by(id: post.topic_id)
guardian.ensure_can_delete!(topic) if topic.present? guardian.ensure_can_delete!(topic) if topic.present?
end end
PostDestroyer.new(current_user, post, agree_flags: agree_flags).destroy PostDestroyer.new(current_user, post).destroy
end end
end end

View File

@ -147,11 +147,7 @@ class PostDestroyer
update_user_counts update_user_counts
TopicUser.update_post_action_cache(post_id: @post.id) TopicUser.update_post_action_cache(post_id: @post.id)
DB.after_commit do DB.after_commit do
if @opts[:agree_flags] agree_with_flags
agree_with_flags
else
defer_flags
end
end end
end end
@ -229,7 +225,7 @@ class PostDestroyer
if @post.has_active_flag? && @user.id > 0 && @user.staff? if @post.has_active_flag? && @user.id > 0 && @user.staff?
Jobs.enqueue( Jobs.enqueue(
:send_system_message, :send_system_message,
user_id: @post.user_id, user_id: @post.user.id,
message_type: :flags_agreed_and_post_deleted, message_type: :flags_agreed_and_post_deleted,
message_options: { message_options: {
url: @post.url, url: @post.url,
@ -241,11 +237,8 @@ class PostDestroyer
} }
) )
end end
PostAction.agree_flags!(@post, @user, delete_post: true)
end
def defer_flags PostAction.agree_flags!(@post, @user, delete_post: true)
PostAction.defer_flags!(@post, @user, delete_post: true)
end end
def trash_user_actions def trash_user_actions

View File

@ -632,13 +632,13 @@ describe PostDestroyer do
let!(:flag) { PostAction.act(moderator, second_post, PostActionType.types[:off_topic]) } let!(:flag) { PostAction.act(moderator, second_post, PostActionType.types[:off_topic]) }
before do before do
Jobs::SendSystemMessage.clear SiteSetting.queue_jobs = false
end end
it "should delete public post actions and agree with flags" do it "should delete public post actions and agree with flags" do
second_post.expects(:update_flagged_posts_count) second_post.expects(:update_flagged_posts_count)
PostDestroyer.new(moderator, second_post, agree_flags: true).destroy PostDestroyer.new(moderator, second_post).destroy
expect(PostAction.find_by(id: bookmark.id)).to eq(nil) expect(PostAction.find_by(id: bookmark.id)).to eq(nil)
@ -650,39 +650,36 @@ describe PostDestroyer do
expect(second_post.bookmark_count).to eq(0) expect(second_post.bookmark_count).to eq(0)
expect(second_post.off_topic_count).to eq(1) expect(second_post.off_topic_count).to eq(1)
expect(Jobs::SendSystemMessage.jobs.size).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
it "should not send the flags_agreed_and_post_deleted message if it was deleted by system" do it "should not send the flags_agreed_and_post_deleted message if it was deleted by system" do
expect(PostAction.flagged_posts_count).to eq(1) second_post.expects(:update_flagged_posts_count)
PostDestroyer.new(Discourse.system_user, second_post, agree_flags: true).destroy PostDestroyer.new(Discourse.system_user, second_post).destroy
expect(Jobs::SendSystemMessage.jobs.size).to eq(0) expect(
expect(PostAction.flagged_posts_count).to eq(0) Topic.where(title: I18n.t('system_messages.flags_agreed_and_post_deleted.subject_template')).exists?
).to eq(false)
end end
it "should not send the flags_agreed_and_post_deleted message if it was deleted by author" do it "should not send the flags_agreed_and_post_deleted message if it was deleted by author" do
SiteSetting.delete_removed_posts_after = 0 SiteSetting.delete_removed_posts_after = 0
expect(PostAction.flagged_posts_count).to eq(1) second_post.expects(:update_flagged_posts_count)
PostDestroyer.new(second_post.user, second_post, agree_flags: true).destroy PostDestroyer.new(second_post.user, second_post).destroy
expect(Jobs::SendSystemMessage.jobs.size).to eq(0) expect(
expect(PostAction.flagged_posts_count).to eq(0) Topic.where(title: I18n.t('system_messages.flags_agreed_and_post_deleted.subject_template')).exists?
).to eq(false)
end end
it "should not send the flags_agreed_and_post_deleted message if flags were deferred" do it "should not send the flags_agreed_and_post_deleted message if flags were deferred" do
expect(PostAction.flagged_posts_count).to eq(1) second_post.expects(:update_flagged_posts_count)
PostAction.defer_flags!(second_post, moderator) PostAction.defer_flags!(second_post, moderator)
second_post.reload second_post.reload
expect(PostAction.flagged_posts_count).to eq(0) PostDestroyer.new(moderator, second_post).destroy
expect(
PostDestroyer.new(moderator, second_post, agree_flags: true).destroy Topic.where(title: I18n.t('system_messages.flags_agreed_and_post_deleted.subject_template')).exists?
expect(Jobs::SendSystemMessage.jobs.size).to eq(0) ).to eq(false)
end
it "should not send the flags_agreed_and_post_deleted message if agree_flags is false" do
expect(PostAction.flagged_posts_count).to eq(1)
PostDestroyer.new(moderator, second_post, agree_flags: false).destroy
expect(Jobs::SendSystemMessage.jobs.size).to eq(0)
expect(PostAction.flagged_posts_count).to eq(0)
end end
it "should set the deleted_public_actions custom field" do it "should set the deleted_public_actions custom field" do