diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ef6fc81a5d5..3062b5945c0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -63,7 +63,10 @@ class ApplicationController < ActionController::Base end def project - @project ||= current_user.projects.find_by_code(params[:project_id] || params[:id]) + id = params[:project_id] || params[:id] + id = id.split("/") if id.include?("/") + + @project ||= current_user.projects.find_by_code(id) @project || render_404 end diff --git a/app/models/project.rb b/app/models/project.rb index ef4905f6de5..479a2ac863a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -135,7 +135,11 @@ class Project < ActiveRecord::Base end def to_param - code + if namespace + namespace.code + "/" + code + else + code + end end def web_url @@ -201,4 +205,7 @@ class Project < ActiveRecord::Base path end end + + def move_repo + end end diff --git a/app/observers/project_observer.rb b/app/observers/project_observer.rb index 18874e72274..ed503f3d116 100644 --- a/app/observers/project_observer.rb +++ b/app/observers/project_observer.rb @@ -1,13 +1,15 @@ class ProjectObserver < ActiveRecord::Observer - def after_save(project) - project.update_repository - + def before_save(project) # Move repository if namespace changed if project.namespace_id_changed? move_project(project) end end + def after_save(project) + project.update_repository + end + def after_destroy(project) log_info("Project \"#{project.name}\" was removed") @@ -35,7 +37,8 @@ class ProjectObserver < ActiveRecord::Observer 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}` + + log_info "Project #{project.name} was moved from #{old_path} to #{new_path}" end end diff --git a/config/routes.rb b/config/routes.rb index 98cf7e812c9..42de89dd1df 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,7 +18,7 @@ Gitlab::Application.routes.draw do project_root: Gitlab.config.git_base_path, upload_pack: Gitlab.config.git_upload_pack, receive_pack: Gitlab.config.git_receive_pack - }), at: '/:path', constraints: { path: /[\w\.-]+\.git/ } + }), at: '/:path', constraints: { path: /[-\/\w\.-]+\.git/ } # # Help @@ -107,7 +107,7 @@ Gitlab::Application.routes.draw do # # Project Area # - resources :projects, constraints: { id: /[^\/]+/ }, except: [:new, :create, :index], path: "/" do + resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, except: [:new, :create, :index], path: "/" do member do get "wall" get "graph"