FIX: doesn't translate group permission keys

This commit is contained in:
Régis Hanol 2018-08-21 12:56:56 +02:00
parent 0f07494b12
commit 3e436e2daf
2 changed files with 28 additions and 5 deletions

View File

@ -12,12 +12,14 @@ class TagGroupSerializer < ApplicationSerializer
def permissions
@permissions ||= begin
h = {}
object.tag_group_permissions.joins(:group).includes(:group).order("groups.name").each do |tgp|
h[tgp.group.name] = tgp.permission_type
end
if h.size == 0
h['everyone'] = TagGroupPermission.permission_types[:full]
object.tag_group_permissions.joins(:group).includes(:group).find_each do |tgp|
name = Group::AUTO_GROUP_IDS.fetch(tgp.group_id, tgp.group.name).to_s
h[name] = tgp.permission_type
end
h["everyone"] = TagGroupPermission.permission_types[:full] if h.empty?
h
end
end

View 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