discourse-shared-edits/spec/lib/guardian_spec.rb
Sam 4e51a4e231
Some checks failed
Discourse Plugin / ci (push) Has been cancelled
FEATURE: allow shared edits to be enabled on any group (#163)
Allow sites to choose which groups can enable or disable shared edits instead of hardcoding staff and TL4 users. Expose the permission on the current user serializer so the admin menu can hide toggle actions for unauthorized users.

Add rate limits to privileged reset and recover endpoints, and update specs, acceptance tests, docs, and settings copy for the new permission model.

* Update config/settings.yml

Co-authored-by: Martin Brennan <martin@discourse.org>

* fix spec

---------

Co-authored-by: Martin Brennan <martin@discourse.org>
2026-06-25 16:28:07 +10:00

62 lines
2 KiB
Ruby

# frozen_string_literal: true
RSpec.describe Guardian do
fab!(:moderator)
fab!(:admin)
fab!(:user)
fab!(:tl4_user) { Fabricate(:user, trust_level: TrustLevel[4], refresh_auto_groups: true) }
fab!(:group)
describe "#can_toggle_shared_edits?" do
context "when shared edits are enabled" do
before do
SiteSetting.shared_edits_enabled = true
SiteSetting.shared_edits_toggle_allowed_groups = "1|2|14"
end
it "allows the default groups" do
aggregate_failures do
expect(Guardian.new(admin)).to be_can_toggle_shared_edits
expect(Guardian.new(moderator)).to be_can_toggle_shared_edits
expect(Guardian.new(tl4_user)).to be_can_toggle_shared_edits
end
end
it "disallows users outside the configured groups" do
expect(Guardian.new(user)).not_to be_can_toggle_shared_edits
end
it "disallows anonymous users" do
expect(Guardian.new).not_to be_can_toggle_shared_edits
end
it "uses the configured groups" do
SiteSetting.shared_edits_toggle_allowed_groups = group.id.to_s
group.add(user)
user.reload
aggregate_failures do
expect(Guardian.new(user)).to be_can_toggle_shared_edits
expect(Guardian.new(admin)).to be_can_toggle_shared_edits
expect(Guardian.new(moderator)).not_to be_can_toggle_shared_edits
expect(Guardian.new(tl4_user)).not_to be_can_toggle_shared_edits
end
end
end
context "when shared edits are disabled" do
before do
SiteSetting.shared_edits_enabled = false
SiteSetting.shared_edits_toggle_allowed_groups = "1|2|14"
end
it "disallows users in configured groups" do
aggregate_failures do
expect(Guardian.new(admin)).not_to be_can_toggle_shared_edits
expect(Guardian.new(moderator)).not_to be_can_toggle_shared_edits
expect(Guardian.new(tl4_user)).not_to be_can_toggle_shared_edits
end
end
end
end
end