Commit d4da0f84 authored by charlie ablett's avatar charlie ablett

Merge branch...

Merge branch '354335-project-transfers-to-personal-namespace-does-not-create-membership-for-the-owner' into 'master'

Resolve "Project transfers to personal namespace does not create membership for the owner"

See merge request gitlab-org/gitlab!83175
parents 91dffb00 0e56b243
......@@ -121,6 +121,7 @@ module Projects
# Overridden in EE
def post_update_hooks(project)
move_pages(project)
ensure_personal_project_owner_membership(project)
end
# Overridden in EE
......@@ -152,6 +153,19 @@ module Projects
project.track_project_repository
end
def ensure_personal_project_owner_membership(project)
# In case of personal projects, we want to make sure that
# a membership record with `OWNER` access level exists for the owner of the namespace.
return unless project.personal?
namespace_owner = project.namespace.owner
existing_membership_record = project.member(namespace_owner)
return if existing_membership_record.present? && existing_membership_record.access_level == Gitlab::Access::OWNER
project.add_owner(namespace_owner)
end
def refresh_permissions
# This ensures we only schedule 1 job for every user that has access to
# the namespaces.
......
......@@ -11,8 +11,9 @@ RSpec.describe Projects::TransferService do
let(:project) { create(:project, :repository, :legacy_storage, namespace: user.namespace) }
let(:target) { group }
let(:executor) { user }
subject(:execute_transfer) { described_class.new(project, user).execute(target).tap { project.reload } }
subject(:execute_transfer) { described_class.new(project, executor).execute(target).tap { project.reload } }
context 'with npm packages' do
before do
......@@ -92,6 +93,55 @@ RSpec.describe Projects::TransferService do
end
end
context 'project in a group -> a personal namespace', :enable_admin_mode do
let(:project) { create(:project, :repository, :legacy_storage, group: group) }
let(:target) { user.namespace }
# We need to use an admin user as the executor because
# only an admin user has required permissions to transfer projects
# under _all_ the different circumstances specified below.
let(:executor) { create(:user, :admin) }
it 'executes the transfer to personal namespace successfully' do
execute_transfer
expect(project.namespace).to eq(user.namespace)
end
context 'the owner of the namespace does not have a direct membership in the project residing in the group' do
it 'creates a project membership record for the owner of the namespace, with OWNER access level, after the transfer' do
execute_transfer
expect(project.members.owners.find_by(user_id: user.id)).to be_present
end
end
context 'the owner of the namespace has a direct membership in the project residing in the group' do
context 'that membership has an access level of OWNER' do
before do
project.add_owner(user)
end
it 'retains the project membership record for the owner of the namespace, with OWNER access level, after the transfer' do
execute_transfer
expect(project.members.owners.find_by(user_id: user.id)).to be_present
end
end
context 'that membership has an access level that is not OWNER' do
before do
project.add_developer(user)
end
it 'updates the project membership record for the owner of the namespace, to OWNER access level, after the transfer' do
execute_transfer
expect(project.members.owners.find_by(user_id: user.id)).to be_present
end
end
end
end
context 'when transfer succeeds' do
before do
group.add_owner(user)
......
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