Add batch suspend for accounts in admin UI (#17009)
parent
2e2ea6bb6b
commit
0fb9536d38
@ -1,52 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module Admin
|
|
||||||
class PendingAccountsController < BaseController
|
|
||||||
before_action :set_accounts, only: :index
|
|
||||||
|
|
||||||
def index
|
|
||||||
@form = Form::AccountBatch.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def batch
|
|
||||||
@form = Form::AccountBatch.new(form_account_batch_params.merge(current_account: current_account, action: action_from_button))
|
|
||||||
@form.save
|
|
||||||
rescue ActionController::ParameterMissing
|
|
||||||
flash[:alert] = I18n.t('admin.accounts.no_account_selected')
|
|
||||||
ensure
|
|
||||||
redirect_to admin_pending_accounts_path(current_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def approve_all
|
|
||||||
Form::AccountBatch.new(current_account: current_account, account_ids: User.pending.pluck(:account_id), action: 'approve').save
|
|
||||||
redirect_to admin_pending_accounts_path(current_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def reject_all
|
|
||||||
Form::AccountBatch.new(current_account: current_account, account_ids: User.pending.pluck(:account_id), action: 'reject').save
|
|
||||||
redirect_to admin_pending_accounts_path(current_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def set_accounts
|
|
||||||
@accounts = Account.joins(:user).merge(User.pending.recent).includes(user: :invite_request).page(params[:page])
|
|
||||||
end
|
|
||||||
|
|
||||||
def form_account_batch_params
|
|
||||||
params.require(:form_account_batch).permit(:action, account_ids: [])
|
|
||||||
end
|
|
||||||
|
|
||||||
def action_from_button
|
|
||||||
if params[:approve]
|
|
||||||
'approve'
|
|
||||||
elsif params[:reject]
|
|
||||||
'reject'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_params
|
|
||||||
params.slice(:page).permit(:page)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,10 +1,41 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Admin::DashboardHelper
|
module Admin::DashboardHelper
|
||||||
def feature_hint(feature, enabled)
|
def relevant_account_ip(account, ip_query)
|
||||||
indicator = safe_join([enabled ? t('simple_form.yes') : t('simple_form.no'), fa_icon('power-off fw')], ' ')
|
default_ip = [account.user_current_sign_in_ip || account.user_sign_up_ip]
|
||||||
class_names = enabled ? 'pull-right positive-hint' : 'pull-right neutral-hint'
|
|
||||||
|
|
||||||
safe_join([feature, content_tag(:span, indicator, class: class_names)])
|
matched_ip = begin
|
||||||
|
ip_query_addr = IPAddr.new(ip_query)
|
||||||
|
account.user.recent_ips.find { |(_, ip)| ip_query_addr.include?(ip) } || default_ip
|
||||||
|
rescue IPAddr::Error
|
||||||
|
default_ip
|
||||||
|
end.last
|
||||||
|
|
||||||
|
if matched_ip
|
||||||
|
link_to matched_ip, admin_accounts_path(ip: matched_ip)
|
||||||
|
else
|
||||||
|
'-'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def relevant_account_timestamp(account)
|
||||||
|
timestamp, exact = begin
|
||||||
|
if account.user_current_sign_in_at && account.user_current_sign_in_at < 24.hours.ago
|
||||||
|
[account.user_current_sign_in_at, true]
|
||||||
|
elsif account.user_current_sign_in_at
|
||||||
|
[account.user_current_sign_in_at, false]
|
||||||
|
elsif account.user_pending?
|
||||||
|
[account.user_created_at, true]
|
||||||
|
elsif account.last_status_at.present?
|
||||||
|
[account.last_status_at, true]
|
||||||
|
else
|
||||||
|
[nil, false]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return '-' if timestamp.nil?
|
||||||
|
return t('generic.today') unless exact
|
||||||
|
|
||||||
|
content_tag(:time, l(timestamp), class: 'time-ago', datetime: timestamp.iso8601, title: l(timestamp))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,24 +1,35 @@
|
|||||||
%tr
|
.batch-table__row{ class: [!account.suspended? && account.user_pending? && 'batch-table__row--attention', account.suspended? && 'batch-table__row--muted'] }
|
||||||
|
%label.batch-table__row__select.batch-table__row__select--aligned.batch-checkbox
|
||||||
|
= f.check_box :account_ids, { multiple: true, include_hidden: false }, account.id
|
||||||
|
.batch-table__row__content.batch-table__row__content--unpadded
|
||||||
|
%table.accounts-table
|
||||||
|
%tbody
|
||||||
|
%tr
|
||||||
%td
|
%td
|
||||||
= admin_account_link_to(account)
|
= account_link_to account, path: admin_account_path(account.id)
|
||||||
%td
|
%td.accounts-table__count.optional
|
||||||
%div.account-badges= account_badge(account, all: true)
|
- if account.suspended? || account.user_pending?
|
||||||
%td
|
|
||||||
- if account.user_current_sign_in_ip
|
|
||||||
%samp.ellipsized-ip{ title: account.user_current_sign_in_ip }= account.user_current_sign_in_ip
|
|
||||||
- else
|
|
||||||
\-
|
\-
|
||||||
%td
|
|
||||||
- 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
|
|
||||||
- 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
|
||||||
|
= friendly_number_to_human account.statuses_count
|
||||||
|
%small= t('accounts.posts', count: account.statuses_count).downcase
|
||||||
|
%td.accounts-table__count.optional
|
||||||
|
- if account.suspended? || account.user_pending?
|
||||||
\-
|
\-
|
||||||
%td
|
|
||||||
- if account.local? && account.user_pending?
|
|
||||||
= table_link_to 'check', t('admin.accounts.approve'), approve_admin_account_path(account.id), method: :post, data: { confirm: t('admin.accounts.are_you_sure') } if can?(:approve, account.user)
|
|
||||||
= table_link_to 'times', t('admin.accounts.reject'), reject_admin_account_path(account.id), method: :post, data: { confirm: t('admin.accounts.are_you_sure') } if can?(:reject, account.user)
|
|
||||||
- else
|
- else
|
||||||
= table_link_to 'circle', t('admin.accounts.web'), web_path("accounts/#{account.id}")
|
= friendly_number_to_human account.followers_count
|
||||||
= table_link_to 'globe', t('admin.accounts.public'), ActivityPub::TagManager.instance.url_for(account)
|
%small= t('accounts.followers', count: account.followers_count).downcase
|
||||||
|
%td.accounts-table__count
|
||||||
|
= relevant_account_timestamp(account)
|
||||||
|
%small= t('accounts.last_active')
|
||||||
|
%td.accounts-table__extra
|
||||||
|
- if account.local?
|
||||||
|
- if account.user_email
|
||||||
|
= link_to account.user_email.split('@').last, admin_accounts_path(email: "%@#{account.user_email.split('@').last}"), title: account.user_email
|
||||||
|
- else
|
||||||
|
\-
|
||||||
|
%br/
|
||||||
|
%samp.ellipsized-ip= relevant_account_ip(account, params[:ip])
|
||||||
|
- if !account.suspended? && account.user_pending? && account.user&.invite_request&.text&.present?
|
||||||
|
.batch-table__row__content__quote
|
||||||
|
%p= account.user&.invite_request&.text
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
.batch-table__row
|
|
||||||
%label.batch-table__row__select.batch-table__row__select--aligned.batch-checkbox
|
|
||||||
= f.check_box :account_ids, { multiple: true, include_hidden: false }, account.id
|
|
||||||
.batch-table__row__content.pending-account
|
|
||||||
.pending-account__header
|
|
||||||
= link_to admin_account_path(account.id) do
|
|
||||||
%strong= account.user_email
|
|
||||||
= "(@#{account.username})"
|
|
||||||
%br/
|
|
||||||
%samp= account.user_current_sign_in_ip
|
|
||||||
•
|
|
||||||
= t 'admin.accounts.time_in_queue', time: time_ago_in_words(account.user&.created_at)
|
|
||||||
|
|
||||||
- if account.user&.invite_request&.text&.present?
|
|
||||||
.pending-account__body
|
|
||||||
%p= account.user&.invite_request&.text
|
|
@ -1,33 +0,0 @@
|
|||||||
- content_for :page_title do
|
|
||||||
= t('admin.pending_accounts.title', count: User.pending.count)
|
|
||||||
|
|
||||||
- content_for :header_tags do
|
|
||||||
= javascript_pack_tag 'admin', async: true, crossorigin: 'anonymous'
|
|
||||||
|
|
||||||
= form_for(@form, url: batch_admin_pending_accounts_path) do |f|
|
|
||||||
= hidden_field_tag :page, params[:page] || 1
|
|
||||||
|
|
||||||
.batch-table
|
|
||||||
.batch-table__toolbar
|
|
||||||
%label.batch-table__toolbar__select.batch-checkbox-all
|
|
||||||
= check_box_tag :batch_checkbox_all, nil, false
|
|
||||||
.batch-table__toolbar__actions
|
|
||||||
= f.button safe_join([fa_icon('check'), t('admin.accounts.approve')]), name: :approve, class: 'table-action-link', type: :submit, data: { confirm: t('admin.reports.are_you_sure') }
|
|
||||||
|
|
||||||
= f.button safe_join([fa_icon('times'), t('admin.accounts.reject')]), name: :reject, class: 'table-action-link', type: :submit, data: { confirm: t('admin.reports.are_you_sure') }
|
|
||||||
.batch-table__body
|
|
||||||
- if @accounts.empty?
|
|
||||||
= nothing_here 'nothing-here--under-tabs'
|
|
||||||
- else
|
|
||||||
= render partial: 'account', collection: @accounts, locals: { f: f }
|
|
||||||
|
|
||||||
= paginate @accounts
|
|
||||||
|
|
||||||
%hr.spacer/
|
|
||||||
|
|
||||||
%div.action-buttons
|
|
||||||
%div
|
|
||||||
= link_to t('admin.accounts.approve_all'), approve_all_admin_pending_accounts_path, method: :post, data: { confirm: t('admin.accounts.are_you_sure') }, class: 'button'
|
|
||||||
|
|
||||||
%div
|
|
||||||
= link_to t('admin.accounts.reject_all'), reject_all_admin_pending_accounts_path, method: :post, data: { confirm: t('admin.accounts.are_you_sure') }, class: 'button button--destructive'
|
|
Loading…
Reference in new issue