Use TransferContext for project
This commit is contained in:
parent
850881a2ef
commit
1fb99264a9
2 changed files with 34 additions and 0 deletions
27
app/contexts/projects/transfer_context.rb
Normal file
27
app/contexts/projects/transfer_context.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Projects
|
||||
class TransferContext < BaseContext
|
||||
def execute(role = :default)
|
||||
namespace_id = params[:project].delete(:namespace_id)
|
||||
allowed_transfer = can?(current_user, :change_namespace, project) || role == :admin
|
||||
|
||||
if allowed_transfer && namespace_id.present?
|
||||
if namespace_id == Namespace.global_id
|
||||
if project.namespace.present?
|
||||
# Transfer to global namespace from anyone
|
||||
project.transfer(nil)
|
||||
end
|
||||
elsif namespace_id.to_i != project.namespace_id
|
||||
# Transfer to someone namespace
|
||||
namespace = Namespace.find(namespace_id)
|
||||
project.transfer(namespace)
|
||||
end
|
||||
end
|
||||
|
||||
rescue ProjectTransferService::TransferError => ex
|
||||
project.reload
|
||||
project.errors.add(:namespace_id, ex.message)
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
7
app/views/projects/transfer.js.haml
Normal file
7
app/views/projects/transfer.js.haml
Normal file
|
@ -0,0 +1,7 @@
|
|||
- if @project.errors[:namespace_id].present?
|
||||
:plain
|
||||
$("#tab-transfer .errors-holder").replaceWith(errorMessage('#{escape_javascript(@project.errors[:namespace_id].first)}'));
|
||||
$("#tab-transfer .form-actions input").removeAttr('disabled').removeClass('disabled');
|
||||
- else
|
||||
:plain
|
||||
location.href = "#{edit_project_path(@project)}";
|
Loading…
Reference in a new issue