2021-09-23 05:09:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-12-07 10:15:03 -05:00
|
|
|
RSpec.describe Namespaces::ProjectNamespacePolicy do
|
2021-09-23 05:09:51 -04:00
|
|
|
let_it_be(:parent) { create(:namespace) }
|
2021-11-10 13:12:35 -05:00
|
|
|
let_it_be(:project) { create(:project, namespace: parent) }
|
|
|
|
let_it_be(:namespace) { project.project_namespace }
|
2021-09-23 05:09:51 -04:00
|
|
|
|
|
|
|
let(:permissions) do
|
|
|
|
[:owner_access, :create_projects, :admin_namespace, :read_namespace,
|
2022-05-11 08:09:03 -04:00
|
|
|
:read_statistics, :transfer_projects, :admin_package,
|
|
|
|
:create_jira_connect_subscription]
|
2021-09-23 05:09:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(current_user, namespace) }
|
|
|
|
|
|
|
|
context 'with no user' do
|
|
|
|
let_it_be(:current_user) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*permissions) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'regular user' do
|
|
|
|
let_it_be(:current_user) { create(:user) }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*permissions) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'parent owner' do
|
2022-01-25 13:11:55 -05:00
|
|
|
let_it_be(:current_user) { parent.first_owner }
|
2021-09-23 05:09:51 -04:00
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*permissions) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'admin' do
|
|
|
|
let_it_be(:current_user) { create(:admin) }
|
|
|
|
|
|
|
|
context 'when admin mode is enabled', :enable_admin_mode do
|
2021-12-07 10:15:03 -05:00
|
|
|
it { is_expected.to be_disallowed(*permissions) }
|
2021-09-23 05:09:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin mode is disabled' do
|
|
|
|
it { is_expected.to be_disallowed(*permissions) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|