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>
56 lines
1.4 KiB
Ruby
Vendored
56 lines
1.4 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class AccessControlList::SearchGrantees
|
|
include Service::Base
|
|
|
|
MAX_RESULTS = 50
|
|
|
|
params do
|
|
attribute :term, :string
|
|
attribute :limit, :integer
|
|
|
|
validates :limit,
|
|
presence: true,
|
|
numericality: {
|
|
only_integer: true,
|
|
greater_than: 0,
|
|
less_than_or_equal_to: AccessControlList::SearchGrantees::MAX_RESULTS,
|
|
}
|
|
end
|
|
|
|
model :search_term, optional: true
|
|
model :visible_groups, optional: true
|
|
model :users, optional: true
|
|
model :groups, optional: true
|
|
|
|
private
|
|
|
|
def fetch_search_term(params:)
|
|
params.term.to_s.strip.presence
|
|
end
|
|
|
|
def fetch_visible_groups(guardian:)
|
|
Group.visible_groups(
|
|
guardian.user,
|
|
"groups.name ASC",
|
|
include_everyone: !SiteSetting.granular_anonymous_and_logged_in_groups_permissions,
|
|
include_pseudogroups: SiteSetting.granular_anonymous_and_logged_in_groups_permissions,
|
|
)
|
|
end
|
|
|
|
def fetch_users(search_term:, params:, guardian:)
|
|
if search_term.present?
|
|
UserSearch.new(search_term, searching_user: guardian.user, limit: params.limit).search
|
|
else
|
|
[]
|
|
end
|
|
end
|
|
|
|
def fetch_groups(search_term:, visible_groups:, params:)
|
|
if search_term.present?
|
|
Group.search_groups(search_term, groups: visible_groups, sort: :auto).limit(params.limit)
|
|
else
|
|
[]
|
|
end
|
|
end
|
|
end
|