Commit 0c66f683 authored by Jonas Wälter's avatar Jonas Wälter Committed by James Lopez

Fix project import error occurring due to default visibility

parent 91817c59
...@@ -19,6 +19,8 @@ module Projects ...@@ -19,6 +19,8 @@ module Projects
@project = Project.new(params) @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 # 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" # 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' @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 ...@@ -349,27 +349,38 @@ RSpec.describe Projects::CreateService, '#execute' do
context 'default visibility level' do context 'default visibility level' do
let(:group) { create(:group, :private) } let(:group) { create(:group, :private) }
before do using RSpec::Parameterized::TableSyntax
stub_application_setting(default_project_visibility: Gitlab::VisibilityLevel::INTERNAL)
group.add_developer(user)
opts.merge!( where(:case_name, :group_level, :project_level) do
visibility: 'private', [
name: 'test', ['in public group', Gitlab::VisibilityLevel::PUBLIC, Gitlab::VisibilityLevel::INTERNAL],
namespace: group, ['in internal group', Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::INTERNAL],
path: 'foo' ['in private group', Gitlab::VisibilityLevel::PRIVATE, Gitlab::VisibilityLevel::PRIVATE]
) ]
end end
it 'creates a private project' do with_them do
project = create_project(user, opts) 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) it 'creates project with correct visibility level', :aggregate_failures do
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) project = create_project(user, opts)
expect(project.saved?).to be(true)
expect(project.valid?).to be(true) 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
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