Commit 2ac9a385 authored by James Lopez's avatar James Lopez

Merge branch 'fix/project-import-visibility-error' into 'master'

Fix project import error occurring due to default visibility

See merge request gitlab-org/gitlab!53827
parents 126e0158 0c66f683
......@@ -19,6 +19,8 @@ module Projects
@project = Project.new(params)
@project.visibility_level = @project.group.visibility_level unless @project.visibility_level_allowed_by_group?
# If a project is newly created it should have shared runners settings
# based on its group having it enabled. This is like the "default value"
@project.shared_runners_enabled = false if !params.key?(:shared_runners_enabled) && @project.group && @project.group.shared_runners_setting != 'enabled'
......
---
title: Fix project import error occurring due to default visibility
merge_request: 53827
author: Jonas Wälter @wwwjon
type: fixed
......@@ -349,27 +349,38 @@ RSpec.describe Projects::CreateService, '#execute' do
context 'default visibility level' do
let(:group) { create(:group, :private) }
before do
stub_application_setting(default_project_visibility: Gitlab::VisibilityLevel::INTERNAL)
group.add_developer(user)
using RSpec::Parameterized::TableSyntax
opts.merge!(
visibility: 'private',
name: 'test',
namespace: group,
path: 'foo'
)
where(:case_name, :group_level, :project_level) do
[
['in public group', Gitlab::VisibilityLevel::PUBLIC, Gitlab::VisibilityLevel::INTERNAL],
['in internal group', Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::INTERNAL],
['in private group', Gitlab::VisibilityLevel::PRIVATE, Gitlab::VisibilityLevel::PRIVATE]
]
end
it 'creates a private project' do
project = create_project(user, opts)
with_them do
before do
stub_application_setting(default_project_visibility: Gitlab::VisibilityLevel::INTERNAL)
group.add_developer(user)
group.update!(visibility_level: group_level)
expect(project).to respond_to(:errors)
opts.merge!(
name: 'test',
namespace: group,
path: 'foo'
)
end
expect(project.errors.any?).to be(false)
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
expect(project.saved?).to be(true)
expect(project.valid?).to be(true)
it 'creates project with correct visibility level', :aggregate_failures do
project = create_project(user, opts)
expect(project).to respond_to(:errors)
expect(project.errors).to be_blank
expect(project.visibility_level).to eq(project_level)
expect(project).to be_saved
expect(project).to be_valid
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