Commit 17c5e274 authored by Stan Hu's avatar Stan Hu

Merge branch 'issue_32364' into 'master'

Fix permissions for group milestones

See merge request gitlab-org/gitlab!17783
parents af80dec7 28930bc7
...@@ -44,25 +44,25 @@ class GroupPolicy < BasePolicy ...@@ -44,25 +44,25 @@ class GroupPolicy < BasePolicy
rule { public_group }.policy do rule { public_group }.policy do
enable :read_group enable :read_group
enable :read_list
enable :read_label
end end
rule { logged_in_viewable }.enable :read_group rule { logged_in_viewable }.enable :read_group
rule { guest }.policy do rule { guest }.policy do
enable :read_group enable :read_group
enable :read_list
enable :upload_file enable :upload_file
enable :read_label
end end
rule { admin }.enable :read_group rule { admin }.enable :read_group
rule { has_projects }.policy do rule { has_projects }.policy do
enable :read_group
end
rule { can?(:read_group) }.policy do
enable :read_milestone
enable :read_list enable :read_list
enable :read_label enable :read_label
enable :read_group
end end
rule { has_access }.enable :read_namespace rule { has_access }.enable :read_namespace
......
# frozen_string_literal: true # frozen_string_literal: true
class MilestonePolicy < BasePolicy class MilestonePolicy < BasePolicy
delegate { @subject.project } delegate { @subject.parent }
end end
---
title: Fix permissions for group milestones
merge_request:
author:
type: fixed
...@@ -9,6 +9,7 @@ describe GroupPolicy do ...@@ -9,6 +9,7 @@ describe GroupPolicy do
it do it do
expect_allowed(:read_group) expect_allowed(:read_group)
expect_allowed(*read_group_permissions)
expect_disallowed(:upload_file) expect_disallowed(:upload_file)
expect_disallowed(*reporter_permissions) expect_disallowed(*reporter_permissions)
expect_disallowed(*developer_permissions) expect_disallowed(*developer_permissions)
...@@ -27,6 +28,7 @@ describe GroupPolicy do ...@@ -27,6 +28,7 @@ describe GroupPolicy do
end end
it { expect_disallowed(:read_group) } it { expect_disallowed(:read_group) }
it { expect_disallowed(*read_group_permissions) }
end end
context 'with foreign user and public project' do context 'with foreign user and public project' do
...@@ -39,6 +41,7 @@ describe GroupPolicy do ...@@ -39,6 +41,7 @@ describe GroupPolicy do
end end
it { expect_disallowed(:read_group) } it { expect_disallowed(:read_group) }
it { expect_disallowed(*read_group_permissions) }
end end
context 'has projects' do context 'has projects' do
...@@ -49,13 +52,13 @@ describe GroupPolicy do ...@@ -49,13 +52,13 @@ describe GroupPolicy do
project.add_developer(current_user) project.add_developer(current_user)
end end
it { expect_allowed(:read_label, :read_list) } it { expect_allowed(*read_group_permissions) }
context 'in subgroups' do context 'in subgroups' do
let(:subgroup) { create(:group, :private, parent: group) } let(:subgroup) { create(:group, :private, parent: group) }
let(:project) { create(:project, namespace: subgroup) } let(:project) { create(:project, namespace: subgroup) }
it { expect_allowed(:read_label, :read_list) } it { expect_allowed(*read_group_permissions) }
end end
end end
...@@ -63,6 +66,7 @@ describe GroupPolicy do ...@@ -63,6 +66,7 @@ describe GroupPolicy do
let(:current_user) { guest } let(:current_user) { guest }
it do it do
expect_allowed(*read_group_permissions)
expect_allowed(*guest_permissions) expect_allowed(*guest_permissions)
expect_disallowed(*reporter_permissions) expect_disallowed(*reporter_permissions)
expect_disallowed(*developer_permissions) expect_disallowed(*developer_permissions)
...@@ -75,6 +79,7 @@ describe GroupPolicy do ...@@ -75,6 +79,7 @@ describe GroupPolicy do
let(:current_user) { reporter } let(:current_user) { reporter }
it do it do
expect_allowed(*read_group_permissions)
expect_allowed(*guest_permissions) expect_allowed(*guest_permissions)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_disallowed(*developer_permissions) expect_disallowed(*developer_permissions)
...@@ -87,6 +92,7 @@ describe GroupPolicy do ...@@ -87,6 +92,7 @@ describe GroupPolicy do
let(:current_user) { developer } let(:current_user) { developer }
it do it do
expect_allowed(*read_group_permissions)
expect_allowed(*guest_permissions) expect_allowed(*guest_permissions)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_allowed(*developer_permissions) expect_allowed(*developer_permissions)
...@@ -110,6 +116,7 @@ describe GroupPolicy do ...@@ -110,6 +116,7 @@ describe GroupPolicy do
updated_owner_permissions = updated_owner_permissions =
owner_permissions - create_subgroup_permission owner_permissions - create_subgroup_permission
expect_allowed(*read_group_permissions)
expect_allowed(*guest_permissions) expect_allowed(*guest_permissions)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_allowed(*developer_permissions) expect_allowed(*developer_permissions)
...@@ -120,6 +127,7 @@ describe GroupPolicy do ...@@ -120,6 +127,7 @@ describe GroupPolicy do
context 'with subgroup_creation_level set to owner' do context 'with subgroup_creation_level set to owner' do
it 'allows every maintainer permission' do it 'allows every maintainer permission' do
expect_allowed(*read_group_permissions)
expect_allowed(*guest_permissions) expect_allowed(*guest_permissions)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_allowed(*developer_permissions) expect_allowed(*developer_permissions)
...@@ -133,6 +141,7 @@ describe GroupPolicy do ...@@ -133,6 +141,7 @@ describe GroupPolicy do
let(:current_user) { owner } let(:current_user) { owner }
it do it do
expect_allowed(*read_group_permissions)
expect_allowed(*guest_permissions) expect_allowed(*guest_permissions)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_allowed(*developer_permissions) expect_allowed(*developer_permissions)
...@@ -145,6 +154,7 @@ describe GroupPolicy do ...@@ -145,6 +154,7 @@ describe GroupPolicy do
let(:current_user) { admin } let(:current_user) { admin }
it do it do
expect_allowed(*read_group_permissions)
expect_allowed(*guest_permissions) expect_allowed(*guest_permissions)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_allowed(*developer_permissions) expect_allowed(*developer_permissions)
...@@ -176,6 +186,7 @@ describe GroupPolicy do ...@@ -176,6 +186,7 @@ describe GroupPolicy do
let(:current_user) { nil } let(:current_user) { nil }
it do it do
expect_disallowed(*read_group_permissions)
expect_disallowed(*guest_permissions) expect_disallowed(*guest_permissions)
expect_disallowed(*reporter_permissions) expect_disallowed(*reporter_permissions)
expect_disallowed(*developer_permissions) expect_disallowed(*developer_permissions)
...@@ -188,6 +199,7 @@ describe GroupPolicy do ...@@ -188,6 +199,7 @@ describe GroupPolicy do
let(:current_user) { guest } let(:current_user) { guest }
it do it do
expect_allowed(*read_group_permissions)
expect_allowed(*guest_permissions) expect_allowed(*guest_permissions)
expect_disallowed(*reporter_permissions) expect_disallowed(*reporter_permissions)
expect_disallowed(*developer_permissions) expect_disallowed(*developer_permissions)
...@@ -200,6 +212,7 @@ describe GroupPolicy do ...@@ -200,6 +212,7 @@ describe GroupPolicy do
let(:current_user) { reporter } let(:current_user) { reporter }
it do it do
expect_allowed(*read_group_permissions)
expect_allowed(*guest_permissions) expect_allowed(*guest_permissions)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_disallowed(*developer_permissions) expect_disallowed(*developer_permissions)
...@@ -212,6 +225,7 @@ describe GroupPolicy do ...@@ -212,6 +225,7 @@ describe GroupPolicy do
let(:current_user) { developer } let(:current_user) { developer }
it do it do
expect_allowed(*read_group_permissions)
expect_allowed(*guest_permissions) expect_allowed(*guest_permissions)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_allowed(*developer_permissions) expect_allowed(*developer_permissions)
...@@ -224,6 +238,7 @@ describe GroupPolicy do ...@@ -224,6 +238,7 @@ describe GroupPolicy do
let(:current_user) { maintainer } let(:current_user) { maintainer }
it do it do
expect_allowed(*read_group_permissions)
expect_allowed(*guest_permissions) expect_allowed(*guest_permissions)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_allowed(*developer_permissions) expect_allowed(*developer_permissions)
...@@ -236,6 +251,7 @@ describe GroupPolicy do ...@@ -236,6 +251,7 @@ describe GroupPolicy do
let(:current_user) { owner } let(:current_user) { owner }
it do it do
expect_allowed(*read_group_permissions)
expect_allowed(*guest_permissions) expect_allowed(*guest_permissions)
expect_allowed(*reporter_permissions) expect_allowed(*reporter_permissions)
expect_allowed(*developer_permissions) expect_allowed(*developer_permissions)
......
...@@ -16,6 +16,7 @@ RSpec.shared_context 'GroupPolicy context' do ...@@ -16,6 +16,7 @@ RSpec.shared_context 'GroupPolicy context' do
read_group_merge_requests read_group_merge_requests
] ]
end end
let(:read_group_permissions) { %i[read_label read_list read_milestone] }
let(:reporter_permissions) { %i[admin_label read_container_image] } let(:reporter_permissions) { %i[admin_label read_container_image] }
let(:developer_permissions) { [:admin_milestone] } let(:developer_permissions) { [:admin_milestone] }
let(:maintainer_permissions) do let(:maintainer_permissions) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment