Setup visibility level for project when transfering for a group

This commit is contained in:
Felipe Artur 2016-04-13 15:28:10 -03:00
parent f026e53c4d
commit 11f46b459e
3 changed files with 41 additions and 4 deletions

View file

@ -34,9 +34,12 @@ module Projects
raise TransferError.new("Project with same path in target namespace already exists")
end
# Apply new namespace id
project.namespace = new_namespace
project.save!
# Apply new namespace id and visibility level
project.tap do |p|
p.namespace = new_namespace
setup_visibility_level(p, new_namespace)
p.save!
end
# Notifications
project.send_move_instructions(old_path)
@ -56,7 +59,7 @@ module Projects
Gitlab::UploadsTransfer.new.move_project(project.path, old_namespace.path, new_namespace.path)
project.old_path_with_namespace = old_path
SystemHooksService.new.execute_hooks_for(project, :transfer)
true
end
@ -68,5 +71,15 @@ module Projects
namespace.id != project.namespace_id &&
current_user.can?(:create_projects, namespace)
end
private
def setup_visibility_level(project, new_namespace)
return unless new_namespace.is_a?(Group)
if project.visibility_level > new_namespace.visibility_level
project.visibility_level = new_namespace.visibility_level
end
end
end
end

View file

@ -210,6 +210,7 @@
%li Be careful. Changing the project's namespace can have unintended side effects.
%li You can only transfer the project to namespaces you manage.
%li You will need to update your local repositories to point to the new location.
%li Project visibility level will be changed to match namespace rules when transfering to a group.
.form-actions
= f.submit 'Transfer project', class: "btn btn-remove js-confirm-danger", data: { "confirm-danger-message" => transfer_project_message(@project) }
- else

View file

@ -38,4 +38,27 @@ describe Projects::TransferService, services: true do
def transfer_project(project, user, new_namespace)
Projects::TransferService.new(project, user).execute(new_namespace)
end
context 'visibility level' do
let(:internal_group) { create(:group, :internal) }
before { internal_group.add_owner(user) }
context 'when namespace visibility level < project visibility level' do
let(:public_project) { create(:project, :public, namespace: user.namespace) }
before { transfer_project(public_project, user, internal_group) }
it { expect(public_project.visibility_level).to eq(internal_group.visibility_level) }
end
context 'when namespace visibility level > project visibility level' do
let(:private_project) { create(:project, :private, namespace: user.namespace) }
before { transfer_project(private_project, user, internal_group) }
it { expect(private_project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) }
end
end
end