diff options
author | Matt Jankowski <mjankowski@thoughtbot.com> | 2017-04-13 07:04:23 -0400 |
---|---|---|
committer | Eugen <eugen@zeonfederated.com> | 2017-04-13 13:04:23 +0200 |
commit | 3a9eb81a8006af0306e8abc54bd8aca8381eee25 (patch) | |
tree | 9bae0b991f7db4cfe0de626829995346cdb29549 /app/models | |
parent | 0e39cc6a35661416a1f1ccb8841863f7bf307020 (diff) |
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
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account_filter.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb new file mode 100644 index 000000000..a8d8c8837 --- /dev/null +++ b/app/models/account_filter.rb @@ -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 |