FIX: ensure GroupChooser works with localized group names (#30593)

The "Tag Groups Form" component was using group names to handle
permissions. This works just fine when the default locale is "English"
but breaks as soon as it's changed to a different locale.

The fix is to use the group id's for handling the permissions instead of
the group name.

Reported in https://meta.discourse.org/t/221849
This commit is contained in:
Régis Hanol
2025-01-13 11:29:04 +01:00
committed by GitHub
parent 79b68bc32b
commit 03119312b5
9 changed files with 65 additions and 142 deletions

View File

@@ -762,6 +762,8 @@ class Group < ActiveRecord::Base
def self.group_id_from_param(group_param)
return group_param.id if group_param.is_a?(Group)
return group_param if group_param.is_a?(Integer)
return Group[group_param].id if group_param.is_a?(Symbol)
return group_param.to_i if group_param.to_i.to_s == group_param
# subtle, using Group[] ensures the group exists in the DB
Group[group_param.to_sym].id

View File

@@ -56,9 +56,12 @@ class TagGroup < ActiveRecord::Base
def self.resolve_permissions(permissions)
permissions.map do |group, permission|
group_id = Group.group_id_from_param(group)
permission = TagGroupPermission.permission_types[permission.to_sym] unless permission.is_a?(
Integer,
)
permission =
if permission.is_a?(Integer)
permission
else
TagGroupPermission.permission_types[permission.to_sym]
end
[group_id, permission]
end
end