discourse/lib/impersonator_constraint.rb
Ted Johansson b24a3d81ed
DEV: Allow impersonation without session swapping (#34213)
The current impersonation feature works by signing you in as the user you are impersonating. This has the side effect of invalidating your own session and forcing you to log out and in again.

In this experimental implementation you keep your existing session, but DefaultCurrentUserProvider returns the user being impersonated, allowing you to see the site from their perspective.
2025-08-21 14:18:15 +08:00

10 lines
256 B
Ruby

# frozen_string_literal: true
class ImpersonatorConstraint
def matches?(request)
current_user = CurrentUser.lookup_from_env(request.env)
!!current_user&.is_impersonating
rescue Discourse::InvalidAccess, Discourse::ReadOnly
false
end
end