Skip to content

A platform for community discussion. Free, open, simple.

FIX: Prevent resurrection of approved queued reviewables when reusing flagged reviewables for the same target (#41790)

small-lovely-catc3110f53e15c
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index d1d38a9f9dc..19d3971d893 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -163,7 +163,8 @@ class Reviewable < ActiveRecord::Base
update_args = {
status: statuses[:pending],
id: target.id,
- type: target.class.polymorphic_name,
+ target_type: target.class.polymorphic_name,
+ reviewable_type: reviewable.type,
potential_spam: potential_spam == true ? true : nil,
potentially_illegal: potentially_illegal == true ? true : nil,
}
@@ -175,7 +176,9 @@ class Reviewable < ActiveRecord::Base
potentially_illegal = COALESCE(:potentially_illegal, reviewables.potentially_illegal)
FROM reviewables AS old_reviewables
WHERE reviewables.target_id = :id
- AND reviewables.target_type = :type
+ AND reviewables.target_type = :target_type
+ AND reviewables.type = :reviewable_type
+ AND old_reviewables.id = reviewables.id
RETURNING old_reviewables.status
SQL
old_status = row[0]
diff --git a/spec/models/reviewable_spec.rb b/spec/models/reviewable_spec.rb
index 003d1230359..8da11572e58 100644
--- a/spec/models/reviewable_spec.rb
+++ b/spec/models/reviewable_spec.rb
@@ -103,6 +103,20 @@ RSpec.describe Reviewable, type: :model do
r1 = ReviewableFlaggedPost.needs_review!(created_by: admin, target: r0.target)
expect(r1.pending?).to eq(true)
end
+
+ it "will not resurrect an approved queued reviewable when reusing a flagged reviewable for the same target" do
+ r0 = Fabricate(:reviewable_queued_post)
+ r0.perform(admin, :approve_post)
+ expect(r0.reload.status).to eq("approved")
+
+ r1 = ReviewableFlaggedPost.needs_review!(created_by: admin, target: r0.target)
+ expect(r1.pending?).to eq(true)
+
+ ReviewableFlaggedPost.needs_review!(created_by: admin, target: r0.target)
+
+ expect(r1.reload.pending?).to eq(true)
+ expect(r0.reload.status).to eq("approved")
+ end
end
describe ".list_for" do