Fix project lookup. Show error if project transfer fails
This commit is contained in:
parent
d09873018a
commit
1d156c9c8e
5 changed files with 22 additions and 2 deletions
|
@ -7,6 +7,12 @@ window.slugify = (text) ->
|
|||
window.ajaxGet = (url) ->
|
||||
$.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
|
||||
window.disableButtonIfEmptyField = (field_selector, button_selector) ->
|
||||
field = $(field_selector)
|
||||
|
|
|
@ -46,6 +46,10 @@ class ProjectsController < ProjectResourceController
|
|||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
rescue Project::TransferError => ex
|
||||
@error = ex
|
||||
render :update_failed
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
@ -26,6 +26,8 @@ class Project < ActiveRecord::Base
|
|||
include Authority
|
||||
include Team
|
||||
|
||||
class TransferError < StandardError; end
|
||||
|
||||
attr_accessible :name, :path, :description, :default_branch, :issues_enabled,
|
||||
: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
|
||||
where(namespace_id: namespace_id).find_by_path(id.last)
|
||||
else
|
||||
find_by_path(id)
|
||||
where(path: id, namespace_id: nil).last
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -270,12 +272,18 @@ class Project < ActiveRecord::Base
|
|||
self.path
|
||||
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
|
||||
|
||||
git_host.move_repository(old_repo, self)
|
||||
|
||||
save!
|
||||
end
|
||||
rescue Gitlab::ProjectMover::ProjectMoveError => ex
|
||||
raise TransferError.new(ex.message)
|
||||
end
|
||||
|
||||
def name_with_namespace
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
%span Namespace
|
||||
.controls
|
||||
- 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'}
|
||||
|
||||
%span.cred Be careful. Changing project namespace can have unintended side effects
|
||||
- else
|
||||
|
|
2
app/views/projects/update_failed.js.haml
Normal file
2
app/views/projects/update_failed.js.haml
Normal file
|
@ -0,0 +1,2 @@
|
|||
:plain
|
||||
$(".save-project-loader").replaceWith(errorMessage('#{escape_javascript(@error.message)}'));
|
Loading…
Reference in a new issue