Commit d9554171 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '344422-cablett-2-namespace-user-policy-refactor' into 'master'

Remove redundant condition from UserNamespace policy

See merge request gitlab-org/gitlab!75864
parents 24829413 a0cc2986
......@@ -4,7 +4,6 @@ module Namespaces
class UserNamespacePolicy < ::NamespacePolicy
rule { anonymous }.prevent_all
condition(:personal_project, scope: :subject) { @subject.kind == 'user' }
condition(:can_create_personal_project, scope: :user) { @user.can_create_project? }
condition(:owner) { @subject.owner == @user }
......@@ -19,7 +18,7 @@ module Namespaces
enable :read_package_settings
end
rule { personal_project & ~can_create_personal_project }.prevent :create_projects
rule { ~can_create_personal_project }.prevent :create_projects
rule { (owner | admin) & can?(:create_projects) }.enable :transfer_projects
end
......
......@@ -74,4 +74,26 @@ RSpec.describe Namespaces::UserNamespacePolicy do
it { is_expected.to be_disallowed(:create_jira_connect_subscription) }
end
end
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
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