Commit ada81c36 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'vij-move-change-repo-policy' into 'master'

Move change_repository_storage policy to BasePolicy

See merge request gitlab-org/gitlab!46164
parents 3803fff4 4b90cccb
......@@ -57,6 +57,8 @@ class BasePolicy < DeclarativePolicy::Base
rule { default }.enable :read_cross_project
condition(:is_gitlab_com) { ::Gitlab.dev_env_or_com? }
rule { admin }.enable :change_repository_storage
end
BasePolicy.prepend_if_ee('EE::BasePolicy')
......@@ -546,8 +546,6 @@ class ProjectPolicy < BasePolicy
prevent :create_pipeline
end
rule { admin }.enable :change_repository_storage
rule { can?(:read_issue) }.policy do
enable :read_design
enable :read_design_activity
......
......@@ -22,70 +22,62 @@ RSpec.describe BasePolicy do
end
end
describe 'read cross project' do
shared_examples 'admin only access' do |policy|
let(:current_user) { build_stubbed(:user) }
let(:user) { build_stubbed(:user) }
subject { described_class.new(current_user, [user]) }
it { is_expected.to be_allowed(:read_cross_project) }
context 'for anonymous' do
let(:current_user) { nil }
it { is_expected.to be_allowed(:read_cross_project) }
end
context 'when an external authorization service is enabled' do
before do
enable_external_authorization_service_check
end
subject { described_class.new(current_user, nil) }
it { is_expected.not_to be_allowed(:read_cross_project) }
it { is_expected.not_to be_allowed(policy) }
context 'for admins' do
let(:current_user) { build_stubbed(:admin) }
subject { described_class.new(current_user, nil) }
it 'allowed when in admin mode' do
enable_admin_mode!(current_user)
is_expected.to be_allowed(:read_cross_project)
is_expected.to be_allowed(policy)
end
it 'prevented when not in admin mode' do
is_expected.not_to be_allowed(:read_cross_project)
is_expected.not_to be_allowed(policy)
end
end
context 'for anonymous' do
let(:current_user) { nil }
it { is_expected.not_to be_allowed(:read_cross_project) }
end
it { is_expected.not_to be_allowed(policy) }
end
end
describe 'full private access' do
describe 'read cross project' do
let(:current_user) { build_stubbed(:user) }
let(:user) { build_stubbed(:user) }
subject { described_class.new(current_user, nil) }
subject { described_class.new(current_user, [user]) }
it { is_expected.not_to be_allowed(:read_all_resources) }
it { is_expected.to be_allowed(:read_cross_project) }
context 'for admins' do
let(:current_user) { build_stubbed(:admin) }
context 'for anonymous' do
let(:current_user) { nil }
it 'allowed when in admin mode' do
enable_admin_mode!(current_user)
it { is_expected.to be_allowed(:read_cross_project) }
end
is_expected.to be_allowed(:read_all_resources)
context 'when an external authorization service is enabled' do
before do
enable_external_authorization_service_check
end
it 'prevented when not in admin mode' do
is_expected.not_to be_allowed(:read_all_resources)
it_behaves_like 'admin only access', :read_cross_project
end
end
describe 'full private access' do
it_behaves_like 'admin only access', :read_all_resources
end
describe 'change_repository_storage' do
it_behaves_like 'admin only access', :change_repository_storage
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