mirror of
https://github.com/discourse/discourse.git
synced 2025-05-26 07:41:43 +08:00
FEATURE: Count only approved flagged posts in user pages (#22799)
FEATURE: Only approved flags for post counters * Why was this change necessary? The counters for flagged posts in the user's profile and user index from the admin view include flags that were rejected, ignored or pending review. This introduces unnecessary noise. Also the flagged posts counter in the user's profile includes custom flags which add further noise to this signal. * How does it address the problem? * Modifying User#flags_received_count to return posts with only approved standard flags * Refactoring User#number_of_flagged_posts to alias to User#flags_received_count * Updating the flagged post staff counter hyperlink to navigate to a filtered view of that user's approved flagged posts to maintain consistency with the counter * Adding system tests for the profile page to cover the flagged posts staff counter
This commit is contained in:
@ -2002,16 +2002,43 @@ RSpec.describe User do
|
||||
end
|
||||
|
||||
describe "#number_of_flagged_posts" do
|
||||
it "counts flagged posts from the user" do
|
||||
Fabricate(:reviewable_flagged_post, target_created_by: user)
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
|
||||
expect(user.number_of_flagged_posts).to eq(1)
|
||||
it "counts only approved standard flagged posts from the user" do
|
||||
%i[disagree ignore delete_and_ignore].each do |review_action|
|
||||
PostActionCreator
|
||||
.off_topic(admin, Fabricate(:post, user: user))
|
||||
.reviewable
|
||||
.perform(admin, review_action)
|
||||
end
|
||||
%i[agree_and_keep delete_and_agree].each do |approval_action|
|
||||
PostActionCreator
|
||||
.off_topic(admin, Fabricate(:post, user: user))
|
||||
.reviewable
|
||||
.perform(admin, approval_action)
|
||||
end
|
||||
|
||||
expect(user.number_of_flagged_posts).to eq 2
|
||||
end
|
||||
|
||||
it "ignores custom flags from the user" do
|
||||
PostActionCreator
|
||||
.notify_moderators(admin, Fabricate(:post, user: user))
|
||||
.reviewable
|
||||
.perform(admin, :agree_and_keep)
|
||||
expect(user.number_of_flagged_posts).to be_zero
|
||||
end
|
||||
|
||||
it "ignores flagged posts from another user" do
|
||||
Fabricate(:reviewable_flagged_post, target_created_by: Fabricate(:user))
|
||||
other_user = Fabricate(:user)
|
||||
%i[disagree ignore delete_and_ignore agree_and_keep].each do |review_action|
|
||||
PostActionCreator
|
||||
.off_topic(admin, Fabricate(:post, user: other_user))
|
||||
.reviewable
|
||||
.perform(admin, review_action)
|
||||
end
|
||||
|
||||
expect(user.number_of_flagged_posts).to eq(0)
|
||||
expect(user.number_of_flagged_posts).to be_zero
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user