Fix changed filter params in admin APIs
Fix approve and reject actions not being logged from individual actions
This commit is contained in:
parent
d78ddb1cea
commit
5b5cc4b3fa
58 changed files with 83 additions and 91 deletions
|
@ -48,12 +48,14 @@ module Admin
|
|||
|
||||
def approve
|
||||
authorize @account.user, :approve?
|
||||
log_action :approve, @account.user
|
||||
@account.user.approve!
|
||||
redirect_to admin_accounts_path(status: 'pending'), notice: I18n.t('admin.accounts.approved_msg', username: @account.acct)
|
||||
end
|
||||
|
||||
def reject
|
||||
authorize @account.user, :reject?
|
||||
log_action :reject, @account.user, username: @account.username
|
||||
DeleteAccountService.new.call(@account, reserve_email: false, reserve_username: false)
|
||||
redirect_to admin_accounts_path(status: 'pending'), notice: I18n.t('admin.accounts.rejected_msg', username: @account.acct)
|
||||
end
|
||||
|
|
|
@ -48,7 +48,7 @@ module Admin
|
|||
private
|
||||
|
||||
def filtered_reports
|
||||
ReportFilter.new(filter_params).results.order(id: :desc).includes(:account, :target_account)
|
||||
ReportFilter.new(filter_params).results.includes(:account, :target_account)
|
||||
end
|
||||
|
||||
def filter_params
|
||||
|
|
|
@ -15,24 +15,7 @@ class Api::V1::Admin::AccountsController < Api::BaseController
|
|||
|
||||
after_action :insert_pagination_headers, only: :index
|
||||
|
||||
FILTER_PARAMS = %i(
|
||||
local
|
||||
remote
|
||||
by_domain
|
||||
active
|
||||
pending
|
||||
disabled
|
||||
sensitized
|
||||
silenced
|
||||
suspended
|
||||
username
|
||||
display_name
|
||||
email
|
||||
ip
|
||||
staff
|
||||
).freeze
|
||||
|
||||
PAGINATION_PARAMS = (%i(limit) + FILTER_PARAMS).freeze
|
||||
PAGINATION_PARAMS = (%i(limit) + AccountFilter::KEYS).freeze
|
||||
|
||||
def index
|
||||
authorize :account, :index?
|
||||
|
@ -53,12 +36,14 @@ class Api::V1::Admin::AccountsController < Api::BaseController
|
|||
|
||||
def approve
|
||||
authorize @account.user, :approve?
|
||||
log_action(:approve, @account.user)
|
||||
@account.user.approve!
|
||||
render json: @account, serializer: REST::Admin::AccountSerializer
|
||||
end
|
||||
|
||||
def reject
|
||||
authorize @account.user, :reject?
|
||||
log_action(:reject, @account.user, username: @account.username)
|
||||
DeleteAccountService.new.call(@account, reserve_email: false, reserve_username: false)
|
||||
render json: @account, serializer: REST::Admin::AccountSerializer
|
||||
end
|
||||
|
@ -94,7 +79,7 @@ class Api::V1::Admin::AccountsController < Api::BaseController
|
|||
private
|
||||
|
||||
def set_accounts
|
||||
@accounts = filtered_accounts.order(id: :desc).includes(user: [:invite_request, :invite]).to_a_paginated_by_id(limit_param(LIMIT), params_slice(:max_id, :since_id, :min_id))
|
||||
@accounts = filtered_accounts.to_a_paginated_by_id(limit_param(LIMIT), params_slice(:max_id, :since_id, :min_id))
|
||||
end
|
||||
|
||||
def set_account
|
||||
|
@ -102,11 +87,11 @@ class Api::V1::Admin::AccountsController < Api::BaseController
|
|||
end
|
||||
|
||||
def filtered_accounts
|
||||
AccountFilter.new(filter_params).results
|
||||
AccountFilter.new(filter_params.with_defaults(order: 'recent')).results
|
||||
end
|
||||
|
||||
def filter_params
|
||||
params.permit(*FILTER_PARAMS)
|
||||
params.slice(*AccountFilter::KEYS).permit(*AccountFilter::KEYS)
|
||||
end
|
||||
|
||||
def insert_pagination_headers
|
||||
|
|
|
@ -14,13 +14,7 @@ class Api::V1::Admin::ReportsController < Api::BaseController
|
|||
|
||||
after_action :insert_pagination_headers, only: :index
|
||||
|
||||
FILTER_PARAMS = %i(
|
||||
resolved
|
||||
account_id
|
||||
target_account_id
|
||||
).freeze
|
||||
|
||||
PAGINATION_PARAMS = (%i(limit) + FILTER_PARAMS).freeze
|
||||
PAGINATION_PARAMS = (%i(limit) + ReportFilter::KEYS).freeze
|
||||
|
||||
def index
|
||||
authorize :report, :index?
|
||||
|
@ -75,7 +69,7 @@ class Api::V1::Admin::ReportsController < Api::BaseController
|
|||
end
|
||||
|
||||
def filter_params
|
||||
params.permit(*FILTER_PARAMS)
|
||||
params.slice(*ReportFilter::KEYS).permit(*ReportFilter::KEYS)
|
||||
end
|
||||
|
||||
def insert_pagination_headers
|
||||
|
|
|
@ -21,7 +21,7 @@ class AccountFilter
|
|||
end
|
||||
|
||||
def results
|
||||
scope = Account.includes(:account_stat, user: [:session_activations, :invite_request]).without_instance_actor.reorder(nil)
|
||||
scope = Account.includes(:account_stat, user: [:ips, :invite, :invite_request]).without_instance_actor.reorder(nil)
|
||||
|
||||
params.each do |key, value|
|
||||
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
class ReportFilter
|
||||
KEYS = %i(
|
||||
resolved
|
||||
status
|
||||
account_id
|
||||
target_account_id
|
||||
by_target_domain
|
||||
target_domain
|
||||
target_origin
|
||||
).freeze
|
||||
|
||||
|
@ -16,7 +16,7 @@ class ReportFilter
|
|||
end
|
||||
|
||||
def results
|
||||
scope = Report.unresolved
|
||||
scope = Report.order(id: :desc)
|
||||
|
||||
params.each do |key, value|
|
||||
scope = scope.merge scope_for(key, value)
|
||||
|
@ -27,10 +27,10 @@ class ReportFilter
|
|||
|
||||
def scope_for(key, value)
|
||||
case key.to_sym
|
||||
when :by_target_domain
|
||||
when :target_domain
|
||||
Report.where(target_account: Account.where(domain: value))
|
||||
when :resolved
|
||||
Report.resolved
|
||||
when :status
|
||||
status_scope(value)
|
||||
when :account_id
|
||||
Report.where(account_id: value)
|
||||
when :target_account_id
|
||||
|
@ -52,4 +52,15 @@ class ReportFilter
|
|||
raise "Unknown value: #{value}"
|
||||
end
|
||||
end
|
||||
|
||||
def status_scope(value)
|
||||
case value.to_sym
|
||||
when :resolved
|
||||
Report.resolved
|
||||
when :unresolved
|
||||
Report.unresolved
|
||||
else
|
||||
raise "Unknown value: #{value}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
.filter-subset
|
||||
%strong= t('admin.reports.status')
|
||||
%ul
|
||||
%li= filter_link_to t('admin.reports.unresolved'), resolved: nil
|
||||
%li= filter_link_to t('admin.reports.resolved'), resolved: '1'
|
||||
%li= filter_link_to t('admin.reports.unresolved'), status: 'unresolved'
|
||||
%li= filter_link_to t('admin.reports.resolved'), status: 'resolved'
|
||||
.filter-subset
|
||||
%strong= t('admin.reports.target_origin')
|
||||
%ul
|
||||
|
@ -19,7 +19,7 @@
|
|||
- ReportFilter::KEYS.each do |key|
|
||||
= hidden_field_tag key, params[key] if params[key].present?
|
||||
|
||||
- %i(by_target_domain).each do |key|
|
||||
- %i(target_domain).each do |key|
|
||||
.input.string.optional
|
||||
= text_field_tag key, params[key], class: 'string optional', placeholder: I18n.t("admin.reports.#{key}")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue