DEV: Ensure don't feed the trolls feature considers active flags only (#22774)
We recently added a "don't feed the trolls" feature which warns you about interacting with posts that have been flagged and are pending review. The problem is the warning persists even if an admin reviews the post and rejects the flag. After this change we only consider active flags when deciding whether to show the warning or not.
This commit is contained in:
parent
f1a43f2319
commit
f380643528
|
@ -238,7 +238,7 @@ class ComposerMessagesFinder
|
|||
|
||||
return if post.blank?
|
||||
|
||||
flags = post.flags.group(:user_id).count
|
||||
flags = post.flags.active.group(:user_id).count
|
||||
flagged_by_replier = flags[@user.id].to_i > 0
|
||||
flagged_by_others = flags.values.sum >= SiteSetting.dont_feed_the_trolls_threshold
|
||||
|
||||
|
|
|
@ -339,6 +339,7 @@ RSpec.describe ComposerMessagesFinder do
|
|||
fab!(:self_flagged_post) { Fabricate(:post, topic: topic, user: author) }
|
||||
fab!(:under_flagged_post) { Fabricate(:post, topic: topic, user: author) }
|
||||
fab!(:over_flagged_post) { Fabricate(:post, topic: topic, user: author) }
|
||||
fab!(:resolved_flag_post) { Fabricate(:post, topic: topic, user: author) }
|
||||
|
||||
before { SiteSetting.dont_feed_the_trolls_threshold = 2 }
|
||||
|
||||
|
@ -383,6 +384,20 @@ RSpec.describe ComposerMessagesFinder do
|
|||
expect(finder.check_dont_feed_the_trolls).to be_blank
|
||||
end
|
||||
|
||||
it "does not show a message when the flag has already been resolved" do
|
||||
SiteSetting.dont_feed_the_trolls_threshold = 1
|
||||
|
||||
Fabricate(:flag, post: resolved_flag_post, user: other_user, disagreed_at: 1.hour.ago)
|
||||
finder =
|
||||
ComposerMessagesFinder.new(
|
||||
user,
|
||||
composer_action: "reply",
|
||||
topic_id: topic.id,
|
||||
post_id: resolved_flag_post.id,
|
||||
)
|
||||
expect(finder.check_dont_feed_the_trolls).to be_blank
|
||||
end
|
||||
|
||||
it "shows a message when enough others have already flagged the post" do
|
||||
Fabricate(:flag, post: over_flagged_post, user: other_user)
|
||||
Fabricate(:flag, post: over_flagged_post, user: third_user)
|
||||
|
|
Loading…
Reference in New Issue