Commit 1d156c9c8ee0d81370844d58c2863cb4b780489e
1 parent
d0987301
Exists in
master
and in
4 other branches
Fix project lookup. Show error if project transfer fails
Showing
5 changed files
with
22 additions
and
2 deletions
Show diff stats
app/assets/javascripts/main.js.coffee
... | ... | @@ -7,6 +7,12 @@ window.slugify = (text) -> |
7 | 7 | window.ajaxGet = (url) -> |
8 | 8 | $.ajax({type: "GET", url: url, dataType: "script"}) |
9 | 9 | |
10 | +window.errorMessage = (message) -> | |
11 | + ehtml = $("<p>") | |
12 | + ehtml.addClass("error_message") | |
13 | + ehtml.html(message) | |
14 | + ehtml | |
15 | + | |
10 | 16 | # Disable button if text field is empty |
11 | 17 | window.disableButtonIfEmptyField = (field_selector, button_selector) -> |
12 | 18 | field = $(field_selector) | ... | ... |
app/controllers/projects_controller.rb
app/models/project.rb
... | ... | @@ -26,6 +26,8 @@ class Project < ActiveRecord::Base |
26 | 26 | include Authority |
27 | 27 | include Team |
28 | 28 | |
29 | + class TransferError < StandardError; end | |
30 | + | |
29 | 31 | attr_accessible :name, :path, :description, :default_branch, :issues_enabled, |
30 | 32 | :wall_enabled, :merge_requests_enabled, :wiki_enabled, as: [:default, :admin] |
31 | 33 | |
... | ... | @@ -101,7 +103,7 @@ class Project < ActiveRecord::Base |
101 | 103 | namespace_id = Namespace.find_by_path(id.first).id |
102 | 104 | where(namespace_id: namespace_id).find_by_path(id.last) |
103 | 105 | else |
104 | - find_by_path(id) | |
106 | + where(path: id, namespace_id: nil).last | |
105 | 107 | end |
106 | 108 | end |
107 | 109 | |
... | ... | @@ -270,12 +272,18 @@ class Project < ActiveRecord::Base |
270 | 272 | self.path |
271 | 273 | end |
272 | 274 | |
275 | + if Project.where(path: self.path, namespace_id: new_namespace.try(:id)).present? | |
276 | + raise TransferError.new("Project with same path in target namespace already exists") | |
277 | + end | |
278 | + | |
273 | 279 | Gitlab::ProjectMover.new(self, old_dir, new_dir).execute |
274 | 280 | |
275 | 281 | git_host.move_repository(old_repo, self) |
276 | 282 | |
277 | 283 | save! |
278 | 284 | end |
285 | + rescue Gitlab::ProjectMover::ProjectMoveError => ex | |
286 | + raise TransferError.new(ex.message) | |
279 | 287 | end |
280 | 288 | |
281 | 289 | def name_with_namespace | ... | ... |
app/views/projects/_form.html.haml
... | ... | @@ -22,7 +22,7 @@ |
22 | 22 | %span Namespace |
23 | 23 | .controls |
24 | 24 | - if can? current_user, :change_namespace, @project |
25 | - = f.select :namespace_id, namespaces_options(@project.namespace_id), {prompt: 'Choose a project namespace'}, {class: 'chosen'} | |
25 | + = f.select :namespace_id, namespaces_options(@project.namespace_id || Namespace::global_id), {prompt: 'Choose a project namespace'}, {class: 'chosen'} | |
26 | 26 | |
27 | 27 | %span.cred Be careful. Changing project namespace can have unintended side effects |
28 | 28 | - else | ... | ... |