mirror of
https://github.com/mastodon/mastodon
synced 2024-12-01 00:08:21 +09:00
Add sorting by username, creation and last activity in moderation view (#13076)
* Add ability to order accounts in moderation view * Display last status date in “Most recent activity” for remote users
This commit is contained in:
parent
2e18b1a2a2
commit
4a4cd686c1
@ -102,6 +102,7 @@ class Account < ApplicationRecord
|
|||||||
scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).left_outer_joins(:account_stat) }
|
scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).left_outer_joins(:account_stat) }
|
||||||
scope :tagged_with, ->(tag) { joins(:accounts_tags).where(accounts_tags: { tag_id: tag }) }
|
scope :tagged_with, ->(tag) { joins(:accounts_tags).where(accounts_tags: { tag_id: tag }) }
|
||||||
scope :by_recent_status, -> { order(Arel.sql('(case when account_stats.last_status_at is null then 1 else 0 end) asc, account_stats.last_status_at desc, accounts.id desc')) }
|
scope :by_recent_status, -> { order(Arel.sql('(case when account_stats.last_status_at is null then 1 else 0 end) asc, account_stats.last_status_at desc, accounts.id desc')) }
|
||||||
|
scope :by_recent_sign_in, -> { order(Arel.sql('(case when users.current_sign_in_at is null then 1 else 0 end) asc, users.current_sign_in_at desc, accounts.id desc')) }
|
||||||
scope :popular, -> { order('account_stats.followers_count desc') }
|
scope :popular, -> { order('account_stats.followers_count desc') }
|
||||||
scope :by_domain_and_subdomains, ->(domain) { where(domain: domain).or(where(arel_table[:domain].matches('%.' + domain))) }
|
scope :by_domain_and_subdomains, ->(domain) { where(domain: domain).or(where(arel_table[:domain].matches('%.' + domain))) }
|
||||||
scope :not_excluded_by_account, ->(account) { where.not(id: account.excluded_from_timeline_account_ids) }
|
scope :not_excluded_by_account, ->(account) { where.not(id: account.excluded_from_timeline_account_ids) }
|
||||||
|
@ -14,6 +14,7 @@ class AccountFilter
|
|||||||
email
|
email
|
||||||
ip
|
ip
|
||||||
staff
|
staff
|
||||||
|
order
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
attr_reader :params
|
attr_reader :params
|
||||||
@ -24,7 +25,7 @@ class AccountFilter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def results
|
def results
|
||||||
scope = Account.recent.includes(:user)
|
scope = Account.includes(:user).reorder(nil)
|
||||||
|
|
||||||
params.each do |key, value|
|
params.each do |key, value|
|
||||||
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
|
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
|
||||||
@ -38,6 +39,7 @@ class AccountFilter
|
|||||||
def set_defaults!
|
def set_defaults!
|
||||||
params['local'] = '1' if params['remote'].blank?
|
params['local'] = '1' if params['remote'].blank?
|
||||||
params['active'] = '1' if params['suspended'].blank? && params['silenced'].blank? && params['pending'].blank?
|
params['active'] = '1' if params['suspended'].blank? && params['silenced'].blank? && params['pending'].blank?
|
||||||
|
params['order'] = 'recent' if params['order'].blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def scope_for(key, value)
|
def scope_for(key, value)
|
||||||
@ -51,9 +53,9 @@ class AccountFilter
|
|||||||
when 'active'
|
when 'active'
|
||||||
Account.without_suspended
|
Account.without_suspended
|
||||||
when 'pending'
|
when 'pending'
|
||||||
accounts_with_users.merge User.pending
|
accounts_with_users.merge(User.pending)
|
||||||
when 'disabled'
|
when 'disabled'
|
||||||
accounts_with_users.merge User.disabled
|
accounts_with_users.merge(User.disabled)
|
||||||
when 'silenced'
|
when 'silenced'
|
||||||
Account.silenced
|
Account.silenced
|
||||||
when 'suspended'
|
when 'suspended'
|
||||||
@ -63,16 +65,31 @@ class AccountFilter
|
|||||||
when 'display_name'
|
when 'display_name'
|
||||||
Account.matches_display_name(value)
|
Account.matches_display_name(value)
|
||||||
when 'email'
|
when 'email'
|
||||||
accounts_with_users.merge User.matches_email(value)
|
accounts_with_users.merge(User.matches_email(value))
|
||||||
when 'ip'
|
when 'ip'
|
||||||
valid_ip?(value) ? accounts_with_users.merge(User.matches_ip(value)) : Account.none
|
valid_ip?(value) ? accounts_with_users.merge(User.matches_ip(value)) : Account.none
|
||||||
when 'staff'
|
when 'staff'
|
||||||
accounts_with_users.merge User.staff
|
accounts_with_users.merge(User.staff)
|
||||||
|
when 'order'
|
||||||
|
order_scope(value)
|
||||||
else
|
else
|
||||||
raise "Unknown filter: #{key}"
|
raise "Unknown filter: #{key}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def order_scope(value)
|
||||||
|
case value
|
||||||
|
when 'active'
|
||||||
|
params['remote'] ? Account.joins(:account_stat).by_recent_status : Account.joins(:user).by_recent_sign_in
|
||||||
|
when 'recent'
|
||||||
|
Account.recent
|
||||||
|
when 'alphabetic'
|
||||||
|
Account.alphabetic
|
||||||
|
else
|
||||||
|
raise "Unknown order: #{value}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def accounts_with_users
|
def accounts_with_users
|
||||||
Account.joins(:user)
|
Account.joins(:user)
|
||||||
end
|
end
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
%td
|
%td
|
||||||
- if account.user_current_sign_in_at
|
- if account.user_current_sign_in_at
|
||||||
%time.time-ago{ datetime: account.user_current_sign_in_at.iso8601, title: l(account.user_current_sign_in_at) }= l account.user_current_sign_in_at
|
%time.time-ago{ datetime: account.user_current_sign_in_at.iso8601, title: l(account.user_current_sign_in_at) }= l account.user_current_sign_in_at
|
||||||
|
- elsif account.last_status_at.present?
|
||||||
|
%time.time-ago{ datetime: account.last_status_at.iso8601, title: l(account.last_status_at) }= l account.last_status_at
|
||||||
- else
|
- else
|
||||||
\-
|
\-
|
||||||
%td
|
%td
|
||||||
|
@ -19,6 +19,12 @@
|
|||||||
%ul
|
%ul
|
||||||
%li= filter_link_to t('admin.accounts.moderation.all'), staff: nil
|
%li= filter_link_to t('admin.accounts.moderation.all'), staff: nil
|
||||||
%li= filter_link_to t('admin.accounts.roles.staff'), staff: '1'
|
%li= filter_link_to t('admin.accounts.roles.staff'), staff: '1'
|
||||||
|
.filter-subset
|
||||||
|
%strong= t 'generic.order_by'
|
||||||
|
%ul
|
||||||
|
%li= filter_link_to t('relationships.most_recent'), order: nil
|
||||||
|
%li= filter_link_to t('admin.accounts.username'), order: 'alphabetic'
|
||||||
|
%li= filter_link_to t('relationships.last_active'), order: 'active'
|
||||||
|
|
||||||
= form_tag admin_accounts_url, method: 'GET', class: 'simple_form' do
|
= form_tag admin_accounts_url, method: 'GET', class: 'simple_form' do
|
||||||
.fields-group
|
.fields-group
|
||||||
|
Loading…
Reference in New Issue
Block a user