diff options
author | Matt Jankowski <mjankowski@thoughtbot.com> | 2017-04-18 13:36:18 -0400 |
---|---|---|
committer | Eugen <eugen@zeonfederated.com> | 2017-04-18 19:36:18 +0200 |
commit | 66d8f99a30f9e6062f1bff37d5115beddce9b55d (patch) | |
tree | 5f7c752043054bc86fb57faa89332660688044bc /app | |
parent | f23281e31ead38a1cabbb73f0dbb8b36cb38cadb (diff) |
Admin reports with accounts (#2092)
* Add a ReportFilter class * Add reports and targeted_reports relationships to Account * Use ReportFilter from admin/reports controller * Link to admin/reports filtered views from admin account show view * Add indexes to reports.account_id and reports.target_account_id
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/reports_controller.rb | 10 | ||||
-rw-r--r-- | app/helpers/admin/filter_helper.rb | 2 | ||||
-rw-r--r-- | app/models/account.rb | 4 | ||||
-rw-r--r-- | app/models/report_filter.rb | 30 | ||||
-rw-r--r-- | app/views/admin/accounts/show.html.haml | 6 |
5 files changed, 48 insertions, 4 deletions
diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 4a6f9ea7f..fc63ca5c0 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -49,14 +49,18 @@ module Admin end def filtered_reports - filtering_scope.order('id desc').includes( + ReportFilter.new(filter_params).results.order('id desc').includes( :account, :target_account ) end - def filtering_scope - params[:resolved].present? ? Report.resolved : Report.unresolved + def filter_params + params.permit( + :account_id, + :resolved, + :target_account_id + ) end def set_report diff --git a/app/helpers/admin/filter_helper.rb b/app/helpers/admin/filter_helper.rb index 591056dd7..5080e6350 100644 --- a/app/helpers/admin/filter_helper.rb +++ b/app/helpers/admin/filter_helper.rb @@ -2,7 +2,7 @@ module Admin::FilterHelper ACCOUNT_FILTERS = %i[local remote by_domain silenced suspended recent].freeze - REPORT_FILTERS = %i[resolved].freeze + REPORT_FILTERS = %i[resolved account_id target_account_id].freeze FILTERS = ACCOUNT_FILTERS + REPORT_FILTERS diff --git a/app/models/account.rb b/app/models/account.rb index 259a87451..2a10f8345 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -55,6 +55,10 @@ class Account < ApplicationRecord # PuSH subscriptions has_many :subscriptions, dependent: :destroy + # Report relationships + has_many :reports + has_many :targeted_reports, class_name: 'Report', foreign_key: :target_account_id + scope :remote, -> { where.not(domain: nil) } scope :local, -> { where(domain: nil) } scope :without_followers, -> { where('(select count(f.id) from follows as f where f.target_account_id = accounts.id) = 0') } diff --git a/app/models/report_filter.rb b/app/models/report_filter.rb new file mode 100644 index 000000000..56ab28df7 --- /dev/null +++ b/app/models/report_filter.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class ReportFilter + attr_reader :params + + def initialize(params) + @params = params + end + + def results + scope = Report.unresolved + params.each do |key, value| + scope = scope.merge scope_for(key, value) + end + scope + end + + def scope_for(key, value) + case key.to_sym + when :resolved + Report.resolved + when :account_id + Report.where(account_id: value) + when :target_account_id + Report.where(target_account_id: value) + else + raise "Unknown filter: #{key}" + end + end +end diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml index 7609868e6..ebf2b5ac1 100644 --- a/app/views/admin/accounts/show.html.haml +++ b/app/views/admin/accounts/show.html.haml @@ -60,6 +60,12 @@ = @account.media_attachments.count = surround '(', ')' do = number_to_human_size @account.media_attachments.sum('file_file_size') + %tr + %th= t('.created_reports') + %td= link_to pluralize(@account.reports.count, t('.report')), admin_reports_path(account_id: @account.id) + %tr + %th= t('.targeted_reports') + %td= link_to pluralize(@account.targeted_reports.count, t('.report')), admin_reports_path(target_account_id: @account.id) - if @account.local? %div{ style: 'float: right' } |