2013-11-06 10:13:21 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Projects::UpdateService, '#execute' do
|
2017-08-22 19:19:35 -04:00
|
|
|
let(:gitlab_shell) { Gitlab::Shell.new }
|
2017-01-15 01:58:05 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:admin) { create(:admin) }
|
2013-11-06 10:13:21 -05:00
|
|
|
|
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
|
|
|
|
|
|
|
|
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)
|
2013-11-06 10:13:21 -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
|
|
|
|
it 'updates the project to public' do
|
|
|
|
result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
expect(result).to eq({ status: :success })
|
|
|
|
expect(project).to be_public
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-15 01:58:05 -05:00
|
|
|
context 'when visibility levels are restricted to PUBLIC only' do
|
2013-11-06 10:13:21 -05:00
|
|
|
before do
|
2015-07-01 17:21:51 -04:00
|
|
|
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
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)
|
|
|
|
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
|
|
|
|
it 'does not update the project to public' do
|
|
|
|
result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
|
2013-11-06 10:13:21 -05:00
|
|
|
|
2017-07-13 09:32:31 -04:00
|
|
|
expect(result).to eq({ status: :error, message: 'New visibility level not allowed!' })
|
2017-01-15 01:58:05 -05:00
|
|
|
expect(project).to be_private
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
2017-01-15 01:58:05 -05:00
|
|
|
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
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-09-12 17:07:11 -04:00
|
|
|
|
|
|
|
context 'When project visibility is higher than parent group' do
|
|
|
|
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)
|
|
|
|
|
|
|
|
expect(result).to eq({ status: :error, message: 'Visibility level public is not allowed in a internal group.' })
|
|
|
|
expect(project.reload).to be_internal
|
|
|
|
end
|
|
|
|
end
|
2013-11-06 10:13:21 -05:00
|
|
|
end
|
|
|
|
|
2017-07-14 05:21:52 -04:00
|
|
|
describe 'when updating project that has forks' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :internal) }
|
2016-03-08 16:40:45 -05:00
|
|
|
let(:forked_project) { create(:forked_project_with_submodules, :internal) }
|
2015-12-24 04:33:26 -05:00
|
|
|
|
|
|
|
before do
|
2017-07-14 05:21:52 -04:00
|
|
|
forked_project.build_forked_project_link(forked_to_project_id: forked_project.id,
|
|
|
|
forked_from_project_id: project.id)
|
2015-12-24 04:33:26 -05:00
|
|
|
forked_project.save
|
|
|
|
end
|
|
|
|
|
2017-01-15 01:58:05 -05:00
|
|
|
it 'updates forks visibility level when parent set to more restrictive' do
|
|
|
|
opts = { visibility_level: Gitlab::VisibilityLevel::PRIVATE }
|
|
|
|
|
|
|
|
expect(project).to be_internal
|
|
|
|
expect(forked_project).to be_internal
|
2015-12-24 04:33:26 -05:00
|
|
|
|
2017-01-15 01:58:05 -05:00
|
|
|
expect(update_project(project, admin, opts)).to eq({ status: :success })
|
|
|
|
|
|
|
|
expect(project).to be_private
|
|
|
|
expect(forked_project.reload).to be_private
|
2015-12-24 04:33:26 -05:00
|
|
|
end
|
|
|
|
|
2017-01-15 01:58:05 -05:00
|
|
|
it 'does not update forks visibility level when parent set to less restrictive' do
|
|
|
|
opts = { visibility_level: Gitlab::VisibilityLevel::PUBLIC }
|
|
|
|
|
|
|
|
expect(project).to be_internal
|
|
|
|
expect(forked_project).to be_internal
|
2015-12-24 04:33:26 -05:00
|
|
|
|
2017-01-15 01:58:05 -05:00
|
|
|
expect(update_project(project, admin, opts)).to eq({ status: :success })
|
|
|
|
|
|
|
|
expect(project).to be_public
|
|
|
|
expect(forked_project.reload).to be_internal
|
2015-12-24 04:33:26 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-14 05:21:52 -04:00
|
|
|
context 'when updating a default branch' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
|
|
|
|
it 'changes a default branch' do
|
|
|
|
update_project(project, admin, default_branch: 'feature')
|
|
|
|
|
|
|
|
expect(Project.find(project.id).default_branch).to eq 'feature'
|
|
|
|
end
|
2017-08-07 21:10:55 -04:00
|
|
|
|
|
|
|
it 'does not change a default branch' do
|
|
|
|
# The branch 'unexisted-branch' does not exist.
|
|
|
|
update_project(project, admin, default_branch: 'unexisted-branch')
|
|
|
|
|
|
|
|
expect(Project.find(project.id).default_branch).to eq 'master'
|
|
|
|
end
|
2017-07-14 05:21:52 -04:00
|
|
|
end
|
|
|
|
|
2017-07-24 06:47:33 -04:00
|
|
|
context 'when updating a project that contains container images' do
|
2017-07-14 05:27:50 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
it 'does not allow to rename the project' do
|
|
|
|
result = update_project(project, admin, path: 'renamed')
|
|
|
|
|
|
|
|
expect(result).to include(status: :error)
|
|
|
|
expect(result[:message]).to match(/contains container registry tags/)
|
|
|
|
end
|
2017-07-24 06:47:33 -04:00
|
|
|
|
|
|
|
it 'allows to update other settings' do
|
|
|
|
result = update_project(project, admin, public_builds: true)
|
|
|
|
|
|
|
|
expect(result[:status]).to eq :success
|
|
|
|
expect(project.reload.public_builds).to be true
|
|
|
|
end
|
2017-07-14 05:27:50 -04:00
|
|
|
end
|
|
|
|
|
2017-08-22 19:19:35 -04:00
|
|
|
context 'when renaming a project' do
|
|
|
|
let(:repository_storage_path) { Gitlab.config.repositories.storages['default']['path'] }
|
|
|
|
|
|
|
|
before do
|
|
|
|
gitlab_shell.add_repository(repository_storage_path, "#{user.namespace.full_path}/existing")
|
|
|
|
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')
|
|
|
|
|
|
|
|
expect(result).to include(status: :error)
|
2017-09-15 10:55:57 -04:00
|
|
|
expect(result[:message]).to match('There is already a repository with that name on disk')
|
2017-08-22 19:19:35 -04:00
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2017-07-14 05:21:52 -04: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-01-15 01:58:05 -05:00
|
|
|
|
2017-09-12 17:07:11 -04: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-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
|