Commit 71214bee755028946ff12748b8d7acbfef62d18d
1 parent
e29ccece
Exists in
master
and in
4 other branches
Move directory with project. Fixed all related path methods to use namespace
Showing
9 changed files
with
55 additions
and
10 deletions
Show diff stats
app/controllers/admin/groups_controller.rb
| ... | ... | @@ -48,14 +48,18 @@ class Admin::GroupsController < AdminController |
| 48 | 48 | |
| 49 | 49 | def project_update |
| 50 | 50 | project_ids = params[:project_ids] |
| 51 | - Project.where(id: project_ids).update_all(group_id: @group.id) | |
| 51 | + | |
| 52 | + Project.where(id: project_ids).each do |project| | |
| 53 | + project.namespace_id = @group.id | |
| 54 | + project.save | |
| 55 | + end | |
| 52 | 56 | |
| 53 | 57 | redirect_to :back, notice: 'Group was successfully updated.' |
| 54 | 58 | end |
| 55 | 59 | |
| 56 | 60 | def remove_project |
| 57 | 61 | @project = Project.find(params[:project_id]) |
| 58 | - @project.group_id = nil | |
| 62 | + @project.namespace_id = nil | |
| 59 | 63 | @project.save |
| 60 | 64 | |
| 61 | 65 | redirect_to :back, notice: 'Group was successfully updated.' | ... | ... |
app/controllers/dashboard_controller.rb
| ... | ... | @@ -4,7 +4,7 @@ class DashboardController < ApplicationController |
| 4 | 4 | before_filter :event_filter, only: :index |
| 5 | 5 | |
| 6 | 6 | def index |
| 7 | - @groups = Group.where(id: current_user.projects.pluck(:group_id)) | |
| 7 | + @groups = Group.where(id: current_user.projects.pluck(:namespace_id)) | |
| 8 | 8 | @projects = current_user.projects_sorted_by_activity |
| 9 | 9 | @projects = @projects.page(params[:page]).per(30) |
| 10 | 10 | ... | ... |
app/controllers/groups_controller.rb
| ... | ... | @@ -54,7 +54,7 @@ class GroupsController < ApplicationController |
| 54 | 54 | end |
| 55 | 55 | |
| 56 | 56 | def projects |
| 57 | - @projects ||= current_user.projects_sorted_by_activity.where(group_id: @group.id) | |
| 57 | + @projects ||= current_user.projects_sorted_by_activity.where(namespace_id: @group.id) | |
| 58 | 58 | end |
| 59 | 59 | |
| 60 | 60 | def project_ids | ... | ... |
app/observers/issue_observer.rb
| ... | ... | @@ -3,7 +3,7 @@ class IssueObserver < ActiveRecord::Observer |
| 3 | 3 | |
| 4 | 4 | def after_create(issue) |
| 5 | 5 | if issue.assignee && issue.assignee != current_user |
| 6 | - Notify.new_issue_email(issue.id).deliver | |
| 6 | + Notify.new_issue_email(issue.id).deliver | |
| 7 | 7 | end |
| 8 | 8 | end |
| 9 | 9 | |
| ... | ... | @@ -14,8 +14,8 @@ class IssueObserver < ActiveRecord::Observer |
| 14 | 14 | status = 'closed' if issue.is_being_closed? |
| 15 | 15 | status = 'reopened' if issue.is_being_reopened? |
| 16 | 16 | if status |
| 17 | - Note.create_status_change_note(issue, current_user, status) | |
| 18 | - [issue.author, issue.assignee].compact.each do |recipient| | |
| 17 | + Note.create_status_change_note(issue, current_user, status) | |
| 18 | + [issue.author, issue.assignee].compact.each do |recipient| | |
| 19 | 19 | Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user) |
| 20 | 20 | end |
| 21 | 21 | end | ... | ... |
app/observers/project_observer.rb
| 1 | 1 | class ProjectObserver < ActiveRecord::Observer |
| 2 | 2 | def after_save(project) |
| 3 | 3 | project.update_repository |
| 4 | + | |
| 5 | + # Move repository if namespace changed | |
| 6 | + if project.namespace_id_changed? | |
| 7 | + move_project(project) | |
| 8 | + end | |
| 4 | 9 | end |
| 5 | 10 | |
| 6 | 11 | def after_destroy(project) |
| ... | ... | @@ -18,4 +23,19 @@ class ProjectObserver < ActiveRecord::Observer |
| 18 | 23 | def log_info message |
| 19 | 24 | Gitlab::AppLogger.info message |
| 20 | 25 | end |
| 26 | + | |
| 27 | + def move_project(project) | |
| 28 | + old_dir = Namespace.find_by_id(project.namespace_id_was).try(:code) || '' | |
| 29 | + new_dir = Namespace.find_by_id(project.namespace_id).try(:code) || '' | |
| 30 | + | |
| 31 | + # Create new dir if missing | |
| 32 | + new_dir_path = File.join(Gitlab.config.git_base_path, new_dir) | |
| 33 | + Dir.mkdir(new_dir_path) unless File.exists?(new_dir_path) | |
| 34 | + | |
| 35 | + old_path = File.join(Gitlab.config.git_base_path, old_dir, "#{project.path}.git") | |
| 36 | + new_path = File.join(new_dir_path, "#{project.path}.git") | |
| 37 | + | |
| 38 | + binding.pry | |
| 39 | + `mv #{old_path} #{new_path}` | |
| 40 | + end | |
| 21 | 41 | end | ... | ... |
app/roles/repository.rb
| ... | ... | @@ -79,11 +79,15 @@ module Repository |
| 79 | 79 | end |
| 80 | 80 | |
| 81 | 81 | def url_to_repo |
| 82 | - git_host.url_to_repo(path) | |
| 82 | + git_host.url_to_repo(path_with_namespace) | |
| 83 | 83 | end |
| 84 | 84 | |
| 85 | 85 | def path_to_repo |
| 86 | - File.join(Gitlab.config.git_base_path, "#{path}.git") | |
| 86 | + File.join(Gitlab.config.git_base_path, namespace_dir, "#{path}.git") | |
| 87 | + end | |
| 88 | + | |
| 89 | + def namespace_dir | |
| 90 | + namespace.try(:code) || '' | |
| 87 | 91 | end |
| 88 | 92 | |
| 89 | 93 | def update_repository | ... | ... |
spec/factories.rb
| ... | ... | @@ -29,10 +29,14 @@ FactoryGirl.define do |
| 29 | 29 | owner |
| 30 | 30 | end |
| 31 | 31 | |
| 32 | - factory :group do | |
| 32 | + factory :namespace do | |
| 33 | 33 | sequence(:name) { |n| "group#{n}" } |
| 34 | 34 | code { name.downcase.gsub(/\s/, '_') } |
| 35 | 35 | owner |
| 36 | + | |
| 37 | + factory :group do | |
| 38 | + type 'Group' | |
| 39 | + end | |
| 36 | 40 | end |
| 37 | 41 | |
| 38 | 42 | factory :users_project do | ... | ... |
| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | +require 'spec_helper' | |
| 2 | + | |
| 3 | +describe Namespace do | |
| 4 | + let!(:namespace) { create(:namespace) } | |
| 5 | + | |
| 6 | + it { should have_many :projects } | |
| 7 | + it { should validate_presence_of :name } | |
| 8 | + it { should validate_uniqueness_of(:name) } | |
| 9 | + it { should validate_presence_of :code } | |
| 10 | + it { should validate_uniqueness_of(:code) } | |
| 11 | + it { should validate_presence_of :owner } | |
| 12 | +end | ... | ... |
spec/models/project_spec.rb
| ... | ... | @@ -24,6 +24,7 @@ require 'spec_helper' |
| 24 | 24 | describe Project do |
| 25 | 25 | describe "Associations" do |
| 26 | 26 | it { should belong_to(:group) } |
| 27 | + it { should belong_to(:namespace) } | |
| 27 | 28 | it { should belong_to(:owner).class_name('User') } |
| 28 | 29 | it { should have_many(:users) } |
| 29 | 30 | it { should have_many(:events).dependent(:destroy) } | ... | ... |