Skip to content
Snippets Groups Projects
Commit 8053d08f authored by Bob Van Landuyt :neckbeard:'s avatar Bob Van Landuyt :neckbeard: :sunglasses:
Browse files

Update username when renaming a user-namespace

parent ae84e350
No related branches found
No related tags found
1 merge request!11492Fixes for the rename reserved paths helpers
Pipeline #
This commit is part of merge request !11492. Comments created here will be created in the context of that merge request.
Loading
Loading
@@ -48,6 +48,14 @@ module Gitlab
def self.name
'Namespace'
end
def kind
type == 'Group' ? 'group' : 'user'
end
end
class User < ActiveRecord::Base
self.table_name = 'users'
end
 
class Route < ActiveRecord::Base
Loading
Loading
Loading
Loading
@@ -29,9 +29,15 @@ module Gitlab
move_repositories(namespace, old_full_path, new_full_path)
move_uploads(old_full_path, new_full_path)
move_pages(old_full_path, new_full_path)
rename_user(old_full_path, new_full_path) if namespace.kind == 'user'
remove_cached_html_for_projects(projects_for_namespace(namespace).map(&:id))
end
 
def rename_user(old_username, new_username)
MigrationClasses::User.where(username: old_username)
.update_all(username: new_username)
end
def move_repositories(namespace, old_full_path, new_full_path)
repo_paths_for_namespace(namespace).each do |repository_storage_path|
# Ensure old directory exists before moving it
Loading
Loading
Loading
Loading
@@ -137,7 +137,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do
end
 
describe "#rename_namespace" do
let(:namespace) { create(:namespace, path: 'the-path') }
let(:namespace) { create(:group, name: 'the-path') }
 
it 'renames paths & routes for the namespace' do
expect(subject).to receive(:rename_path_for_routable).
Loading
Loading
@@ -177,6 +177,31 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do
 
subject.rename_namespace(namespace)
end
it "doesn't rename users for other namespaces" do
expect(subject).not_to receive(:rename_user)
subject.rename_namespace(namespace)
end
it 'renames the username of a namespace for a user' do
user = create(:user, username: 'the-path')
expect(subject).to receive(:rename_user).with('the-path', 'the-path0')
subject.rename_namespace(user.namespace)
end
end
describe '#rename_user' do
it 'renames a username' do
subject = described_class.new([], migration)
user = create(:user, username: 'broken')
subject.rename_user('broken', 'broken0')
expect(user.reload.username).to eq('broken0')
end
end
 
describe '#rename_namespaces' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment