FIX: Recalculate scores only when approving or transitioning to pending. (#13009)

Recalculating a ReviewableFlaggedPost's score after rejecting or ignoring it sets the score as 0, which means that we can't find them after reviewing. They don't surpass the minimum priority threshold and are hidden.

Additionally, we only want to use agreed flags when calculating the different priority thresholds.
This commit is contained in:
Roman Rizzi
2021-05-10 14:09:04 -03:00
committed by GitHub
parent d61573fb1b
commit d4b5a81b05
6 changed files with 58 additions and 20 deletions
+9 -3
View File
@@ -175,7 +175,13 @@ class Reviewable < ActiveRecord::Base
reviewable.save!
else
reviewable = find_by(target: target)
reviewable.log_history(:transitioned, created_by) if old_status != statuses[:pending]
if old_status != statuses[:pending]
# If we're transitioning back from reviewed to pending, we should recalculate
# the score to prevent posts from being hidden.
reviewable.recalculate_score
reviewable.log_history(:transitioned, created_by)
end
end
end
@@ -584,8 +590,6 @@ class Reviewable < ActiveRecord::Base
SQL
end
protected
def recalculate_score
# pending/agreed scores count
sql = <<~SQL
@@ -633,6 +637,8 @@ protected
self.score
end
protected
def increment_version!(version = nil)
version_result = nil