diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /app/services/projects/create_service.rb | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'app/services/projects/create_service.rb')
-rw-r--r-- | app/services/projects/create_service.rb | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index 9bc8bb428fb..6381ee67ce7 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -26,7 +26,7 @@ module Projects return ::Projects::CreateFromTemplateService.new(current_user, params).execute end - @project = Project.new(params) + @project = Project.new(params.merge(creator: current_user)) validate_import_source_enabled! @@ -45,20 +45,14 @@ module Projects set_project_name_from_path # get namespace id - namespace_id = params[:namespace_id] - - if namespace_id - # Find matching namespace and check if it allowed - # for current user if namespace_id passed. - unless current_user.can?(:create_projects, parent_namespace) - @project.namespace_id = nil - deny_namespace - return @project - end - else - # Set current user namespace if namespace_id is nil - @project.namespace_id = current_user.namespace_id - end + namespace_id = params[:namespace_id] || current_user.namespace_id + @project.namespace_id = namespace_id.to_i + + @project.check_personal_projects_limit + return @project if @project.errors.any? + + validate_create_permissions + return @project if @project.errors.any? @relations_block&.call(@project) yield(@project) if block_given? @@ -92,7 +86,9 @@ module Projects protected - def deny_namespace + def validate_create_permissions + return if current_user.can?(:create_projects, parent_namespace) + @project.errors.add(:namespace, "is not valid") end |