Redesign admin accounts index (#9340)
* Improve overview of accounts in admin UI - Display suspended status, role, last activity and IP prominently - Default to showing local accounts - Default to not showing suspended accounts * Remove unused strings * Fix tests * Allow filtering accounts by IP mask
This commit is contained in:
parent
db9aea34de
commit
73faadad28
56 changed files with 47 additions and 266 deletions
|
@ -123,6 +123,7 @@ class Account < ApplicationRecord
|
|||
scope :suspended, -> { where(suspended: true) }
|
||||
scope :without_suspended, -> { where(suspended: false) }
|
||||
scope :recent, -> { reorder(id: :desc) }
|
||||
scope :bots, -> { where(actor_type: %w(Application Service)) }
|
||||
scope :alphabetic, -> { order(domain: :asc, username: :asc) }
|
||||
scope :by_domain_accounts, -> { group(:domain).select(:domain, 'COUNT(*) AS accounts_count').order('accounts_count desc') }
|
||||
scope :matches_username, ->(value) { where(arel_table[:username].matches("#{value}%")) }
|
||||
|
|
|
@ -5,13 +5,14 @@ class AccountFilter
|
|||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
set_defaults!
|
||||
end
|
||||
|
||||
def results
|
||||
scope = Account.recent
|
||||
scope = Account.recent.includes(:user)
|
||||
|
||||
params.each do |key, value|
|
||||
scope.merge!(scope_for(key, value)) if value.present?
|
||||
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
|
||||
end
|
||||
|
||||
scope
|
||||
|
@ -19,6 +20,11 @@ class AccountFilter
|
|||
|
||||
private
|
||||
|
||||
def set_defaults!
|
||||
params['local'] = '1' if params['remote'].blank?
|
||||
params['active'] = '1' if params['suspended'].blank? && params['silenced'].blank?
|
||||
end
|
||||
|
||||
def scope_for(key, value)
|
||||
case key.to_s
|
||||
when 'local'
|
||||
|
@ -27,10 +33,10 @@ class AccountFilter
|
|||
Account.remote
|
||||
when 'by_domain'
|
||||
Account.where(domain: value)
|
||||
when 'active'
|
||||
Account.without_suspended
|
||||
when 'silenced'
|
||||
Account.silenced
|
||||
when 'alphabetic'
|
||||
Account.reorder(nil).alphabetic
|
||||
when 'suspended'
|
||||
Account.suspended
|
||||
when 'username'
|
||||
|
@ -40,11 +46,7 @@ class AccountFilter
|
|||
when 'email'
|
||||
accounts_with_users.merge User.matches_email(value)
|
||||
when 'ip'
|
||||
if valid_ip?(value)
|
||||
accounts_with_users.merge User.with_recent_ip_address(value)
|
||||
else
|
||||
Account.default_scoped
|
||||
end
|
||||
valid_ip?(value) ? accounts_with_users.where('users.current_sign_in_ip <<= ?', value) : Account.none
|
||||
when 'staff'
|
||||
accounts_with_users.merge User.staff
|
||||
else
|
||||
|
@ -57,8 +59,7 @@ class AccountFilter
|
|||
end
|
||||
|
||||
def valid_ip?(value)
|
||||
IPAddr.new(value)
|
||||
true
|
||||
IPAddr.new(value) && true
|
||||
rescue IPAddr::InvalidAddressError
|
||||
false
|
||||
end
|
||||
|
|
|
@ -83,7 +83,6 @@ class User < ApplicationRecord
|
|||
scope :inactive, -> { where(arel_table[:current_sign_in_at].lt(ACTIVE_DURATION.ago)) }
|
||||
scope :active, -> { confirmed.where(arel_table[:current_sign_in_at].gteq(ACTIVE_DURATION.ago)).joins(:account).where(accounts: { suspended: false }) }
|
||||
scope :matches_email, ->(value) { where(arel_table[:email].matches("#{value}%")) }
|
||||
scope :with_recent_ip_address, ->(value) { where(arel_table[:current_sign_in_ip].eq(value).or(arel_table[:last_sign_in_ip].eq(value))) }
|
||||
|
||||
before_validation :sanitize_languages
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue