Fix project lookup. Show error if project transfer fails

This commit is contained in:
Dmitriy Zaporozhets 2012-12-13 18:42:15 +02:00
parent d09873018a
commit 1d156c9c8e
5 changed files with 22 additions and 2 deletions

View file

@ -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)

View file

@ -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

View file

@ -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
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
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

View file

@ -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

View file

@ -0,0 +1,2 @@
:plain
$(".save-project-loader").replaceWith(errorMessage('#{escape_javascript(@error.message)}'));