mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user