Commit d405c8fc605256c1273cca1e30dfa1196459d625
1 parent
4023d9f8
Exists in
master
and in
4 other branches
Create namespace on username init. Raise exception if project cannot be moved
Showing
4 changed files
with
21 additions
and
8 deletions
Show diff stats
app/observers/project_observer.rb
1 | 1 | class ProjectObserver < ActiveRecord::Observer |
2 | 2 | def after_save(project) |
3 | - project.update_repository | |
4 | - | |
5 | 3 | # Move repository if namespace changed |
6 | 4 | if project.namespace_id_changed? and not project.new_record? |
7 | 5 | old_dir = Namespace.find_by_id(project.namespace_id_was).try(:path) || '' |
... | ... | @@ -9,6 +7,9 @@ class ProjectObserver < ActiveRecord::Observer |
9 | 7 | |
10 | 8 | Gitlab::ProjectMover.new(project, old_dir, new_dir).execute |
11 | 9 | end |
10 | + | |
11 | + # Update gitolite | |
12 | + project.update_repository | |
12 | 13 | end |
13 | 14 | |
14 | 15 | def after_destroy(project) | ... | ... |
app/observers/user_observer.rb
... | ... | @@ -12,8 +12,12 @@ class UserObserver < ActiveRecord::Observer |
12 | 12 | end |
13 | 13 | |
14 | 14 | def after_save user |
15 | - if user.username_changed? and user.namespace | |
16 | - user.namespace.update_attributes(path: user.username) | |
15 | + if user.username_changed? | |
16 | + if user.namespace | |
17 | + user.namespace.update_attributes(path: user.username) | |
18 | + else | |
19 | + user.create_namespace!(path: user.username, name: user.name) | |
20 | + end | |
17 | 21 | end |
18 | 22 | end |
19 | 23 | ... | ... |
lib/gitlab/project_mover.rb
... | ... | @@ -3,6 +3,8 @@ |
3 | 3 | # Used for moving project repositories from one subdir to another |
4 | 4 | module Gitlab |
5 | 5 | class ProjectMover |
6 | + class ProjectMoveError < StandardError; end | |
7 | + | |
6 | 8 | attr_reader :project, :old_dir, :new_dir |
7 | 9 | |
8 | 10 | def initialize(project, old_dir, new_dir) |
... | ... | @@ -23,7 +25,9 @@ module Gitlab |
23 | 25 | log_info "Project #{project.name} was moved from #{old_path} to #{new_path}" |
24 | 26 | true |
25 | 27 | else |
26 | - log_info "Error! Project #{project.name} cannot be moved from #{old_path} to #{new_path}" | |
28 | + message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}" | |
29 | + log_info "Error! #{message}" | |
30 | + raise ProjectMoveError.new(message) | |
27 | 31 | false |
28 | 32 | end |
29 | 33 | end | ... | ... |
lib/tasks/gitlab/activate_namespaces.rake
... | ... | @@ -2,11 +2,15 @@ namespace :gitlab do |
2 | 2 | desc "GITLAB | Enable usernames and namespaces for user projects" |
3 | 3 | task activate_namespaces: :environment do |
4 | 4 | User.find_each(batch_size: 500) do |user| |
5 | + next if user.namespace | |
6 | + | |
5 | 7 | User.transaction do |
6 | 8 | username = user.email.match(/^[^@]*/)[0] |
7 | - user.update_attributes!(username: username) | |
8 | - user.create_namespace!(code: username, name: user.name) | |
9 | - print '.'.green | |
9 | + if user.update_attributes!(username: username) | |
10 | + print '.'.green | |
11 | + else | |
12 | + print 'F'.red | |
13 | + end | |
10 | 14 | end |
11 | 15 | end |
12 | 16 | end | ... | ... |