Commit 1fb99264a99e5fbe03b9ccef42ac8c4f07575d8c
1 parent
850881a2
Exists in
master
and in
4 other branches
Use TransferContext for project
Showing
2 changed files
with
34 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | +module Projects | |
| 2 | + class TransferContext < BaseContext | |
| 3 | + def execute(role = :default) | |
| 4 | + namespace_id = params[:project].delete(:namespace_id) | |
| 5 | + allowed_transfer = can?(current_user, :change_namespace, project) || role == :admin | |
| 6 | + | |
| 7 | + if allowed_transfer && namespace_id.present? | |
| 8 | + if namespace_id == Namespace.global_id | |
| 9 | + if project.namespace.present? | |
| 10 | + # Transfer to global namespace from anyone | |
| 11 | + project.transfer(nil) | |
| 12 | + end | |
| 13 | + elsif namespace_id.to_i != project.namespace_id | |
| 14 | + # Transfer to someone namespace | |
| 15 | + namespace = Namespace.find(namespace_id) | |
| 16 | + project.transfer(namespace) | |
| 17 | + end | |
| 18 | + end | |
| 19 | + | |
| 20 | + rescue ProjectTransferService::TransferError => ex | |
| 21 | + project.reload | |
| 22 | + project.errors.add(:namespace_id, ex.message) | |
| 23 | + false | |
| 24 | + end | |
| 25 | + end | |
| 26 | +end | |
| 27 | + | ... | ... |
| ... | ... | @@ -0,0 +1,7 @@ |
| 1 | +- if @project.errors[:namespace_id].present? | |
| 2 | + :plain | |
| 3 | + $("#tab-transfer .errors-holder").replaceWith(errorMessage('#{escape_javascript(@project.errors[:namespace_id].first)}')); | |
| 4 | + $("#tab-transfer .form-actions input").removeAttr('disabled').removeClass('disabled'); | |
| 5 | +- else | |
| 6 | + :plain | |
| 7 | + location.href = "#{edit_project_path(@project)}"; | ... | ... |