mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
Followup 5823e4e3b2,
this commit allows the addition of users along with
groups to access control lists, modifying DAccessControl
to support selecting a user or group from the same
search input.
Shown here is a mix of user & group permissions in the
`DAccessControl` component:
<img width="611" height="664" alt="image"
src="https://github.com/user-attachments/assets/c25e13b0-8885-4ce7-972c-5116f3acb094"
/>
When the search opens, we show the site's groups that
the user can see as preloaded values, showing only the
group name for clarity:
<img width="612" height="389" alt="image"
src="https://github.com/user-attachments/assets/df93a94b-918e-4fed-b045-ac72f02aca41"
/>
When searching a GET request is sent and users are included
in search results.
<img width="608" height="404" alt="image"
src="https://github.com/user-attachments/assets/ff17e6c0-2505-480e-ae25-e6f8309555bc"
/>
---------
Co-authored-by: Jordan Vidrine <jordan@jordanvidrine.com>
101 lines
3.4 KiB
Ruby
Vendored
101 lines
3.4 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe Acl::User do
|
|
subject(:user_acl) { described_class.new(flattened_acl_list) }
|
|
|
|
fab!(:category)
|
|
fab!(:topic)
|
|
|
|
fab!(:other_topic, :topic)
|
|
|
|
let(:flattened_acl_list) do
|
|
[
|
|
{ type: :group, id: 10, permission: "view", target_type: "Category", target_id: category.id },
|
|
{ type: :group, id: 10, permission: "edit", target_type: "Category", target_id: category.id },
|
|
{ type: :group, id: 11, permission: "view", target_type: "Topic", target_id: topic.id },
|
|
]
|
|
end
|
|
|
|
describe "#has_target_permission?" do
|
|
it "returns true when the target record holds the permission" do
|
|
expect(user_acl.has_target_permission?(category, "view")).to eq(true)
|
|
end
|
|
|
|
it "accepts a target hash as well as a record" do
|
|
expect(
|
|
user_acl.has_target_permission?(
|
|
{ target_type: "Category", target_id: category.id },
|
|
"edit",
|
|
),
|
|
).to eq(true)
|
|
end
|
|
|
|
it "returns false when the target does not hold the permission" do
|
|
expect(user_acl.has_target_permission?(topic, "edit")).to eq(false)
|
|
end
|
|
|
|
it "returns nil for a target absent from the list" do
|
|
expect(user_acl.has_target_permission?(other_topic, "view")).to be_nil
|
|
end
|
|
end
|
|
|
|
describe "#has_any_target_permission?" do
|
|
it "returns true when the target holds any of the permissions" do
|
|
expect(user_acl.has_any_target_permission?(category, %w[manage edit])).to eq(true)
|
|
end
|
|
|
|
it "returns false when the target holds none of the permissions" do
|
|
expect(user_acl.has_any_target_permission?(topic, %w[edit manage])).to eq(false)
|
|
end
|
|
|
|
it "returns false for a target absent from the list" do
|
|
expect(user_acl.has_any_target_permission?(other_topic, %w[view edit])).to eq(false)
|
|
end
|
|
end
|
|
|
|
describe "#target_ids_with_permission" do
|
|
it "returns the target ids of the given class holding the permission" do
|
|
expect(user_acl.target_ids_with_permission(Category, "view")).to contain_exactly(category.id)
|
|
end
|
|
|
|
it "scopes the ids to the requested target class" do
|
|
expect(user_acl.target_ids_with_permission(Topic, "view")).to contain_exactly(topic.id)
|
|
end
|
|
|
|
it "returns an empty array when no target of that class holds the permission" do
|
|
expect(user_acl.target_ids_with_permission(Category, "manage")).to eq([])
|
|
end
|
|
|
|
it "returns an empty array when the class has no entry for the permission" do
|
|
expect(user_acl.target_ids_with_permission(Topic, "edit")).to eq([])
|
|
end
|
|
|
|
it "returns a defensive copy" do
|
|
user_acl.target_ids_with_permission(Category, "view").clear
|
|
|
|
expect(user_acl.target_ids_with_permission(Category, "view")).to contain_exactly(category.id)
|
|
end
|
|
end
|
|
|
|
describe "#target_ids_with_any_permissions" do
|
|
it "returns the unique target ids across all the permissions" do
|
|
expect(user_acl.target_ids_with_any_permissions(Category, %w[view edit])).to contain_exactly(
|
|
category.id,
|
|
)
|
|
end
|
|
|
|
it "scopes the combined ids to the requested target class" do
|
|
expect(user_acl.target_ids_with_any_permissions(Topic, %w[view edit])).to contain_exactly(
|
|
topic.id,
|
|
)
|
|
end
|
|
|
|
it "returns a defensive copy" do
|
|
user_acl.target_ids_with_any_permissions(Category, %w[view edit]).clear
|
|
|
|
expect(user_acl.target_ids_with_any_permissions(Category, %w[view edit])).to contain_exactly(
|
|
category.id,
|
|
)
|
|
end
|
|
end
|
|
end
|