mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 05:42:36 +08:00
Allows the use of `type:group` in plugins to select only 1 group in the
UI:
```
some_group:
default: ""
type: "group"
```
<img width="712" height="108" alt="CleanShot 2026-06-17 at 12 59 40"
src="https://github.com/user-attachments/assets/36d328e9-3a3b-4e01-b6f1-a754b8657114"
/>
18 lines
381 B
Ruby
Vendored
18 lines
381 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class GroupSettingValidator
|
|
def initialize(opts = {})
|
|
@opts = opts
|
|
end
|
|
|
|
def valid_value?(val)
|
|
return true if val.blank?
|
|
|
|
group_id = Integer(val, exception: false)
|
|
(group_id.present? && Group.exists?(id: group_id)) || Group.exists?(name: val)
|
|
end
|
|
|
|
def error_message
|
|
I18n.t("site_settings.errors.invalid_group")
|
|
end
|
|
end
|