Skip to content

Commit

Permalink
Add pages to help issues removal to admin
Browse files Browse the repository at this point in the history
From
#1011 (comment)
can probably be removed soon.
  • Loading branch information
nikolai-b committed Jan 17, 2022
1 parent 6af1947 commit e4cf546
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 3 deletions.
16 changes: 16 additions & 0 deletions app/controllers/admin/stats_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion app/models/tag.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/stats/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand Down
5 changes: 5 additions & 0 deletions app/views/admin/stats/issues_untagged.html.haml
Original file line number Diff line number Diff line change
@@ -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

10 changes: 10 additions & 0 deletions app/views/admin/stats/issues_with_multiple_threads.html.haml
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion config/authorization_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e4cf546

Please sign in to comment.