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,6 +7,12 @@ window.slugify = (text) -> | ||
7 | window.ajaxGet = (url) -> | 7 | window.ajaxGet = (url) -> |
8 | $.ajax({type: "GET", url: url, dataType: "script"}) | 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 | # Disable button if text field is empty | 16 | # Disable button if text field is empty |
11 | window.disableButtonIfEmptyField = (field_selector, button_selector) -> | 17 | window.disableButtonIfEmptyField = (field_selector, button_selector) -> |
12 | field = $(field_selector) | 18 | field = $(field_selector) |
app/controllers/projects_controller.rb
@@ -46,6 +46,10 @@ class ProjectsController < ProjectResourceController | @@ -46,6 +46,10 @@ class ProjectsController < ProjectResourceController | ||
46 | format.js | 46 | format.js |
47 | end | 47 | end |
48 | end | 48 | end |
49 | + | ||
50 | + rescue Project::TransferError => ex | ||
51 | + @error = ex | ||
52 | + render :update_failed | ||
49 | end | 53 | end |
50 | 54 | ||
51 | def show | 55 | def show |
app/models/project.rb
@@ -26,6 +26,8 @@ class Project < ActiveRecord::Base | @@ -26,6 +26,8 @@ class Project < ActiveRecord::Base | ||
26 | include Authority | 26 | include Authority |
27 | include Team | 27 | include Team |
28 | 28 | ||
29 | + class TransferError < StandardError; end | ||
30 | + | ||
29 | attr_accessible :name, :path, :description, :default_branch, :issues_enabled, | 31 | attr_accessible :name, :path, :description, :default_branch, :issues_enabled, |
30 | :wall_enabled, :merge_requests_enabled, :wiki_enabled, as: [:default, :admin] | 32 | :wall_enabled, :merge_requests_enabled, :wiki_enabled, as: [:default, :admin] |
31 | 33 | ||
@@ -101,7 +103,7 @@ class Project < ActiveRecord::Base | @@ -101,7 +103,7 @@ class Project < ActiveRecord::Base | ||
101 | namespace_id = Namespace.find_by_path(id.first).id | 103 | namespace_id = Namespace.find_by_path(id.first).id |
102 | where(namespace_id: namespace_id).find_by_path(id.last) | 104 | where(namespace_id: namespace_id).find_by_path(id.last) |
103 | else | 105 | else |
104 | - find_by_path(id) | 106 | + where(path: id, namespace_id: nil).last |
105 | end | 107 | end |
106 | end | 108 | end |
107 | 109 | ||
@@ -270,12 +272,18 @@ class Project < ActiveRecord::Base | @@ -270,12 +272,18 @@ class Project < ActiveRecord::Base | ||
270 | self.path | 272 | self.path |
271 | end | 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 | Gitlab::ProjectMover.new(self, old_dir, new_dir).execute | 279 | Gitlab::ProjectMover.new(self, old_dir, new_dir).execute |
274 | 280 | ||
275 | git_host.move_repository(old_repo, self) | 281 | git_host.move_repository(old_repo, self) |
276 | 282 | ||
277 | save! | 283 | save! |
278 | end | 284 | end |
285 | + rescue Gitlab::ProjectMover::ProjectMoveError => ex | ||
286 | + raise TransferError.new(ex.message) | ||
279 | end | 287 | end |
280 | 288 | ||
281 | def name_with_namespace | 289 | def name_with_namespace |
app/views/projects/_form.html.haml
@@ -22,7 +22,7 @@ | @@ -22,7 +22,7 @@ | ||
22 | %span Namespace | 22 | %span Namespace |
23 | .controls | 23 | .controls |
24 | - if can? current_user, :change_namespace, @project | 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 | %span.cred Be careful. Changing project namespace can have unintended side effects | 27 | %span.cred Be careful. Changing project namespace can have unintended side effects |
28 | - else | 28 | - else |