Commit fc939c83 authored by Douwe Maan's avatar Douwe Maan

Merge branch...

Merge branch '2532-saving-a-mirrored-project-errors-out-if-mirror-user-has-been-deleted' into 'master'

Update mirror user for all projects deleted user is mirror_user for

Closes #2532

See merge request !2013
parents 970f41cf 98f0094f
......@@ -26,6 +26,12 @@ module Users
::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
end
Project.includes(group: :owners).where(mirror_user: user).find_each do |project|
if project.group.present?
project.update(mirror_user: project.group.owners.first)
end
end
MigrateToGhostUserService.new(user).execute unless options[:hard_delete]
# Destroy the namespace after destroying the user since certain methods may depend on the namespace existing
......
---
title: Update mirror_user for project when mirror_user is deleted
merge_request: 2013
author: Athar Hameed
......@@ -159,5 +159,23 @@ describe Users::DestroyService, services: true do
service.execute(user, hard_delete: true)
end
end
context "when the user was the mirror_user for a group project" do
let(:group_owner) { create(:user) }
let(:mirror_user) { create(:user) }
let(:group) { create(:group) }
before do
group.add_owner(group_owner)
group.add_master(mirror_user)
end
it 'updates the mirror_user to one of the group owners' do
project = create(:empty_project, namespace_id: group.id, creator: group_owner, mirror_user: mirror_user)
service.execute(mirror_user)
expect(project.reload.mirror_user).to eq group_owner
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