Commit 29fe9d5d authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch...

Merge branch '224674-fix-update_routes_for_lost_and_found_group_and_orphaned_projects-conflict-with-ghost-route' into 'master'

Fix conflict on the migration that adds routes for orphaned projects

See merge request gitlab-org/gitlab!35425
parents 822c4d81 db7d808b
---
title: Fix path conflict for Ghost on UpdateRoutesForLostAndFoundGroupAndOrphanedProjects
merge_request: 35425
author:
type: fixed
...@@ -136,6 +136,7 @@ class UpdateRoutesForLostAndFoundGroupAndOrphanedProjects < ActiveRecord::Migrat ...@@ -136,6 +136,7 @@ class UpdateRoutesForLostAndFoundGroupAndOrphanedProjects < ActiveRecord::Migrat
# to ensure the Active Record's knowledge of the table structure is current # to ensure the Active Record's knowledge of the table structure is current
Namespace.reset_column_information Namespace.reset_column_information
Route.reset_column_information Route.reset_column_information
User.reset_column_information
# Find the ghost user, its namespace and the "lost and found" group # Find the ghost user, its namespace and the "lost and found" group
ghost_user = User.ghost ghost_user = User.ghost
...@@ -158,6 +159,15 @@ class UpdateRoutesForLostAndFoundGroupAndOrphanedProjects < ActiveRecord::Migrat ...@@ -158,6 +159,15 @@ class UpdateRoutesForLostAndFoundGroupAndOrphanedProjects < ActiveRecord::Migrat
'More info: gitlab.com/gitlab-org/gitlab/-/issues/198603' 'More info: gitlab.com/gitlab-org/gitlab/-/issues/198603'
lost_and_found_group.save! lost_and_found_group.save!
# make sure that the ghost namespace has a unique path
ghost_namespace.generate_unique_path
if ghost_namespace.path_changed?
ghost_namespace.save!
# If the path changed, also update the Ghost User's username to match the new path.
ghost_user.update!(username: ghost_namespace.path)
end
# Update the routes for the Ghost user, the "lost and found" group # Update the routes for the Ghost user, the "lost and found" group
# and all the orphaned projects # and all the orphaned projects
ghost_namespace.ensure_route! ghost_namespace.ensure_route!
......
...@@ -62,8 +62,8 @@ RSpec.describe UpdateRoutesForLostAndFoundGroupAndOrphanedProjects, :migration d ...@@ -62,8 +62,8 @@ RSpec.describe UpdateRoutesForLostAndFoundGroupAndOrphanedProjects, :migration d
source_type: 'Project', source_type: 'Project',
path: 'orphaned_project', path: 'orphaned_project',
name: 'orphaned_project', name: 'orphaned_project',
created_at: Time.zone.now, created_at: Time.current,
updated_at: Time.zone.now updated_at: Time.current
) )
# Create another user named ghost which is not the Ghost User # Create another user named ghost which is not the Ghost User
...@@ -90,10 +90,10 @@ RSpec.describe UpdateRoutesForLostAndFoundGroupAndOrphanedProjects, :migration d ...@@ -90,10 +90,10 @@ RSpec.describe UpdateRoutesForLostAndFoundGroupAndOrphanedProjects, :migration d
routes.create!( routes.create!(
source_id: fake_ghost_user_namespace.id, source_id: fake_ghost_user_namespace.id,
source_type: 'Namespace', source_type: 'Namespace',
path: 'Ghost User', path: 'ghost1',
name: 'ghost1', name: 'Ghost User',
created_at: Time.zone.now, created_at: Time.current,
updated_at: Time.zone.now updated_at: Time.current
) )
fake_lost_and_found_group = namespaces.create!( fake_lost_and_found_group = namespaces.create!(
...@@ -109,8 +109,8 @@ RSpec.describe UpdateRoutesForLostAndFoundGroupAndOrphanedProjects, :migration d ...@@ -109,8 +109,8 @@ RSpec.describe UpdateRoutesForLostAndFoundGroupAndOrphanedProjects, :migration d
source_type: 'Namespace', source_type: 'Namespace',
path: described_class::User::LOST_AND_FOUND_GROUP, # same path as the lost-and-found group path: described_class::User::LOST_AND_FOUND_GROUP, # same path as the lost-and-found group
name: 'Lost and Found', name: 'Lost and Found',
created_at: Time.zone.now, created_at: Time.current,
updated_at: Time.zone.now updated_at: Time.current
) )
members.create!( members.create!(
...@@ -135,17 +135,58 @@ RSpec.describe UpdateRoutesForLostAndFoundGroupAndOrphanedProjects, :migration d ...@@ -135,17 +135,58 @@ RSpec.describe UpdateRoutesForLostAndFoundGroupAndOrphanedProjects, :migration d
source_type: 'Project', source_type: 'Project',
path: "#{described_class::User::LOST_AND_FOUND_GROUP}/normal_project", path: "#{described_class::User::LOST_AND_FOUND_GROUP}/normal_project",
name: 'Lost and Found / normal_project', name: 'Lost and Found / normal_project',
created_at: Time.zone.now, created_at: Time.current,
updated_at: Time.zone.now updated_at: Time.current
) )
# Add a project whose route conflicts with the ghost username
# and should force the data migration to pick a new Ghost username and path
ghost_project = projects.create!(
name: 'Ghost Project',
path: 'ghost',
visibility_level: 20,
archived: false,
namespace_id: fake_lost_and_found_group.id
)
routes.create!(
source_id: ghost_project.id,
source_type: 'Project',
path: 'ghost',
name: 'Ghost Project',
created_at: Time.current,
updated_at: Time.current
)
end
it 'fixes the ghost user username and namespace path' do
ghost_user = users.find_by(user_type: described_class::User::USER_TYPE_GHOST)
ghost_namespace = namespaces.find_by(owner_id: ghost_user.id)
expect(ghost_user.username).to eq('ghost')
expect(ghost_namespace.path).to eq('ghost')
disable_migrations_output { migrate! }
ghost_user = users.find_by(user_type: described_class::User::USER_TYPE_GHOST)
ghost_namespace = namespaces.find_by(owner_id: ghost_user.id)
ghost_namespace_route = routes.find_by(source_id: ghost_namespace.id, source_type: 'Namespace')
expect(ghost_user.username).to eq('ghost2')
expect(ghost_namespace.path).to eq('ghost2')
expect(ghost_namespace_route.path).to eq('ghost2')
end end
it 'creates the route for the ghost user namespace' do it 'creates the route for the ghost user namespace' do
expect(routes.where(path: 'ghost').count).to eq(0) expect(routes.where(path: 'ghost').count).to eq(1)
expect(routes.where(path: 'ghost1').count).to eq(1)
expect(routes.where(path: 'ghost2').count).to eq(0)
disable_migrations_output { migrate! } disable_migrations_output { migrate! }
expect(routes.where(path: 'ghost').count).to eq(1) expect(routes.where(path: 'ghost').count).to eq(1)
expect(routes.where(path: 'ghost1').count).to eq(1)
expect(routes.where(path: 'ghost2').count).to eq(1)
end end
it 'fixes the path for the lost-and-found group by generating a unique one' do it 'fixes the path for the lost-and-found group by generating a unique one' do
......
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