summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorOlaf Tomalka <olaf.tomalka@gmail.com>2016-09-06 02:31:06 +0200
committerOlaf Tomalka <olaf.tomalka@gmail.com>2016-09-06 04:16:14 +0200
commitbad3fb895cad46c52575aa91b02f7e7786634a47 (patch)
treebbcf1a2652b566db7c6c3e12d6173cda5c61fc9f /lib/api
parent7d2bd6b91bdfa0afd6b0032ddf23c24a28c61056 (diff)
downloadgitlab-ce-bad3fb895cad46c52575aa91b02f7e7786634a47.tar.gz
Added fork API paremeter for a specific namespace
Browser interface allows forking to an owned grup. This commit brings API up to speed by providing optional namespace parameter to fork API. This allows forking to users and groups under forker's control using their id or unique name. Fixes #21591
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/projects.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index a1fd598414a..d35ec73c8c1 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -189,16 +189,28 @@ module API
end
end
- # Fork new project for the current user.
+ # Fork new project for the current user or provided namespace.
#
# Parameters:
# id (required) - The ID of a project
+ # namespace (optional) - The ID or name of the namespace that the project will be forked into.
# Example Request
# POST /projects/fork/:id
post 'fork/:id' do
+ attrs = {}
+ namespace_id = params[:namespace]
+ if namespace_id.present?
+ namespace = Namespace.find_by(id: namespace_id) || Namespace.find_by_path_or_name(namespace_id)
+ if namespace.nil?
+ not_found!('Target Namespace')
+ end
+ authorize! :create_projects, namespace
+ attrs[:namespace] = namespace
+ end
@forked_project =
::Projects::ForkService.new(user_project,
- current_user).execute
+ current_user,
+ attrs).execute
if @forked_project.errors.any?
conflict!(@forked_project.errors.messages)
else