diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 4e1329c10fb902ca2fea23c1bb75fe77c0ae2eea..c57fe4fd6c3b4a3e4980f3eeda47b9973eaf5185 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -50,8 +50,7 @@ class Admin::GroupsController < AdminController project_ids = params[:project_ids] Project.where(id: project_ids).each do |project| - project.namespace_id = @group.id - project.save + project.transfer(@group) end redirect_to :back, notice: 'Group was successfully updated.' @@ -59,8 +58,7 @@ class Admin::GroupsController < AdminController def remove_project @project = Project.find(params[:project_id]) - @project.namespace_id = nil - @project.save + @project.transfer(nil) redirect_to :back, notice: 'Group was successfully updated.' end diff --git a/app/models/project.rb b/app/models/project.rb index 2d12aa804c5c6dc6acbb48770421c3d563b29ad2..ad8d8293ff7a0509a5e52f15266dee7cbdbd4334 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -226,4 +226,18 @@ class Project < ActiveRecord::Base def code path end + + def transfer(new_namespace) + Project.transaction do + old_namespace = namespace + self.namespace = new_namespace + + old_dir = old_namespace.try(:path) || '' + new_dir = new_namespace.try(:path) || '' + + Gitlab::ProjectMover.new(self, old_dir, new_dir).execute + + save! + end + end end diff --git a/app/observers/project_observer.rb b/app/observers/project_observer.rb index dc80465bd5364e3b0be3b4738766bcce5242294c..03a617098299c22ddcbaa97374ff4b13ae696fe9 100644 --- a/app/observers/project_observer.rb +++ b/app/observers/project_observer.rb @@ -1,14 +1,5 @@ class ProjectObserver < ActiveRecord::Observer def after_save(project) - # 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) || '' - new_dir = Namespace.find_by_id(project.namespace_id).try(:path) || '' - - Gitlab::ProjectMover.new(project, old_dir, new_dir).execute - end - - # Update gitolite project.update_repository end