0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 16:57:36 +08:00
discourse/spec/requests/access_control_lists_controller_spec.rb
Martin Brennan 7ff30d81a3
FEATURE: Support users in DAccessControl and backend (#41358)
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>
2026-07-15 09:18:06 +10:00

52 lines
1.6 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe AccessControlListsController do
fab!(:current_user, :user)
describe "#search_grantees" do
before { sign_in(current_user) }
it "returns matching users and groups", :aggregate_failures do
user = Fabricate(:user, username: "acl_search_user")
group = Fabricate(:group, name: "acl_search_group", full_name: "ACL search group")
get "/access-control/grantees/search.json", params: { term: "acl_search" }
expect(response.status).to eq(200)
expect(response.parsed_body["users"].map { |result| result["id"] }).to contain_exactly(
user.id,
)
expect(response.parsed_body["groups"]).to contain_exactly(
{
"id" => group.id,
"name" => group.name,
"full_name" => group.full_name,
"display_name" => group.full_name,
"automatic" => false,
},
)
end
it "returns no results for a blank term", :aggregate_failures do
get "/access-control/grantees/search.json", params: { term: "" }
expect(response.status).to eq(200)
expect(response.parsed_body).to eq({ "users" => [], "groups" => [] })
end
include_examples "invalid limit params",
"/access-control/grantees/search.json",
described_class::SEARCH_GRANTEES_LIMIT,
params: {
term: "acl_search",
}
end
context "when logged out" do
it "requires login" do
get "/access-control/grantees/search.json", params: { term: "acl_search" }
expect(response.status).to eq(403)
end
end
end