Follow on adjustments to flag counts (#20207)
This commit is contained in:
parent
77dd41dfb8
commit
044fe88230
4 changed files with 25 additions and 9 deletions
|
|
@ -40,9 +40,11 @@ class Reaction < ApplicationRecord
|
|||
scope :distinct_categories, -> { select("distinct(reactions.category) as category, reactable_id, reactable_type") }
|
||||
scope :live_reactable, lambda {
|
||||
joins("LEFT JOIN articles ON reactions.reactable_id = articles.id AND reactions.reactable_type = 'Article'")
|
||||
.joins("LEFT JOIN users ON reactions.reactable_id = users.id AND reactions.reactable_type = 'User'")
|
||||
.where("
|
||||
CASE
|
||||
WHEN reactions.reactable_type = 'Article' THEN articles.published = TRUE
|
||||
WHEN reactions.reactable_type = 'User' THEN users.username NOT LIKE 'spam_%'
|
||||
ELSE TRUE
|
||||
END
|
||||
")
|
||||
|
|
@ -204,7 +206,7 @@ class Reaction < ApplicationRecord
|
|||
end
|
||||
|
||||
def negative_reaction_from_untrusted_user?
|
||||
return if user&.any_admin? || user&.id == Settings::General.mascot_user_id
|
||||
return false if user&.any_admin? || user&.id == Settings::General.mascot_user_id
|
||||
|
||||
negative? && !user.trusted?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ module Admin
|
|||
.includes(:user, :reactable)
|
||||
.where(status: "valid")
|
||||
.live_reactable
|
||||
.privileged_category
|
||||
.where(category: "vomit")
|
||||
Response.new(
|
||||
open_abuse_reports_count: open_abuse_reports_count,
|
||||
flags_count: flags.size,
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@
|
|||
<div id="vomitReactionsBodyContainer" aria-labelledby="vomitReactionsHeader" data-parent="#vomitReactions">
|
||||
<div class="crayons-card__body" style="overflow: scroll; max-height: 500px;">
|
||||
<% @vomits.each do |reaction| %>
|
||||
<% next if (reaction.reactable_type == "Article" && !reaction.reactable.published) || (reaction.reactable_type == "User" && reaction.reactable&.banished?) %>
|
||||
|
||||
<div
|
||||
class="flex justify-between"
|
||||
data-controller="reaction"
|
||||
|
|
|
|||
|
|
@ -334,26 +334,42 @@ RSpec.describe Reaction do
|
|||
end
|
||||
|
||||
describe ".live_reactable" do
|
||||
let(:moderator) { create(:user, :trusted) }
|
||||
|
||||
it "returns reactions on articles where article is published" do
|
||||
article = create(:article, published: true)
|
||||
reaction = create(:reaction, reactable: article)
|
||||
reaction = create(:vomit_reaction, user: moderator, reactable: article)
|
||||
|
||||
expect(described_class.live_reactable).to eq([reaction])
|
||||
expect(described_class.live_reactable.to_a).to eq([reaction])
|
||||
end
|
||||
|
||||
it "does not return reaction on articles where not published" do
|
||||
article = create(:article)
|
||||
create(:reaction, reactable: article)
|
||||
create(:vomit_reaction, user: moderator, reactable: article)
|
||||
article.update_column(:published, false)
|
||||
|
||||
expect(described_class.live_reactable).to eq([])
|
||||
expect(described_class.live_reactable.to_a).to eq([])
|
||||
end
|
||||
|
||||
it "returns reactions on comments" do
|
||||
comment = create(:comment)
|
||||
reaction = create(:reaction, reactable: comment)
|
||||
reaction = create(:vomit_reaction, user: moderator, reactable: comment)
|
||||
|
||||
expect(described_class.live_reactable).to eq([reaction])
|
||||
end
|
||||
|
||||
it "returns reactions to users" do
|
||||
user = create(:user)
|
||||
reaction = create(:vomit_reaction, user: moderator, reactable: user)
|
||||
|
||||
expect(described_class.live_reactable.to_a).to eq([reaction])
|
||||
end
|
||||
|
||||
it "does not return reactions to users who are deemed spam already" do
|
||||
user = create(:user, username: "spam_400")
|
||||
create(:vomit_reaction, user: moderator, reactable: user)
|
||||
|
||||
expect(described_class.live_reactable.to_a).to eq([])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue