Fix changed filter params in admin APIs

Fix approve and reject actions not being logged from individual actions
This commit is contained in:
Eugen Rochko 2021-12-26 00:39:05 +01:00
parent d78ddb1cea
commit 5b5cc4b3fa
58 changed files with 83 additions and 91 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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