summaryrefslogtreecommitdiff
path: root/app/services/projects/transfer_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/projects/transfer_service.rb')
-rw-r--r--app/services/projects/transfer_service.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb
new file mode 100644
index 00000000000..f8e27f6f1c6
--- /dev/null
+++ b/app/services/projects/transfer_service.rb
@@ -0,0 +1,22 @@
+module Projects
+ class TransferService < BaseService
+ 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.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
+