Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Kaindl <bkl@use.startmail.com>2014-10-03 12:12:44 +0400
committerBernhard Kaindl <bkl@use.startmail.com>2014-10-03 13:52:29 +0400
commitc44764f523cea756f1f2efdc4db954f4f19df440 (patch)
tree217fa86abf6bcc5b4d5a301a47d93f92c66f0dae /app/services/projects/fork_service.rb
parentf74dba8c42ba5466945085bca137cc3a3a39ee87 (diff)
Prepare ForkService to support forking projects to given namespaces
Remove overload of BaseService.initialize, so initialize gains params, which is used to pass the namespace (like e.g. in TransferService). The namespace is checked for permission to create projects in it.
Diffstat (limited to 'app/services/projects/fork_service.rb')
-rw-r--r--app/services/projects/fork_service.rb19
1 files changed, 12 insertions, 7 deletions
diff --git a/app/services/projects/fork_service.rb b/app/services/projects/fork_service.rb
index a59311bf942..c4f2d08efe9 100644
--- a/app/services/projects/fork_service.rb
+++ b/app/services/projects/fork_service.rb
@@ -2,11 +2,9 @@ module Projects
class ForkService < BaseService
include Gitlab::ShellAdapter
- def initialize(project, user)
- @from_project, @current_user = project, user
- end
-
def execute
+ @from_project = @project
+
project_params = {
visibility_level: @from_project.visibility_level,
description: @from_project.description,
@@ -15,8 +13,15 @@ module Projects
project = Project.new(project_params)
project.name = @from_project.name
project.path = @from_project.path
- project.namespace = current_user.namespace
- project.creator = current_user
+ project.namespace = @current_user.namespace
+ if namespace = @params[:namespace]
+ project.namespace = namespace
+ end
+ project.creator = @current_user
+ unless @current_user.can?(:create_projects, project.namespace)
+ project.errors.add(:namespace, 'insufficient access rights')
+ return project
+ end
# If the project cannot save, we do not want to trigger the project destroy
# as this can have the side effect of deleting a repo attached to an existing
@@ -27,7 +32,7 @@ module Projects
#First save the DB entries as they can be rolled back if the repo fork fails
project.build_forked_project_link(forked_to_project_id: project.id, forked_from_project_id: @from_project.id)
if project.save
- project.team << [current_user, :master]
+ project.team << [@current_user, :master]
end
#Now fork the repo
unless gitlab_shell.fork_repository(@from_project.path_with_namespace, project.namespace.path)