2013-11-06 10:13:21 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
describe Projects::UpdateService do
|
2017-09-29 04:04:50 -04:00
|
|
|
include ProjectForksHelper
|
|
|
|
|
2017-01-15 01:58:05 -05:00
|
|
|
let(:user) { create(:user) }
|
2017-07-14 05:21:52 -04:00
|
|
|
let(:project) do
|
2017-08-02 15:55:11 -04:00
|
|
|
create(:project, creator: user, namespace: user.namespace)
|
2017-07-14 05:21:52 -04:00
|
|
|
end
|
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
describe '#execute' do
|
|
|
|
let(:gitlab_shell) { Gitlab::Shell.new }
|
|
|
|
let(:admin) { create(:admin) }
|
2013-11-06 10:13:21 -05:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
context 'when changing visibility level' do
|
2017-01-15 01:58:05 -05:00
|
|
|
context 'when visibility_level is INTERNAL' do
|
|
|
|
it 'updates the project to internal' do
|
|
|
|
result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::INTERNAL)
|
2017-11-17 11:24:40 -05:00
|
|
|
|
2017-01-15 01:58:05 -05:00
|
|
|
expect(result).to eq({ status: :success })
|
|
|
|
expect(project).to be_internal
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-15 01:58:05 -05:00
|
|
|
context 'when visibility_level is PUBLIC' do
|
2017-11-17 11:24:40 -05:00
|
|
|
it 'updates the project to public' do
|
2017-01-15 01:58:05 -05:00
|
|
|
result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(result).to eq({ status: :success })
|
|
|
|
expect(project).to be_public
|
|
|
|
end
|
|
|
|
end
|
2013-11-06 10:13:21 -05:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
context 'when visibility levels are restricted to PUBLIC only' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
context 'when visibility_level is INTERNAL' do
|
|
|
|
it 'updates the project to internal' do
|
|
|
|
result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::INTERNAL)
|
2017-01-15 01:58:05 -05:00
|
|
|
expect(result).to eq({ status: :success })
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(project).to be_internal
|
2017-01-15 01:58:05 -05:00
|
|
|
end
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
2017-09-12 17:07:11 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
context 'when visibility_level is PUBLIC' do
|
|
|
|
it 'does not update the project to public' do
|
|
|
|
result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
2017-09-12 17:07:11 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(result).to eq({ status: :error, message: 'New visibility level not allowed!' })
|
|
|
|
expect(project).to be_private
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when updated by an admin' do
|
|
|
|
it 'updates the project to public' do
|
|
|
|
result = update_project(project, admin, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
expect(result).to eq({ status: :success })
|
|
|
|
expect(project).to be_public
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-09-12 17:07:11 -04:00
|
|
|
end
|
|
|
|
|
2017-12-19 11:53:59 -05:00
|
|
|
context 'when project visibility is higher than parent group' do
|
2017-11-17 11:24:40 -05:00
|
|
|
let(:group) { create(:group, visibility_level: Gitlab::VisibilityLevel::INTERNAL) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.update(namespace: group, visibility_level: group.visibility_level)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update project visibility level' do
|
|
|
|
result = update_project(project, admin, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
2017-09-12 17:07:11 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(result).to eq({ status: :error, message: 'Visibility level public is not allowed in a internal group.' })
|
|
|
|
expect(project.reload).to be_internal
|
|
|
|
end
|
2017-09-12 17:07:11 -04:00
|
|
|
end
|
|
|
|
end
|
2013-11-06 10:13:21 -05:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
describe 'when updating project that has forks' do
|
|
|
|
let(:project) { create(:project, :internal) }
|
|
|
|
let(:forked_project) { fork_project(project) }
|
2015-12-24 04:33:26 -05:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
it 'updates forks visibility level when parent set to more restrictive' do
|
|
|
|
opts = { visibility_level: Gitlab::VisibilityLevel::PRIVATE }
|
2017-01-15 01:58:05 -05:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(project).to be_internal
|
|
|
|
expect(forked_project).to be_internal
|
2015-12-24 04:33:26 -05:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(update_project(project, admin, opts)).to eq({ status: :success })
|
2017-01-15 01:58:05 -05:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(project).to be_private
|
|
|
|
expect(forked_project.reload).to be_private
|
|
|
|
end
|
2015-12-24 04:33:26 -05:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
it 'does not update forks visibility level when parent set to less restrictive' do
|
|
|
|
opts = { visibility_level: Gitlab::VisibilityLevel::PUBLIC }
|
2017-01-15 01:58:05 -05:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(project).to be_internal
|
|
|
|
expect(forked_project).to be_internal
|
2015-12-24 04:33:26 -05:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(update_project(project, admin, opts)).to eq({ status: :success })
|
2017-01-15 01:58:05 -05:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(project).to be_public
|
|
|
|
expect(forked_project.reload).to be_internal
|
|
|
|
end
|
2015-12-24 04:33:26 -05:00
|
|
|
end
|
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
context 'when updating a default branch' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
2017-07-14 05:21:52 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
it 'changes a default branch' do
|
|
|
|
update_project(project, admin, default_branch: 'feature')
|
2017-07-14 05:21:52 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(Project.find(project.id).default_branch).to eq 'feature'
|
|
|
|
end
|
2017-08-07 21:10:55 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
it 'does not change a default branch' do
|
|
|
|
# The branch 'unexisted-branch' does not exist.
|
|
|
|
update_project(project, admin, default_branch: 'unexisted-branch')
|
2017-08-07 21:10:55 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(Project.find(project.id).default_branch).to eq 'master'
|
|
|
|
end
|
2017-08-07 21:10:55 -04:00
|
|
|
end
|
2017-07-14 05:21:52 -04:00
|
|
|
|
2018-02-28 05:06:51 -05:00
|
|
|
context 'when we update project but not enabling a wiki' do
|
|
|
|
it 'does not try to create an empty wiki' do
|
|
|
|
FileUtils.rm_rf(project.wiki.repository.path)
|
|
|
|
|
|
|
|
result = update_project(project, user, { name: 'test1' })
|
|
|
|
|
|
|
|
expect(result).to eq({ status: :success })
|
|
|
|
expect(project.wiki_repository_exists?).to be false
|
|
|
|
end
|
2018-03-08 10:03:53 -05:00
|
|
|
|
|
|
|
it 'handles empty project feature attributes' do
|
|
|
|
project.project_feature.update(wiki_access_level: ProjectFeature::DISABLED)
|
|
|
|
|
|
|
|
result = update_project(project, user, { name: 'test1' })
|
|
|
|
|
|
|
|
expect(result).to eq({ status: :success })
|
|
|
|
expect(project.wiki_repository_exists?).to be false
|
|
|
|
end
|
2018-02-28 05:06:51 -05:00
|
|
|
end
|
|
|
|
|
2018-02-14 09:10:17 -05:00
|
|
|
context 'when enabling a wiki' do
|
|
|
|
it 'creates a wiki' do
|
|
|
|
project.project_feature.update(wiki_access_level: ProjectFeature::DISABLED)
|
|
|
|
FileUtils.rm_rf(project.wiki.repository.path)
|
|
|
|
|
|
|
|
result = update_project(project, user, project_feature_attributes: { wiki_access_level: ProjectFeature::ENABLED })
|
|
|
|
|
|
|
|
expect(result).to eq({ status: :success })
|
|
|
|
expect(project.wiki_repository_exists?).to be true
|
|
|
|
expect(project.wiki_enabled?).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'logs an error and creates a metric when wiki can not be created' do
|
|
|
|
project.project_feature.update(wiki_access_level: ProjectFeature::DISABLED)
|
|
|
|
|
|
|
|
expect_any_instance_of(ProjectWiki).to receive(:wiki).and_raise(ProjectWiki::CouldNotCreateWikiError)
|
|
|
|
expect_any_instance_of(described_class).to receive(:log_error).with("Could not create wiki for #{project.full_name}")
|
|
|
|
expect(Gitlab::Metrics).to receive(:counter)
|
|
|
|
|
|
|
|
update_project(project, user, project_feature_attributes: { wiki_access_level: ProjectFeature::ENABLED })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
context 'when updating a project that contains container images' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_config(enabled: true)
|
|
|
|
stub_container_registry_tags(repository: /image/, tags: %w[rc1])
|
|
|
|
create(:container_repository, project: project, name: :image)
|
|
|
|
end
|
2017-07-14 05:27:50 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
it 'does not allow to rename the project' do
|
|
|
|
result = update_project(project, admin, path: 'renamed')
|
2017-07-14 05:27:50 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(result).to include(status: :error)
|
|
|
|
expect(result[:message]).to match(/contains container registry tags/)
|
|
|
|
end
|
2017-07-24 06:47:33 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
it 'allows to update other settings' do
|
|
|
|
result = update_project(project, admin, public_builds: true)
|
2017-07-24 06:47:33 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(result[:status]).to eq :success
|
|
|
|
expect(project.reload.public_builds).to be true
|
|
|
|
end
|
2017-07-24 06:47:33 -04:00
|
|
|
end
|
2017-07-14 05:27:50 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
context 'when renaming a project' do
|
|
|
|
let(:repository_storage) { 'default' }
|
2018-03-14 09:42:49 -04:00
|
|
|
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
|
2017-08-22 19:19:35 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
context 'with legacy storage' do
|
2017-12-01 08:58:49 -05:00
|
|
|
let(:project) { create(:project, :legacy_storage, :repository, creator: user, namespace: user.namespace) }
|
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
before do
|
2018-03-14 04:56:22 -04:00
|
|
|
gitlab_shell.create_repository(repository_storage, "#{user.namespace.full_path}/existing")
|
2017-11-17 11:24:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
gitlab_shell.remove_repository(repository_storage_path, "#{user.namespace.full_path}/existing")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow renaming when new path matches existing repository on disk' do
|
|
|
|
result = update_project(project, admin, path: 'existing')
|
2017-08-22 19:19:35 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(result).to include(status: :error)
|
|
|
|
expect(result[:message]).to match('There is already a repository with that name on disk')
|
|
|
|
expect(project).not_to be_valid
|
|
|
|
expect(project.errors.messages).to have_key(:base)
|
|
|
|
expect(project.errors.messages[:base]).to include('There is already a repository with that name on disk')
|
|
|
|
end
|
2017-09-21 17:04:09 -04:00
|
|
|
end
|
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
context 'with hashed storage' do
|
|
|
|
let(:project) { create(:project, :repository, creator: user, namespace: user.namespace) }
|
2017-09-21 17:04:09 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
before do
|
|
|
|
stub_application_setting(hashed_storage_enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not check if new path matches existing repository on disk' do
|
|
|
|
expect(project).not_to receive(:repository_with_same_path_already_exists?)
|
|
|
|
|
|
|
|
result = update_project(project, admin, path: 'existing')
|
|
|
|
|
|
|
|
expect(result).to include(status: :success)
|
|
|
|
end
|
2017-09-21 17:04:09 -04:00
|
|
|
end
|
2017-08-22 19:19:35 -04:00
|
|
|
end
|
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
context 'when passing invalid parameters' do
|
|
|
|
it 'returns an error result when record cannot be updated' do
|
|
|
|
result = update_project(project, admin, { name: 'foo&bar' })
|
2017-08-22 19:19:35 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
expect(result).to eq({
|
|
|
|
status: :error,
|
|
|
|
message: "Name can contain only letters, digits, emojis, '_', '.', dash, space. It must start with letter, digit, emoji or '_'."
|
|
|
|
})
|
2017-09-21 17:04:09 -04:00
|
|
|
end
|
2017-11-17 11:24:40 -05:00
|
|
|
end
|
2018-01-03 03:07:03 -05:00
|
|
|
|
|
|
|
context 'when updating #pages_https_only', :https_pages_enabled do
|
|
|
|
subject(:call_service) do
|
|
|
|
update_project(project, admin, pages_https_only: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the attribute' do
|
|
|
|
expect { call_service }
|
|
|
|
.to change { project.pages_https_only? }
|
|
|
|
.to(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls Projects::UpdatePagesConfigurationService' do
|
|
|
|
expect(Projects::UpdatePagesConfigurationService)
|
|
|
|
.to receive(:new)
|
|
|
|
.with(project)
|
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
call_service
|
|
|
|
end
|
|
|
|
end
|
2017-11-17 11:24:40 -05:00
|
|
|
end
|
2017-09-21 17:04:09 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
describe '#run_auto_devops_pipeline?' do
|
2017-12-04 06:27:21 -05:00
|
|
|
subject { described_class.new(project, user).run_auto_devops_pipeline? }
|
2017-09-21 17:04:09 -04:00
|
|
|
|
2017-12-04 06:27:21 -05:00
|
|
|
context 'when master contains a .gitlab-ci.yml file' do
|
|
|
|
before do
|
|
|
|
allow(project.repository).to receive(:gitlab_ci_yml).and_return("script: ['test']")
|
|
|
|
end
|
2017-09-21 17:04:09 -04:00
|
|
|
|
2017-11-17 11:24:40 -05:00
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
end
|
|
|
|
|
2017-12-04 06:27:21 -05:00
|
|
|
context 'when auto devops is explicitly enabled' do
|
|
|
|
before do
|
|
|
|
project.create_auto_devops!(enabled: true)
|
|
|
|
end
|
2017-11-17 11:24:40 -05:00
|
|
|
|
|
|
|
it { is_expected.to eq(true) }
|
2017-08-22 19:19:35 -04:00
|
|
|
end
|
|
|
|
|
2017-12-04 06:27:21 -05:00
|
|
|
context 'when auto devops is explicitly disabled' do
|
|
|
|
before do
|
|
|
|
project.create_auto_devops!(enabled: false)
|
|
|
|
end
|
2017-01-15 01:58:05 -05:00
|
|
|
|
2017-12-04 06:27:21 -05:00
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when auto devops is set to instance setting' do
|
|
|
|
before do
|
|
|
|
project.create_auto_devops!(enabled: nil)
|
|
|
|
allow(project.auto_devops).to receive(:previous_changes).and_return('enabled' => true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when auto devops is enabled system-wide' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(auto_devops_enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when auto devops is disabled system-wide' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(auto_devops_enabled: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
end
|
2017-07-14 05:21:52 -04:00
|
|
|
end
|
2017-01-15 01:58:05 -05:00
|
|
|
end
|
|
|
|
|
2013-11-06 10:13:21 -05:00
|
|
|
def update_project(project, user, opts)
|
2017-01-15 01:58:05 -05:00
|
|
|
described_class.new(project, user, opts).execute
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
2014-01-16 13:29:18 -05:00
|
|
|
end
|