mirror of
https://github.com/discourse/discourse.git
synced 2025-06-09 04:26:56 +08:00
FIX: doesn't translate group permission keys
This commit is contained in:
@ -12,12 +12,14 @@ class TagGroupSerializer < ApplicationSerializer
|
|||||||
def permissions
|
def permissions
|
||||||
@permissions ||= begin
|
@permissions ||= begin
|
||||||
h = {}
|
h = {}
|
||||||
object.tag_group_permissions.joins(:group).includes(:group).order("groups.name").each do |tgp|
|
|
||||||
h[tgp.group.name] = tgp.permission_type
|
object.tag_group_permissions.joins(:group).includes(:group).find_each do |tgp|
|
||||||
end
|
name = Group::AUTO_GROUP_IDS.fetch(tgp.group_id, tgp.group.name).to_s
|
||||||
if h.size == 0
|
h[name] = tgp.permission_type
|
||||||
h['everyone'] = TagGroupPermission.permission_types[:full]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
h["everyone"] = TagGroupPermission.permission_types[:full] if h.empty?
|
||||||
|
|
||||||
h
|
h
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
21
spec/serializers/tag_group_serializer_spec.rb
Normal file
21
spec/serializers/tag_group_serializer_spec.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe TagGroupSerializer do
|
||||||
|
|
||||||
|
it "doesn't translate automatic group names in permissions" do
|
||||||
|
staff_group = Group.find(Group::AUTO_GROUPS[:staff])
|
||||||
|
staff_group.update_columns(name: "custom")
|
||||||
|
|
||||||
|
tag_group = Fabricate(:tag_group)
|
||||||
|
tag_group.permissions = [[
|
||||||
|
Group::AUTO_GROUPS[:staff],
|
||||||
|
TagGroupPermission.permission_types[:full]
|
||||||
|
]]
|
||||||
|
tag_group.save!
|
||||||
|
|
||||||
|
serialized = TagGroupSerializer.new(tag_group, root: false).as_json
|
||||||
|
|
||||||
|
expect(serialized[:permissions].keys).to contain_exactly("staff")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Reference in New Issue
Block a user