From f811f178302ddeb61573cd1b94bf0134de03b439 Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Mon, 2 Oct 2023 15:01:50 +0700 Subject: [PATCH] Fix irrelevant flag numbers (#20204) * Fix irrelevent numbers in admin display * Remove unused possible_spam_users_count * Fix tab styles --- app/assets/stylesheets/components/tabs.scss | 4 ++-- app/assets/stylesheets/themes/dark.css | 2 +- .../admin/feedback_messages_controller.rb | 1 + app/models/reaction.rb | 9 +++++++ app/services/admin/data_counts.rb | 11 ++------- .../admin/overview/_health_check.html.erb | 7 +----- .../admin/shared/_nested_sidebar.html.erb | 6 ++--- spec/models/reaction_spec.rb | 24 +++++++++++++++++++ 8 files changed, 43 insertions(+), 21 deletions(-) diff --git a/app/assets/stylesheets/components/tabs.scss b/app/assets/stylesheets/components/tabs.scss index 8fa9da444..565ad47e3 100644 --- a/app/assets/stylesheets/components/tabs.scss +++ b/app/assets/stylesheets/components/tabs.scss @@ -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); } } } diff --git a/app/assets/stylesheets/themes/dark.css b/app/assets/stylesheets/themes/dark.css index a8cf067f5..1cb9c0159 100644 --- a/app/assets/stylesheets/themes/dark.css +++ b/app/assets/stylesheets/themes/dark.css @@ -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); diff --git a/app/controllers/admin/feedback_messages_controller.rb b/app/controllers/admin/feedback_messages_controller.rb index ae27ce2b6..6b88ff243 100644 --- a/app/controllers/admin/feedback_messages_controller.rb +++ b/app/controllers/admin/feedback_messages_controller.rb @@ -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) diff --git a/app/models/reaction.rb b/app/models/reaction.rb index 7877c8701..99ab51427 100644 --- a/app/models/reaction.rb +++ b/app/models/reaction.rb @@ -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 } diff --git a/app/services/admin/data_counts.rb b/app/services/admin/data_counts.rb index 4936b0e31..7d34fcb4a 100644 --- a/app/services/admin/data_counts.rb +++ b/app/services/admin/data_counts.rb @@ -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, diff --git a/app/views/admin/overview/_health_check.html.erb b/app/views/admin/overview/_health_check.html.erb index 72624cd2d..259d91615 100644 --- a/app/views/admin/overview/_health_check.html.erb +++ b/app/views/admin/overview/_health_check.html.erb @@ -1,7 +1,7 @@

Health check

- + <%= @data_counts.flags_count %> Flags raised by Moderators @@ -15,9 +15,4 @@ <%= @data_counts.open_abuse_reports_count %> <%= "Report".pluralize(@data_counts.open_abuse_reports_count) %> submitted by Users - - - <%= @data_counts.possible_spam_users_count %> - Potential spam/abuse users -
diff --git a/app/views/admin/shared/_nested_sidebar.html.erb b/app/views/admin/shared/_nested_sidebar.html.erb index e18aacb89..41bad300e 100644 --- a/app/views/admin/shared/_nested_sidebar.html.erb +++ b/app/views/admin/shared/_nested_sidebar.html.erb @@ -10,19 +10,19 @@ <% menu_items.each do |group_name, group| %>
  • " + 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) %> <% if group.has_multiple_children? %> -