Fix irrelevant flag numbers (#20204)

* Fix irrelevent numbers in admin display

* Remove unused possible_spam_users_count

* Fix tab styles
This commit is contained in:
Ben Halpern 2023-10-02 15:01:50 +07:00 committed by GitHub
parent 19004680de
commit f811f17830
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 21 deletions

View file

@ -165,9 +165,9 @@
color: var(--base-100);
@media (min-width: $breakpoint-s) {
background: var(--base-inverted);
background: var(--link-bg-current);
&:hover {
background: var(--base-inverted);
background: var(--link-bg-current);
}
}
}

View file

@ -83,7 +83,7 @@
--link-color-current: var(--base-100);
--link-color-secondary: var(--base-70);
--link-color-secondary-hover: var(--base-80);
--link-bg-current: var(--base-inverted);
--link-bg-current: var(--card-bg);
/* Primary buttons */
--button-primary-bg: var(--accent-brand-darker);

View file

@ -85,6 +85,7 @@ module Admin
end
q = Reaction.includes(:user, :reactable)
.where(category: "vomit", status: status)
.live_reactable
.select(:id, :user_id, :reactable_type, :reactable_id)
.order(updated_at: :desc)
.limit(limit)

View file

@ -38,6 +38,15 @@ class Reaction < ApplicationRecord
scope :from_user, ->(user) { where(user: user) }
scope :readinglist_for_user, ->(user) { readinglist.unarchived.only_articles.from_user(user) }
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'")
.where("
CASE
WHEN reactions.reactable_type = 'Article' THEN articles.published = TRUE
ELSE TRUE
END
")
}
validates :category, inclusion: { in: ReactionCategory.all_slugs.map(&:to_s) }
validates :reactable_type, inclusion: { in: REACTABLE_TYPES }

View file

@ -2,7 +2,6 @@ module Admin
class DataCounts
Response = Struct.new(
:open_abuse_reports_count,
:possible_spam_users_count,
:flags_count,
:flags_posts_count,
:flags_comments_count,
@ -18,19 +17,13 @@ module Admin
open_abuse_reports_count =
FeedbackMessage.open_abuse_reports.size
possible_spam_users_count = User.registered.where("length(name) > ?", 30)
.where("created_at > ?", 48.hours.ago)
.order(created_at: :desc)
.select(:username, :name, :id)
.where.not("username LIKE ?", "%spam_%")
.size
flags = Reaction
.includes(:user, :reactable)
.where(status: "valid")
.live_reactable
.privileged_category
Response.new(
open_abuse_reports_count: open_abuse_reports_count,
possible_spam_users_count: possible_spam_users_count,
flags_count: flags.size,
flags_posts_count: flags.where(reactable_type: "Article").size,
flags_comments_count: flags.where(reactable_type: "Comment").size,

View file

@ -1,7 +1,7 @@
<section class="crayons-card p-7 m:basis-1-3">
<h2 class="crayons-subtitle-1 mb-4">Health check</h2>
<a href="<%= admin_privileged_reactions_path %>" class="flex flex-col c-link c-link--block -mx-4">
<a href="<%= admin_feedback_messages_path %>" class="flex flex-col c-link c-link--block -mx-4">
<strong class="fs-xl"><%= @data_counts.flags_count %></strong>
<span>Flags raised by <span class="fw-bold">Moderators</span></span>
<small class="opacity-75">
@ -15,9 +15,4 @@
<strong class="fs-xl"><%= @data_counts.open_abuse_reports_count %></strong>
<span><%= "Report".pluralize(@data_counts.open_abuse_reports_count) %> submitted by <span class="fw-bold">Users</span></span>
</a>
<a href="<%= admin_feedback_messages_path %>" class="flex flex-col c-link c-link--block -mx-4">
<strong class="fs-xl"><%= @data_counts.possible_spam_users_count %></strong>
<span>Potential spam/abuse users</span>
</a>
</section>

View file

@ -10,19 +10,19 @@
<% menu_items.each do |group_name, group| %>
<li>
<a
class="c-link c-link--block c-link--icon-left <%= "c-link--current" if current?(request, group, group_name) %>"
class="c-link c-link--block c-link--icon-left <%= "c-link--current mb-1" if current?(request, group, group_name) %>"
aria-current="<%= "page" if current?(request, group, group_name) && !group.has_multiple_children? %>"
href="<%= nav_path(group, group_name) %>">
<%= crayons_icon_tag(group.svg, class: "c-link__icon", aria_hidden: true) %>
<%= display_name(group_name) %>
</a>
<% if group.has_multiple_children? %>
<ul class="ml-6 mb-1 <%= current?(request, group, group_name) ? "" : "hidden" %>">
<ul class="ml-6 mb-1 <%= current?(request, group, group_name) ? "block" : "hidden" %>">
<% group.children.each do |item| %>
<% if item.visible %>
<li>
<a
class="c-link c-link--block inline-block"
class="c-link c-link--block"
href="<%= admin_path %>/<%= group_name %>/<%= item.controller %>"
<% if sidebar_item_active?(item) %>
style="--bg: transparent"

View file

@ -332,4 +332,28 @@ RSpec.describe Reaction do
expect(described_class.readinglist_for_user(user).pluck(:reactable_id)).to contain_exactly(article.id)
end
end
describe ".live_reactable" do
it "returns reactions on articles where article is published" do
article = create(:article, published: true)
reaction = create(:reaction, reactable: article)
expect(described_class.live_reactable).to eq([reaction])
end
it "does not return reaction on articles where not published" do
article = create(:article)
create(:reaction, reactable: article)
article.update_column(:published, false)
expect(described_class.live_reactable).to eq([])
end
it "returns reactions on comments" do
comment = create(:comment)
reaction = create(:reaction, reactable: comment)
expect(described_class.live_reactable).to eq([reaction])
end
end
end