Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: allow site owners to disable impersonation #20783

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion config/discourse_defaults.conf
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,7 @@ pg_force_readonly_mode = false
dns_query_timeout_secs =

# Default global regex timeout
regex_timeout_seconds =
regex_timeout_seconds =

# Allow impersonation function on the cluster to admins
allow_impersonation = true
2 changes: 1 addition & 1 deletion lib/guardian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def can_see_groups_members?(groups)

# Can we impersonate this user?
def can_impersonate?(target)
target &&
GlobalSetting.allow_impersonation && target &&
# You must be an admin to impersonate
is_admin? &&
# You may not impersonate other admins unless you are a dev
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/guardian_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@
end

describe "can_impersonate?" do
it "disallows impersonation when disabled globally" do
global_setting :allow_impersonation, false
expect(Guardian.new(admin).can_impersonate?(moderator)).to be_falsey
end
it "allows impersonation correctly" do
expect(Guardian.new(admin).can_impersonate?(nil)).to be_falsey
expect(Guardian.new.can_impersonate?(user)).to be_falsey
Expand Down