Commit f9979476 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Project can be transfered to namespace and out now

parent d405c8fc
...@@ -50,8 +50,7 @@ class Admin::GroupsController < AdminController ...@@ -50,8 +50,7 @@ class Admin::GroupsController < AdminController
project_ids = params[:project_ids] project_ids = params[:project_ids]
Project.where(id: project_ids).each do |project| Project.where(id: project_ids).each do |project|
project.namespace_id = @group.id project.transfer(@group)
project.save
end end
redirect_to :back, notice: 'Group was successfully updated.' redirect_to :back, notice: 'Group was successfully updated.'
...@@ -59,8 +58,7 @@ class Admin::GroupsController < AdminController ...@@ -59,8 +58,7 @@ class Admin::GroupsController < AdminController
def remove_project def remove_project
@project = Project.find(params[:project_id]) @project = Project.find(params[:project_id])
@project.namespace_id = nil @project.transfer(nil)
@project.save
redirect_to :back, notice: 'Group was successfully updated.' redirect_to :back, notice: 'Group was successfully updated.'
end end
......
...@@ -226,4 +226,18 @@ class Project < ActiveRecord::Base ...@@ -226,4 +226,18 @@ class Project < ActiveRecord::Base
def code def code
path path
end 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 end
class ProjectObserver < ActiveRecord::Observer class ProjectObserver < ActiveRecord::Observer
def after_save(project) 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 project.update_repository
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment