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) ->
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'}
&nbsp;
%span.cred Be careful. Changing project namespace can have unintended side effects
- 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