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,14 +48,18 @@ class Admin::GroupsController < AdminController | ||
| 48 | 48 | ||
| 49 | def project_update | 49 | def project_update |
| 50 | project_ids = params[:project_ids] | 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 | redirect_to :back, notice: 'Group was successfully updated.' | 57 | redirect_to :back, notice: 'Group was successfully updated.' |
| 54 | end | 58 | end |
| 55 | 59 | ||
| 56 | def remove_project | 60 | def remove_project |
| 57 | @project = Project.find(params[:project_id]) | 61 | @project = Project.find(params[:project_id]) |
| 58 | - @project.group_id = nil | 62 | + @project.namespace_id = nil |
| 59 | @project.save | 63 | @project.save |
| 60 | 64 | ||
| 61 | redirect_to :back, notice: 'Group was successfully updated.' | 65 | redirect_to :back, notice: 'Group was successfully updated.' |
app/controllers/dashboard_controller.rb
| @@ -4,7 +4,7 @@ class DashboardController < ApplicationController | @@ -4,7 +4,7 @@ class DashboardController < ApplicationController | ||
| 4 | before_filter :event_filter, only: :index | 4 | before_filter :event_filter, only: :index |
| 5 | 5 | ||
| 6 | def index | 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 | @projects = current_user.projects_sorted_by_activity | 8 | @projects = current_user.projects_sorted_by_activity |
| 9 | @projects = @projects.page(params[:page]).per(30) | 9 | @projects = @projects.page(params[:page]).per(30) |
| 10 | 10 |
app/controllers/groups_controller.rb
| @@ -54,7 +54,7 @@ class GroupsController < ApplicationController | @@ -54,7 +54,7 @@ class GroupsController < ApplicationController | ||
| 54 | end | 54 | end |
| 55 | 55 | ||
| 56 | def projects | 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 | end | 58 | end |
| 59 | 59 | ||
| 60 | def project_ids | 60 | def project_ids |
app/observers/issue_observer.rb
| @@ -3,7 +3,7 @@ class IssueObserver < ActiveRecord::Observer | @@ -3,7 +3,7 @@ class IssueObserver < ActiveRecord::Observer | ||
| 3 | 3 | ||
| 4 | def after_create(issue) | 4 | def after_create(issue) |
| 5 | if issue.assignee && issue.assignee != current_user | 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 | end | 7 | end |
| 8 | end | 8 | end |
| 9 | 9 | ||
| @@ -14,8 +14,8 @@ class IssueObserver < ActiveRecord::Observer | @@ -14,8 +14,8 @@ class IssueObserver < ActiveRecord::Observer | ||
| 14 | status = 'closed' if issue.is_being_closed? | 14 | status = 'closed' if issue.is_being_closed? |
| 15 | status = 'reopened' if issue.is_being_reopened? | 15 | status = 'reopened' if issue.is_being_reopened? |
| 16 | if status | 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 | Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user) | 19 | Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user) |
| 20 | end | 20 | end |
| 21 | end | 21 | end |
app/observers/project_observer.rb
| 1 | class ProjectObserver < ActiveRecord::Observer | 1 | class ProjectObserver < ActiveRecord::Observer |
| 2 | def after_save(project) | 2 | def after_save(project) |
| 3 | project.update_repository | 3 | project.update_repository |
| 4 | + | ||
| 5 | + # Move repository if namespace changed | ||
| 6 | + if project.namespace_id_changed? | ||
| 7 | + move_project(project) | ||
| 8 | + end | ||
| 4 | end | 9 | end |
| 5 | 10 | ||
| 6 | def after_destroy(project) | 11 | def after_destroy(project) |
| @@ -18,4 +23,19 @@ class ProjectObserver < ActiveRecord::Observer | @@ -18,4 +23,19 @@ class ProjectObserver < ActiveRecord::Observer | ||
| 18 | def log_info message | 23 | def log_info message |
| 19 | Gitlab::AppLogger.info message | 24 | Gitlab::AppLogger.info message |
| 20 | end | 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 | end | 41 | end |
app/roles/repository.rb
| @@ -79,11 +79,15 @@ module Repository | @@ -79,11 +79,15 @@ module Repository | ||
| 79 | end | 79 | end |
| 80 | 80 | ||
| 81 | def url_to_repo | 81 | def url_to_repo |
| 82 | - git_host.url_to_repo(path) | 82 | + git_host.url_to_repo(path_with_namespace) |
| 83 | end | 83 | end |
| 84 | 84 | ||
| 85 | def path_to_repo | 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 | end | 91 | end |
| 88 | 92 | ||
| 89 | def update_repository | 93 | def update_repository |
spec/factories.rb
| @@ -29,10 +29,14 @@ FactoryGirl.define do | @@ -29,10 +29,14 @@ FactoryGirl.define do | ||
| 29 | owner | 29 | owner |
| 30 | end | 30 | end |
| 31 | 31 | ||
| 32 | - factory :group do | 32 | + factory :namespace do |
| 33 | sequence(:name) { |n| "group#{n}" } | 33 | sequence(:name) { |n| "group#{n}" } |
| 34 | code { name.downcase.gsub(/\s/, '_') } | 34 | code { name.downcase.gsub(/\s/, '_') } |
| 35 | owner | 35 | owner |
| 36 | + | ||
| 37 | + factory :group do | ||
| 38 | + type 'Group' | ||
| 39 | + end | ||
| 36 | end | 40 | end |
| 37 | 41 | ||
| 38 | factory :users_project do | 42 | factory :users_project do |
| @@ -0,0 +1,12 @@ | @@ -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,6 +24,7 @@ require 'spec_helper' | ||
| 24 | describe Project do | 24 | describe Project do |
| 25 | describe "Associations" do | 25 | describe "Associations" do |
| 26 | it { should belong_to(:group) } | 26 | it { should belong_to(:group) } |
| 27 | + it { should belong_to(:namespace) } | ||
| 27 | it { should belong_to(:owner).class_name('User') } | 28 | it { should belong_to(:owner).class_name('User') } |
| 28 | it { should have_many(:users) } | 29 | it { should have_many(:users) } |
| 29 | it { should have_many(:events).dependent(:destroy) } | 30 | it { should have_many(:events).dependent(:destroy) } |