From e4cf546843174f1f4412c228c70b02c603f4a81e Mon Sep 17 00:00:00 2001 From: Nikolai B Date: Mon, 17 Jan 2022 20:24:16 +0000 Subject: [PATCH] Add pages to help issues removal to admin From https://github.com/cyclestreets/cyclescape/issues/1011#issuecomment-1014779631 can probably be removed soon. --- app/controllers/admin/stats_controller.rb | 16 ++++++++++++++++ app/models/tag.rb | 1 - app/views/admin/home/index.html.haml | 2 ++ app/views/admin/stats/index.html.haml | 1 + app/views/admin/stats/issues_untagged.html.haml | 5 +++++ .../stats/issues_with_multiple_threads.html.haml | 10 ++++++++++ config/authorization_rules.rb | 2 +- config/routes.rb | 5 ++++- 8 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 app/views/admin/stats/issues_untagged.html.haml create mode 100644 app/views/admin/stats/issues_with_multiple_threads.html.haml diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index ddb6bac6a..9714dafc2 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -1,6 +1,22 @@ # frozen_string_literal: true class Admin::StatsController < ApplicationController + def issues_untagged + @issues_untagged = Issue.joins(:threads).where( + <<~SQL + not exists (select 1 from issue_tags where issue_tags.issue_id = issues.id) + and not exists (select 1 from message_thread_tags where message_thread_tags.thread_id = message_threads.id) + SQL + ).distinct + end + + def issues_with_multiple_threads + multiple_ids = Issue.joins(:threads).group(:id).having("count(*) > 1").ids + @issues_with_multiple_threads = Issue.where(id: multiple_ids).left_joins(:tags).group(:id, :title).select( + "issues.id, title, json_agg(tags.name) as tag_names" + ) + end + def index users_scope = User.all messages_scope = Message.all diff --git a/app/models/tag.rb b/app/models/tag.rb index 992682c2c..4f01ab045 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true - class Tag < ApplicationRecord validates :name, presence: true has_and_belongs_to_many :issues, join_table: "issue_tags" diff --git a/app/views/admin/home/index.html.haml b/app/views/admin/home/index.html.haml index 15ae3e915..c75a545d9 100644 --- a/app/views/admin/home/index.html.haml +++ b/app/views/admin/home/index.html.haml @@ -8,6 +8,8 @@ %li= link_to t(".manage_message_moderations"), admin_message_moderations_path %li= link_to t(".manage_site_config"), admin_site_config_path %li= link_to t(".stats"), admin_stats_path + %li= link_to "Issues Untagged", issues_untagged_admin_stats_path + %li= link_to "Issues with multiple threads", issues_with_multiple_threads_admin_stats_path %li= link_to t(".resque"), resque_server_path %li= link_to t(".manage_planning_filters"), admin_planning_filters_path %li= link_to t(".mail_previews"), "/rails/mailers" diff --git a/app/views/admin/stats/index.html.haml b/app/views/admin/stats/index.html.haml index b1be36848..d634d58fa 100644 --- a/app/views/admin/stats/index.html.haml +++ b/app/views/admin/stats/index.html.haml @@ -5,6 +5,7 @@ - else %h3 For the whole site: - month_sum = usr_sum = 0 + %div= line_chart(@users.map{ |usr| [ usr.month, usr_sum += usr.count]}, ytitle: 'New Users (Cumulative)', library: {title: 'Users'}) %div= line_chart(@messages.map{ |mes| [ mes.month, month_sum += mes.count]}, ytitle: 'New Messages (Cumulative)', library: {title: 'Messages'}) diff --git a/app/views/admin/stats/issues_untagged.html.haml b/app/views/admin/stats/issues_untagged.html.haml new file mode 100644 index 000000000..a5d5e6436 --- /dev/null +++ b/app/views/admin/stats/issues_untagged.html.haml @@ -0,0 +1,5 @@ +%div Issues with threads where neither the issue or the thread have tags +%ul + - @issues_untagged.each do |issue| + %li= link_to issue.title, issue + diff --git a/app/views/admin/stats/issues_with_multiple_threads.html.haml b/app/views/admin/stats/issues_with_multiple_threads.html.haml new file mode 100644 index 000000000..93fe65bc8 --- /dev/null +++ b/app/views/admin/stats/issues_with_multiple_threads.html.haml @@ -0,0 +1,10 @@ +%table + %thead + %th Issue + %th Tags (on the issue only) + %tbody + - @issues_with_multiple_threads.each do |issue| + %tr + %td= link_to issue.title, issue + %td= issue.tag_names.compact + diff --git a/config/authorization_rules.rb b/config/authorization_rules.rb index fb4f8b9b9..f9831a73b 100644 --- a/config/authorization_rules.rb +++ b/config/authorization_rules.rb @@ -16,7 +16,7 @@ has_permission_on :admin_user_locations, to: %i[manage geometry combined_geometry] has_permission_on :admin_home, to: :view has_permission_on :admin_message_moderations, to: :view - has_permission_on :admin_stats, to: :view + has_permission_on :admin_stats, to: %i[view issues_untagged issues_with_multiple_threads] has_permission_on :admin_planning_filters, to: :manage has_permission_on :admin_site_configs, to: :manage has_permission_on :admin_templates, to: :show diff --git a/config/routes.rb b/config/routes.rb index 522032cb5..51c05fdb6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -60,7 +60,10 @@ def issues_route(opts = {}) put :disable, :enable, on: :member end resource :site_config - resources :stats, only: :index + resources :stats, only: :index do + get :issues_untagged, on: :collection + get :issues_with_multiple_threads, on: :collection + end resources :message_moderations, only: :index resources :planning_filters resources :users do