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
This commit is contained in:
parent
f23281e31e
commit
66d8f99a30
9 changed files with 92 additions and 5 deletions
|
@ -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') }
|
||||
|
|
30
app/models/report_filter.rb
Normal file
30
app/models/report_filter.rb
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue