Skip to content
Snippets Groups Projects
Commit d405c8fc authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Create namespace on username init. Raise exception if project cannot be moved

parent 4023d9f8
No related branches found
No related tags found
1 merge request!2051User/Group namespaces for projects
class ProjectObserver < ActiveRecord::Observer
def after_save(project)
project.update_repository
# Move repository if namespace changed
if project.namespace_id_changed? and not project.new_record?
old_dir = Namespace.find_by_id(project.namespace_id_was).try(:path) || ''
Loading
Loading
@@ -9,6 +7,9 @@ class ProjectObserver < ActiveRecord::Observer
 
Gitlab::ProjectMover.new(project, old_dir, new_dir).execute
end
# Update gitolite
project.update_repository
end
 
def after_destroy(project)
Loading
Loading
Loading
Loading
@@ -12,8 +12,12 @@ class UserObserver < ActiveRecord::Observer
end
 
def after_save user
if user.username_changed? and user.namespace
user.namespace.update_attributes(path: user.username)
if user.username_changed?
if user.namespace
user.namespace.update_attributes(path: user.username)
else
user.create_namespace!(path: user.username, name: user.name)
end
end
end
 
Loading
Loading
Loading
Loading
@@ -3,6 +3,8 @@
# Used for moving project repositories from one subdir to another
module Gitlab
class ProjectMover
class ProjectMoveError < StandardError; end
attr_reader :project, :old_dir, :new_dir
 
def initialize(project, old_dir, new_dir)
Loading
Loading
@@ -23,7 +25,9 @@ module Gitlab
log_info "Project #{project.name} was moved from #{old_path} to #{new_path}"
true
else
log_info "Error! Project #{project.name} cannot be moved from #{old_path} to #{new_path}"
message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}"
log_info "Error! #{message}"
raise ProjectMoveError.new(message)
false
end
end
Loading
Loading
Loading
Loading
@@ -2,11 +2,15 @@ namespace :gitlab do
desc "GITLAB | Enable usernames and namespaces for user projects"
task activate_namespaces: :environment do
User.find_each(batch_size: 500) do |user|
next if user.namespace
User.transaction do
username = user.email.match(/^[^@]*/)[0]
user.update_attributes!(username: username)
user.create_namespace!(code: username, name: user.name)
print '.'.green
if user.update_attributes!(username: username)
print '.'.green
else
print 'F'.red
end
end
end
end
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