mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-04-28 23:01:26 +08:00
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.
10 lines
256 B
Ruby
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
|