0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 16:57:36 +08:00
discourse/lib/theme_settings_manager/list.rb
Martin Brennan fc8df41adb
DEV: Add disallowed_groups to theme/component settings (#41792)
Further following on from bee1be8599,
this brings greater parity between theme settings and site settings.

This commit adds a new `disallowed_groups` field to theme and component
settings, which allows theme authors to specify groups that cannot be
selected
by admins for a particular list type or object group type setting.

This is useful for cases where the group-based setting isn't usable
for a group like e.g. anonymous_users, no point allowing them for
a setting that requires a user to be logged in to take effect.

c.f.
https://meta.discourse.org/t/granular-group-based-permissions-for-anonymous-and-logged-in-users/402273/18?u=martin

### List groups

With `disallowed_groups: "4|5"` specified (`logged_in_users` &
`anonymous_users`)

<img width="734" height="450" alt="image"
src="https://github.com/user-attachments/assets/ed8d7338-65fa-44e6-8dce-7073a87076e6"
/>

### Object groups

With `disallowed_groups: "4|5"` specified (`logged_in_users` &
`anonymous_users`)

<img width="696" height="725" alt="image"
src="https://github.com/user-attachments/assets/1a9103d4-cf44-4038-9d62-3838cb779b49"
/>
2026-07-20 09:28:52 +10:00

20 lines
498 B
Ruby
Vendored

# frozen_string_literal: true
class ThemeSettingsManager::List < ThemeSettingsManager
def list_type
@opts[:list_type]
end
def resolve_group_membership?
@opts[:resolve_group_membership] && list_type == "group"
end
def value=(new_value)
if list_type == "group" && disallowed_groups.present?
disallowed_ids = disallowed_groups.to_s.split("|")
new_value = new_value.to_s.split("|").reject { |id| disallowed_ids.include?(id) }.join("|")
end
super
end
end