mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
FEAT: Allow admin delete user's associated accounts (#29018)
This commit introduces a feature that allows an admin to delete a user's associated account. After deletion, a log will be recorded in staff actions. ref=t/136675
This commit is contained in:
@ -26,6 +26,7 @@ class Admin::UsersController < Admin::StaffController
|
||||
disable_second_factor
|
||||
delete_posts_batch
|
||||
sso_record
|
||||
delete_associated_accounts
|
||||
]
|
||||
|
||||
def index
|
||||
@ -514,6 +515,29 @@ class Admin::UsersController < Admin::StaffController
|
||||
render json: success_json
|
||||
end
|
||||
|
||||
def delete_associated_accounts
|
||||
guardian.ensure_can_delete_user_associated_accounts!(@user)
|
||||
previous_value =
|
||||
@user
|
||||
.user_associated_accounts
|
||||
.select(:provider_name, :provider_uid, :info)
|
||||
.map do |associated_account|
|
||||
{
|
||||
provider: associated_account.provider_name,
|
||||
uid: associated_account.provider_uid,
|
||||
info: associated_account.info,
|
||||
}.to_s
|
||||
end
|
||||
.join(",")
|
||||
StaffActionLogger.new(current_user).log_delete_associated_accounts(
|
||||
@user,
|
||||
previous_value:,
|
||||
context: params[:context],
|
||||
)
|
||||
@user.user_associated_accounts.delete_all
|
||||
render json: success_json
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_user
|
||||
|
Reference in New Issue
Block a user