FIX: perform agree_and_keep action only if possible. (#13967)

While deleting spammers from flag modal it's trying to perform `agree_and_keep` action where it's not possible (or already performed).
This commit is contained in:
Vinoth Kannan 2021-09-06 11:41:44 +05:30 committed by GitHub
parent 7b392cee50
commit 0c777825b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -125,7 +125,7 @@ class UserDestroyer
def agree_with_flags(user)
ReviewableFlaggedPost.where(target_created_by: user).find_each do |reviewable|
reviewable.perform(@actor, :agree_and_keep)
reviewable.perform(@actor, :agree_and_keep) if reviewable.actions_for(@guardian).has?(:agree_and_keep)
end
end

View File

@ -665,6 +665,16 @@ RSpec.describe Admin::UsersController do
expect(Topic.where(id: topic.id).count).to eq(0)
expect(User.where(id: delete_me.id).count).to eq(0)
end
context "user has reviewable flagged post which was handled" do
let!(:reviewable) { Fabricate(:reviewable_flagged_post, created_by: admin, target_created_by: delete_me, target: post, topic: topic, status: 4) }
it "deletes the user record" do
delete "/admin/users/#{delete_me.id}.json", params: { delete_posts: true, delete_as_spammer: true }
expect(response.status).to eq(200)
expect(User.where(id: delete_me.id).count).to eq(0)
end
end
end
it "deletes the user record" do