Commit a0cc2986 authored by charlie ablett's avatar charlie ablett

Remove redundant condition from UserNamespace policy

parent de796cf9
...@@ -8,4 +8,3 @@ class NamespacePolicy < BasePolicy ...@@ -8,4 +8,3 @@ class NamespacePolicy < BasePolicy
# here. # here.
# See https://gitlab.com/groups/gitlab-org/-/epics/6689 for details # See https://gitlab.com/groups/gitlab-org/-/epics/6689 for details
end end
...@@ -4,7 +4,6 @@ module Namespaces ...@@ -4,7 +4,6 @@ module Namespaces
class UserNamespacePolicy < ::NamespacePolicy class UserNamespacePolicy < ::NamespacePolicy
rule { anonymous }.prevent_all rule { anonymous }.prevent_all
condition(:personal_project, scope: :subject) { @subject.kind == 'user' }
condition(:can_create_personal_project, scope: :user) { @user.can_create_project? } condition(:can_create_personal_project, scope: :user) { @user.can_create_project? }
condition(:owner) { @subject.owner == @user } condition(:owner) { @subject.owner == @user }
...@@ -19,7 +18,7 @@ module Namespaces ...@@ -19,7 +18,7 @@ module Namespaces
enable :read_package_settings enable :read_package_settings
end 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 rule { (owner | admin) & can?(:create_projects) }.enable :transfer_projects
end end
......
...@@ -74,4 +74,26 @@ RSpec.describe Namespaces::UserNamespacePolicy do ...@@ -74,4 +74,26 @@ RSpec.describe Namespaces::UserNamespacePolicy do
it { is_expected.to be_disallowed(:create_jira_connect_subscription) } it { is_expected.to be_disallowed(:create_jira_connect_subscription) }
end end
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 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