FIX: Ignore posts needing approval when calculating reviewable counts. (#13464)

In #12841, we started setting the ReviewableQueuedPost's target and topic after approving it instead of storing them in the payload. As a result, the reviewable_counts query started to include queued posts.

When a category is set to require approval, every post has an associated reviewable. Pointing that each post has an associated queued post is not necessary in this case, so I added a WHERE clause to skip them.
This commit is contained in:
Roman Rizzi 2021-06-22 12:12:39 -03:00 committed by GitHub
parent e76c583b91
commit e0e1e24c14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -509,7 +509,8 @@ class TopicView
reviewable_scores s ON reviewable_id = r.id
WHERE
r.target_id IN (:post_ids) AND
r.target_type = 'Post'
r.target_type = 'Post' AND
COALESCE(s.reason, '') != 'category'
GROUP BY
target_id
SQL

View File

@ -915,4 +915,41 @@ describe TopicView do
expect(topic_view.show_read_indicator?).to be_falsey
end
end
describe '#reviewable_counts' do
it 'exclude posts queued because the category needs approval' do
category = Fabricate.build(:category, user: admin)
category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = true
category.save!
manager = NewPostManager.new(
user,
raw: 'to the handler I say enqueue me!',
title: 'this is the title of the queued post',
category: category.id
)
result = manager.perform
reviewable = result.reviewable
reviewable.perform(admin, :approve_post)
topic_view = TopicView.new(reviewable.topic, admin)
expect(topic_view.reviewable_counts).to be_empty
end
it 'include posts queued for other reasons' do
Fabricate(:watched_word, word: "darn", action: WatchedWord.actions[:require_approval])
manager = NewPostManager.new(
user,
raw: 'this is darn new post content',
title: 'this is the title of the queued post'
)
result = manager.perform
reviewable = result.reviewable
reviewable.perform(admin, :approve_post)
topic_view = TopicView.new(reviewable.topic, admin)
expect(topic_view.reviewable_counts.keys).to contain_exactly(reviewable.target_id)
end
end
end