2019-10-24 20:06:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-29 07:14:39 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-09-23 18:34:10 -04:00
|
|
|
RSpec.describe Namespaces::UserNamespacePolicy do
|
2021-12-03 10:10:36 -05:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:owner) { create(:user) }
|
|
|
|
let_it_be(:admin) { create(:admin) }
|
|
|
|
let_it_be(:namespace) { create(:user_namespace, owner: owner) }
|
2017-11-27 15:26:50 -05:00
|
|
|
|
2022-05-11 08:09:03 -04:00
|
|
|
let(:owner_permissions) { [:owner_access, :create_projects, :admin_namespace, :read_namespace, :read_statistics, :transfer_projects, :admin_package] }
|
2017-09-29 07:14:39 -04:00
|
|
|
|
|
|
|
subject { described_class.new(current_user, namespace) }
|
|
|
|
|
2017-11-27 15:26:50 -05:00
|
|
|
context 'with no user' do
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to be_banned }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'regular user' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(*owner_permissions) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'owner' do
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(*owner_permissions) }
|
2017-09-29 07:14:39 -04:00
|
|
|
|
2017-11-27 15:26:50 -05:00
|
|
|
context 'user who has exceeded project limit' do
|
|
|
|
let(:owner) { create(:user, projects_limit: 0) }
|
2017-09-29 07:14:39 -04:00
|
|
|
|
2019-03-26 04:22:46 -04:00
|
|
|
it { is_expected.to be_disallowed(:create_projects) }
|
2019-09-23 03:42:26 -04:00
|
|
|
it { is_expected.to be_disallowed(:transfer_projects) }
|
2017-09-29 07:14:39 -04:00
|
|
|
end
|
|
|
|
end
|
2017-11-27 15:26:50 -05:00
|
|
|
|
|
|
|
context 'admin' do
|
|
|
|
let(:current_user) { admin }
|
|
|
|
|
2020-05-15 11:08:04 -04:00
|
|
|
context 'when admin mode is enabled', :enable_admin_mode do
|
|
|
|
it { is_expected.to be_allowed(*owner_permissions) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin mode is disabled' do
|
|
|
|
it { is_expected.to be_disallowed(*owner_permissions) }
|
|
|
|
end
|
2017-11-27 15:26:50 -05:00
|
|
|
end
|
2020-09-01 08:11:01 -04:00
|
|
|
|
|
|
|
describe 'create_jira_connect_subscription' do
|
|
|
|
context 'admin' do
|
|
|
|
let(:current_user) { build_stubbed(:admin) }
|
|
|
|
|
|
|
|
context 'when admin mode enabled', :enable_admin_mode do
|
|
|
|
it { is_expected.to be_allowed(:create_jira_connect_subscription) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin mode disabled' do
|
|
|
|
it { is_expected.to be_disallowed(:create_jira_connect_subscription) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'owner' do
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:create_jira_connect_subscription) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'other user' do
|
|
|
|
let(:current_user) { build_stubbed(:user) }
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:create_jira_connect_subscription) }
|
|
|
|
end
|
|
|
|
end
|
2021-12-10 10:10:24 -05:00
|
|
|
|
|
|
|
describe 'create projects' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let(:current_user) { owner }
|
|
|
|
|
|
|
|
context 'when user can create projects' do
|
|
|
|
before do
|
|
|
|
allow(current_user).to receive(:can_create_project?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:create_projects) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user cannot create projects' do
|
|
|
|
before do
|
|
|
|
allow(current_user).to receive(:can_create_project?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:create_projects) }
|
|
|
|
end
|
|
|
|
end
|
2017-09-29 07:14:39 -04:00
|
|
|
end
|