Move directory with project. Fixed all related path methods to use namespace
This commit is contained in:
parent
e29ccece33
commit
71214bee75
9 changed files with 55 additions and 10 deletions
|
@ -48,14 +48,18 @@ class Admin::GroupsController < AdminController
|
|||
|
||||
def project_update
|
||||
project_ids = params[:project_ids]
|
||||
Project.where(id: project_ids).update_all(group_id: @group.id)
|
||||
|
||||
Project.where(id: project_ids).each do |project|
|
||||
project.namespace_id = @group.id
|
||||
project.save
|
||||
end
|
||||
|
||||
redirect_to :back, notice: 'Group was successfully updated.'
|
||||
end
|
||||
|
||||
def remove_project
|
||||
@project = Project.find(params[:project_id])
|
||||
@project.group_id = nil
|
||||
@project.namespace_id = nil
|
||||
@project.save
|
||||
|
||||
redirect_to :back, notice: 'Group was successfully updated.'
|
||||
|
|
|
@ -4,7 +4,7 @@ class DashboardController < ApplicationController
|
|||
before_filter :event_filter, only: :index
|
||||
|
||||
def index
|
||||
@groups = Group.where(id: current_user.projects.pluck(:group_id))
|
||||
@groups = Group.where(id: current_user.projects.pluck(:namespace_id))
|
||||
@projects = current_user.projects_sorted_by_activity
|
||||
@projects = @projects.page(params[:page]).per(30)
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ class GroupsController < ApplicationController
|
|||
end
|
||||
|
||||
def projects
|
||||
@projects ||= current_user.projects_sorted_by_activity.where(group_id: @group.id)
|
||||
@projects ||= current_user.projects_sorted_by_activity.where(namespace_id: @group.id)
|
||||
end
|
||||
|
||||
def project_ids
|
||||
|
|
|
@ -3,7 +3,7 @@ class IssueObserver < ActiveRecord::Observer
|
|||
|
||||
def after_create(issue)
|
||||
if issue.assignee && issue.assignee != current_user
|
||||
Notify.new_issue_email(issue.id).deliver
|
||||
Notify.new_issue_email(issue.id).deliver
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -14,8 +14,8 @@ class IssueObserver < ActiveRecord::Observer
|
|||
status = 'closed' if issue.is_being_closed?
|
||||
status = 'reopened' if issue.is_being_reopened?
|
||||
if status
|
||||
Note.create_status_change_note(issue, current_user, status)
|
||||
[issue.author, issue.assignee].compact.each do |recipient|
|
||||
Note.create_status_change_note(issue, current_user, status)
|
||||
[issue.author, issue.assignee].compact.each do |recipient|
|
||||
Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
class ProjectObserver < ActiveRecord::Observer
|
||||
def after_save(project)
|
||||
project.update_repository
|
||||
|
||||
# Move repository if namespace changed
|
||||
if project.namespace_id_changed?
|
||||
move_project(project)
|
||||
end
|
||||
end
|
||||
|
||||
def after_destroy(project)
|
||||
|
@ -18,4 +23,19 @@ class ProjectObserver < ActiveRecord::Observer
|
|||
def log_info message
|
||||
Gitlab::AppLogger.info message
|
||||
end
|
||||
|
||||
def move_project(project)
|
||||
old_dir = Namespace.find_by_id(project.namespace_id_was).try(:code) || ''
|
||||
new_dir = Namespace.find_by_id(project.namespace_id).try(:code) || ''
|
||||
|
||||
# Create new dir if missing
|
||||
new_dir_path = File.join(Gitlab.config.git_base_path, new_dir)
|
||||
Dir.mkdir(new_dir_path) unless File.exists?(new_dir_path)
|
||||
|
||||
old_path = File.join(Gitlab.config.git_base_path, old_dir, "#{project.path}.git")
|
||||
new_path = File.join(new_dir_path, "#{project.path}.git")
|
||||
|
||||
binding.pry
|
||||
`mv #{old_path} #{new_path}`
|
||||
end
|
||||
end
|
||||
|
|
|
@ -79,11 +79,15 @@ module Repository
|
|||
end
|
||||
|
||||
def url_to_repo
|
||||
git_host.url_to_repo(path)
|
||||
git_host.url_to_repo(path_with_namespace)
|
||||
end
|
||||
|
||||
def path_to_repo
|
||||
File.join(Gitlab.config.git_base_path, "#{path}.git")
|
||||
File.join(Gitlab.config.git_base_path, namespace_dir, "#{path}.git")
|
||||
end
|
||||
|
||||
def namespace_dir
|
||||
namespace.try(:code) || ''
|
||||
end
|
||||
|
||||
def update_repository
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue