mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 17:53:55 +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>
35 lines
1.2 KiB
Ruby
Vendored
35 lines
1.2 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class AccessControlListsController < ApplicationController
|
|
requires_login
|
|
|
|
SEARCH_GRANTEES_LIMIT = AccessControlList::SearchGrantees::MAX_RESULTS
|
|
|
|
# Used to search for _potential_ users and groups to grant access
|
|
# to a target for an ACL. Exposes same info as public /u and
|
|
# /g endpoints, hides groups not visible to the current user.
|
|
def search_grantees
|
|
limit = fetch_limit_from_params(default: SEARCH_GRANTEES_LIMIT, max: SEARCH_GRANTEES_LIMIT)
|
|
|
|
AccessControlList::SearchGrantees.call(
|
|
service_params.deep_merge(params: { term: params[:term], limit: }),
|
|
) do
|
|
on_success do |users:, groups:|
|
|
render json: { users: serialize_users(users), groups: serialize_groups(groups) }
|
|
end
|
|
|
|
on_failed_contract { |contract| render_json_error(contract.errors.full_messages) }
|
|
on_failure { render_json_error(I18n.t("generic_error")) }
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def serialize_users(users)
|
|
ActiveModel::ArraySerializer.new(users, each_serializer: FoundUserSerializer).as_json
|
|
end
|
|
|
|
def serialize_groups(groups)
|
|
ActiveModel::ArraySerializer.new(groups, each_serializer: FoundGroupSerializer).as_json
|
|
end
|
|
end
|