Commit 1d156c9c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix project lookup. Show error if project transfer fails

parent d0987301
...@@ -7,6 +7,12 @@ window.slugify = (text) -> ...@@ -7,6 +7,12 @@ window.slugify = (text) ->
window.ajaxGet = (url) -> window.ajaxGet = (url) ->
$.ajax({type: "GET", url: url, dataType: "script"}) $.ajax({type: "GET", url: url, dataType: "script"})
window.errorMessage = (message) ->
ehtml = $("<p>")
ehtml.addClass("error_message")
ehtml.html(message)
ehtml
# Disable button if text field is empty # Disable button if text field is empty
window.disableButtonIfEmptyField = (field_selector, button_selector) -> window.disableButtonIfEmptyField = (field_selector, button_selector) ->
field = $(field_selector) field = $(field_selector)
......
...@@ -46,6 +46,10 @@ class ProjectsController < ProjectResourceController ...@@ -46,6 +46,10 @@ class ProjectsController < ProjectResourceController
format.js format.js
end end
end end
rescue Project::TransferError => ex
@error = ex
render :update_failed
end end
def show def show
......
...@@ -26,6 +26,8 @@ class Project < ActiveRecord::Base ...@@ -26,6 +26,8 @@ class Project < ActiveRecord::Base
include Authority include Authority
include Team include Team
class TransferError < StandardError; end
attr_accessible :name, :path, :description, :default_branch, :issues_enabled, attr_accessible :name, :path, :description, :default_branch, :issues_enabled,
:wall_enabled, :merge_requests_enabled, :wiki_enabled, as: [:default, :admin] :wall_enabled, :merge_requests_enabled, :wiki_enabled, as: [:default, :admin]
...@@ -101,7 +103,7 @@ class Project < ActiveRecord::Base ...@@ -101,7 +103,7 @@ class Project < ActiveRecord::Base
namespace_id = Namespace.find_by_path(id.first).id namespace_id = Namespace.find_by_path(id.first).id
where(namespace_id: namespace_id).find_by_path(id.last) where(namespace_id: namespace_id).find_by_path(id.last)
else else
find_by_path(id) where(path: id, namespace_id: nil).last
end end
end end
...@@ -270,12 +272,18 @@ class Project < ActiveRecord::Base ...@@ -270,12 +272,18 @@ class Project < ActiveRecord::Base
self.path self.path
end end
if Project.where(path: self.path, namespace_id: new_namespace.try(:id)).present?
raise TransferError.new("Project with same path in target namespace already exists")
end
Gitlab::ProjectMover.new(self, old_dir, new_dir).execute Gitlab::ProjectMover.new(self, old_dir, new_dir).execute
git_host.move_repository(old_repo, self) git_host.move_repository(old_repo, self)
save! save!
end end
rescue Gitlab::ProjectMover::ProjectMoveError => ex
raise TransferError.new(ex.message)
end end
def name_with_namespace def name_with_namespace
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
%span Namespace %span Namespace
.controls .controls
- if can? current_user, :change_namespace, @project - if can? current_user, :change_namespace, @project
= f.select :namespace_id, namespaces_options(@project.namespace_id), {prompt: 'Choose a project namespace'}, {class: 'chosen'} = f.select :namespace_id, namespaces_options(@project.namespace_id || Namespace::global_id), {prompt: 'Choose a project namespace'}, {class: 'chosen'}
&nbsp; &nbsp;
%span.cred Be careful. Changing project namespace can have unintended side effects %span.cred Be careful. Changing project namespace can have unintended side effects
- else - else
......
:plain
$(".save-project-loader").replaceWith(errorMessage('#{escape_javascript(@error.message)}'));
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