mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-25 07:58:07 +08:00
### What is this change? This PR adds a countdown to the impersonation banner, corresponding to the time left out of the allotted time in the site setting. When the countdown reaches 0 impersonation ends. As part of this change, I made the `impersonate#destroy` endpoint idempotent and visible to all admins, whether they are impersonating or not. This prevents any "unexpected errors" from happening if there's a race to end impersonation. **Screenshot:** <img width="537" height="79" alt="Screenshot 2026-05-11 at 11 26 08 AM" src="https://github.com/user-attachments/assets/e44f6ef0-30ec-4050-ad08-e555c0e9f80a" />
32 lines
796 B
Ruby
Vendored
32 lines
796 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class Admin::ImpersonateController < Admin::AdminController
|
|
skip_before_action :ensure_admin, only: :destroy
|
|
|
|
def create
|
|
params.require(:username_or_email)
|
|
|
|
user = User.find_by_username_or_email(params[:username_or_email])
|
|
raise Discourse::NotFound if user.blank?
|
|
|
|
guardian.ensure_can_impersonate!(user)
|
|
|
|
StaffActionLogger.new(current_user).log_impersonate(user)
|
|
|
|
raise Discourse::InvalidAccess if current_user.is_impersonating
|
|
|
|
start_impersonating_user(user)
|
|
|
|
render body: nil
|
|
end
|
|
|
|
def destroy
|
|
if current_user.is_impersonating
|
|
impersonated_user = current_user
|
|
stop_impersonating_user
|
|
StaffActionLogger.new(current_user).log_stop_impersonation(impersonated_user)
|
|
end
|
|
|
|
render body: nil
|
|
end
|
|
end
|