Commit eec781df authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'fj-26380-admin-manages-personal-snippets' into 'master'

Allow admins to administer personal snippets

See merge request gitlab-org/gitlab!19693
parents 3646d607 dec8699f
...@@ -10,7 +10,7 @@ class PersonalSnippetPolicy < BasePolicy ...@@ -10,7 +10,7 @@ class PersonalSnippetPolicy < BasePolicy
enable :create_note enable :create_note
end end
rule { is_author }.policy do rule { is_author | admin }.policy do
enable :read_personal_snippet enable :read_personal_snippet
enable :update_personal_snippet enable :update_personal_snippet
enable :destroy_personal_snippet enable :destroy_personal_snippet
......
---
title: Allow admins to administer personal snippets
merge_request: 19693
author: Oren Kanner
type: fixed
...@@ -20,6 +20,19 @@ describe PersonalSnippetPolicy do ...@@ -20,6 +20,19 @@ describe PersonalSnippetPolicy do
described_class.new(user, snippet) described_class.new(user, snippet)
end end
shared_examples 'admin access' do
context 'admin user' do
subject { permissions(admin_user) }
it do
is_expected.to be_allowed(:read_personal_snippet)
is_expected.to be_allowed(:create_note)
is_expected.to be_allowed(:award_emoji)
is_expected.to be_allowed(*author_permissions)
end
end
end
context 'public snippet' do context 'public snippet' do
let(:snippet) { create(:personal_snippet, :public) } let(:snippet) { create(:personal_snippet, :public) }
...@@ -55,6 +68,8 @@ describe PersonalSnippetPolicy do ...@@ -55,6 +68,8 @@ describe PersonalSnippetPolicy do
is_expected.to be_allowed(*author_permissions) is_expected.to be_allowed(*author_permissions)
end end
end end
it_behaves_like 'admin access'
end end
context 'internal snippet' do context 'internal snippet' do
...@@ -103,6 +118,8 @@ describe PersonalSnippetPolicy do ...@@ -103,6 +118,8 @@ describe PersonalSnippetPolicy do
is_expected.to be_allowed(*author_permissions) is_expected.to be_allowed(*author_permissions)
end end
end end
it_behaves_like 'admin access'
end end
context 'private snippet' do context 'private snippet' do
...@@ -130,17 +147,6 @@ describe PersonalSnippetPolicy do ...@@ -130,17 +147,6 @@ describe PersonalSnippetPolicy do
end end
end end
context 'admin user' do
subject { permissions(admin_user) }
it do
is_expected.to be_allowed(:read_personal_snippet)
is_expected.to be_disallowed(:create_note)
is_expected.to be_disallowed(:award_emoji)
is_expected.to be_disallowed(*author_permissions)
end
end
context 'external user' do context 'external user' do
subject { permissions(external_user) } subject { permissions(external_user) }
...@@ -162,5 +168,7 @@ describe PersonalSnippetPolicy do ...@@ -162,5 +168,7 @@ describe PersonalSnippetPolicy do
is_expected.to be_allowed(*author_permissions) is_expected.to be_allowed(*author_permissions)
end end
end end
it_behaves_like 'admin access'
end end
end end
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