Commit 6ed730f1 authored by Francisco Javier López's avatar Francisco Javier López Committed by Peter Leitzen

Fix bug with internal project snippets and project maintainer

parent 1c9ba0c5
......@@ -31,7 +31,7 @@ class ProjectSnippetPolicy < BasePolicy
~can?(:read_all_resources))
end.prevent :read_snippet
rule { internal_snippet & ~is_author & ~admin }.policy do
rule { internal_snippet & ~is_author & ~admin & ~project.maintainer }.policy do
prevent :update_snippet
prevent :admin_snippet
end
......@@ -42,7 +42,7 @@ class ProjectSnippetPolicy < BasePolicy
prevent :admin_snippet
end
rule { is_author | admin }.policy do
rule { is_author | admin | project.maintainer }.policy do
enable :read_snippet
enable :update_snippet
enable :admin_snippet
......
---
title: Fix bug deleting internal project snippets by project maintainer
merge_request: 25792
author:
type: fixed
......@@ -20,6 +20,7 @@ describe ProjectSnippetPolicy do
subject { described_class.new(current_user, snippet) }
shared_examples 'regular user access rights' do
context 'not snippet author' do
context 'project team member (non guest)' do
before do
project.add_developer(current_user)
......@@ -36,12 +37,22 @@ describe ProjectSnippetPolicy do
project.add_guest(current_user)
end
context 'not snippet author' do
it do
expect_allowed(:read_snippet, :create_note)
expect_disallowed(:admin_snippet)
end
end
context 'project team member (maintainer)' do
before do
project.add_maintainer(current_user)
end
it do
expect_allowed(:read_snippet, :create_note)
expect_allowed(*author_permissions)
end
end
end
context 'snippet author' do
......@@ -69,6 +80,17 @@ describe ProjectSnippetPolicy do
end
end
context 'project team member (maintainer)' do
before do
project.add_maintainer(current_user)
end
it do
expect_allowed(:read_snippet, :create_note)
expect_allowed(*author_permissions)
end
end
context 'not a project member' do
it do
expect_allowed(:read_snippet, :create_note)
......
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