FIX: Serialize permissions for everyone group

The permissions for the 'everyone' group were not serialized because
the list of groups a user can view did not include it. This bug was
introduced in commit dfaf9831f7.
This commit is contained in:
Bianca Nenciu 2022-04-07 12:21:29 +03:00 committed by Alan Guo Xiang Tan
parent 499793cbbc
commit 07d8189edd
2 changed files with 14 additions and 2 deletions

View File

@ -37,7 +37,7 @@ class CategorySerializer < SiteCategorySerializer
.category_groups
.joins(:group)
.includes(:group)
.merge(Group.visible_groups(scope&.user, "groups.name ASC"))
.merge(Group.visible_groups(scope&.user, "groups.name ASC", include_everyone: true))
.map do |cg|
{
permission_type: cg.permission_type,

View File

@ -98,7 +98,19 @@ describe CategorySerializer do
expect(json[:group_permissions]).to eq([
{ permission_type: CategoryGroup.permission_types[:readonly], group_name: group.name },
{ permission_type: CategoryGroup.permission_types[:full], group_name: private_group.name },
{ permission_type: CategoryGroup.permission_types[:full], group_name: user_group.name }
{ permission_type: CategoryGroup.permission_types[:full], group_name: user_group.name },
{ permission_type: CategoryGroup.permission_types[:readonly], group_name: 'everyone' },
])
end
it "returns the group permissions for everyone group too" do
category.set_permissions(everyone: :readonly)
category.save!
json = described_class.new(category, scope: Guardian.new(admin), root: false).as_json
expect(json[:group_permissions]).to eq([
{ permission_type: CategoryGroup.permission_types[:readonly], group_name: 'everyone' },
])
end
end