summaryrefslogtreecommitdiff
path: root/app/services/projects/create_service.rb
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-10-08 07:51:07 +0000
committerLin Jen-Shin <godfat@godfat.org>2016-10-08 07:51:07 +0000
commit94611607e56f0e0f0b05682481db79ff99e9e34e (patch)
treed2efea4ac3a6ec9aa3feabeb5c2187cfdd91d8f6 /app/services/projects/create_service.rb
parent720968cc8799f665f4f4392e80bf8dfe88fdd69b (diff)
parent28ca8502c254d5c3edfb7ece36fc365e7a715df0 (diff)
downloadgitlab-ce-94611607e56f0e0f0b05682481db79ff99e9e34e.tar.gz
Merge remote-tracking branch 'upstream/master' into pipeline-emails
* upstream/master: (292 commits) Deletes extra empty line breaking the build Optimize the `award_user_list` helper spec Fix typo and add he MWBS accronym for "Merge When Build Succeeds" Added missing content and improved layout ExpireBuildArtifactsWorker query builds table without ordering enqueuing one job per build to cleanup Improve the contribution and MR review guide Updates test in order to look for link Make projects API docs match parameter style Fix Event#reset_project_activity updates Update user whitelist reject message Call ensure_secret_token! in secret token test's before block since it would be called in an initializer. Add a CHANGELOG for CacheMarkdownField Enable CacheMarkdownField for the remaining models Make search results use the markdown cache columns, treating them consistently Use CacheMarkdownField for notes Add markdown cache columns to the database, but don't use them yet Update issue board spec Link to Registry docs from project settings Truncate long labels with ellipsis in labels page Improve issue load time performance by avoiding ORDER BY in find_by call ...
Diffstat (limited to 'app/services/projects/create_service.rb')
-rw-r--r--app/services/projects/create_service.rb20
1 files changed, 19 insertions, 1 deletions
diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb
index be749ba4a1c..15d7918e7fd 100644
--- a/app/services/projects/create_service.rb
+++ b/app/services/projects/create_service.rb
@@ -7,6 +7,8 @@ module Projects
def execute
forked_from_project_id = params.delete(:forked_from_project_id)
import_data = params.delete(:import_data)
+ @skip_wiki = params.delete(:skip_wiki)
+
@project = Project.new(params)
# Make sure that the user is allowed to use the specified visibility level
@@ -15,6 +17,11 @@ module Projects
return @project
end
+ unless allowed_fork?(forked_from_project_id)
+ @project.errors.add(:forked_from_project_id, 'is forbidden')
+ return @project
+ end
+
# Set project name from path
if @project.name.present? && @project.path.present?
# if both name and path set - everything is ok
@@ -71,6 +78,13 @@ module Projects
@project.errors.add(:namespace, "is not valid")
end
+ def allowed_fork?(source_project_id)
+ return true if source_project_id.nil?
+
+ source_project = Project.find_by(id: source_project_id)
+ current_user.can?(:fork_project, source_project)
+ end
+
def allowed_namespace?(user, namespace_id)
namespace = Namespace.find_by(id: namespace_id)
current_user.can?(:create_projects, namespace)
@@ -80,7 +94,7 @@ module Projects
log_info("#{@project.owner.name} created a new project \"#{@project.name_with_namespace}\"")
unless @project.gitlab_project_import?
- @project.create_wiki if @project.feature_available?(:wiki, current_user)
+ @project.create_wiki unless skip_wiki?
@project.build_missing_services
@project.create_labels
@@ -94,6 +108,10 @@ module Projects
end
end
+ def skip_wiki?
+ !@project.feature_available?(:wiki, current_user) || @skip_wiki
+ end
+
def save_project_and_import_data(import_data)
Project.transaction do
@project.create_or_update_import_data(data: import_data[:data], credentials: import_data[:credentials]) if import_data