Don't permanently redirect when renaming a namespace
Steps to reproduce:
-
Go to your profile and change your username.
-
If you try to visit your profile now with your old username it redirects you to the new name. Example: https://gitlab.com/toon redirects to https://gitlab.com/toon_idle
If a new user tries to claim the username which is now available after the rename they get the following error.
Username change failed - Namespace route path toon has been taken
before. Please use another one. Namespace route is invalid. Namespace
path toon has been taken before. Please use another one
Things to check. Redirect still present in the RedirectRoutes
table.
RedirectRoute.find_by_path("toon")
=> #<RedirectRoute id: 229748, source_id: 214011, source_type: "Namespace", path: "toon", created_at: "2018-01-03 05:41:15", updated_at: "2018-01-03 05:41:15", permanent: true>
Route.find_by_path("toon_idle")
=> #<Route id: 220670, source_id: 214011, source_type: "Namespace", path: "toon_idle", created_at: nil, updated_at: "2018-01-03 05:41:14", name: "toon_idle">
Solution: Only redirect while the name is not taken.
The fix is in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/17521 in which we no longer create permanent redirects, the name becomes available immeadiatly. The redirect stays in place as long as possible, but is destroyed when the path is reclaimed.