BigW Consortium Gitlab

Commit 11f46b45 by Felipe Artur

Setup visibility level for project when transfering for a group

parent f026e53c
...@@ -34,9 +34,12 @@ module Projects ...@@ -34,9 +34,12 @@ module Projects
raise TransferError.new("Project with same path in target namespace already exists") raise TransferError.new("Project with same path in target namespace already exists")
end end
# Apply new namespace id # Apply new namespace id and visibility level
project.namespace = new_namespace project.tap do |p|
project.save! p.namespace = new_namespace
setup_visibility_level(p, new_namespace)
p.save!
end
# Notifications # Notifications
project.send_move_instructions(old_path) project.send_move_instructions(old_path)
...@@ -68,5 +71,15 @@ module Projects ...@@ -68,5 +71,15 @@ module Projects
namespace.id != project.namespace_id && namespace.id != project.namespace_id &&
current_user.can?(:create_projects, namespace) current_user.can?(:create_projects, namespace)
end 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
end end
...@@ -210,6 +210,7 @@ ...@@ -210,6 +210,7 @@
%li Be careful. Changing the project's namespace can have unintended side effects. %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 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 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 .form-actions
= f.submit 'Transfer project', class: "btn btn-remove js-confirm-danger", data: { "confirm-danger-message" => transfer_project_message(@project) } = f.submit 'Transfer project', class: "btn btn-remove js-confirm-danger", data: { "confirm-danger-message" => transfer_project_message(@project) }
- else - else
......
...@@ -38,4 +38,27 @@ describe Projects::TransferService, services: true do ...@@ -38,4 +38,27 @@ describe Projects::TransferService, services: true do
def transfer_project(project, user, new_namespace) def transfer_project(project, user, new_namespace)
Projects::TransferService.new(project, user).execute(new_namespace) Projects::TransferService.new(project, user).execute(new_namespace)
end 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 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