Admin accounts controller cleanup (#1664)
* Remove unused account_params method in admin/accounts controller * Introduce AccountFilter to find accounts * Use AccountFilter in admin/accounts controller * Use more restful routes admin silence and suspension area * Add admin/silences and admin/suspensions controllers
This commit is contained in:
parent
0e39cc6a35
commit
3a9eb81a80
9 changed files with 182 additions and 44 deletions
36
app/models/account_filter.rb
Normal file
36
app/models/account_filter.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AccountFilter
|
||||
attr_reader :params
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def results
|
||||
scope = Account.alphabetic
|
||||
params.each do |key, value|
|
||||
scope = scope.merge scope_for(key, value)
|
||||
end
|
||||
scope
|
||||
end
|
||||
|
||||
def scope_for(key, value)
|
||||
case key
|
||||
when /local/
|
||||
Account.local
|
||||
when /remote/
|
||||
Account.remote
|
||||
when /by_domain/
|
||||
Account.where(domain: value)
|
||||
when /silenced/
|
||||
Account.silenced
|
||||
when /recent/
|
||||
Account.recent
|
||||
when /suspended/
|
||||
Account.suspended
|
||||
else
|
||||
raise "Unknown filter: #{key}"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue