Commit dec8699f authored by Francisco Javier López's avatar Francisco Javier López Committed by Heinrich Lee Yu

Allow admins to administer personal snippets

In this commit we allow admins to administer any personal
snippet regardless the visibility.
parent 3646d607
...@@ -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