Commit 42e7e750 authored by Maxim Rydkin's avatar Maxim Rydkin

refactor app/services/ci/create_pipeline_service.rb:50:5

parent 0963ac36
...@@ -16,9 +16,9 @@ module Ci ...@@ -16,9 +16,9 @@ module Ci
protected: project.protected_for?(ref) protected: project.protected_for?(ref)
) )
result = validate(current_user, result = validate_project_and_git_items ||
ignore_skip_ci: ignore_skip_ci, validate_pipeline(ignore_skip_ci: ignore_skip_ci,
save_on_errors: save_on_errors) save_on_errors: save_on_errors)
return result if result return result if result
...@@ -47,13 +47,13 @@ module Ci ...@@ -47,13 +47,13 @@ module Ci
private private
def validate(triggering_user, ignore_skip_ci:, save_on_errors:) def validate_project_and_git_items
unless project.builds_enabled? unless project.builds_enabled?
return error('Pipeline is disabled') return error('Pipeline is disabled')
end end
unless allowed_to_trigger_pipeline?(triggering_user) unless allowed_to_trigger_pipeline?
if can?(triggering_user, :create_pipeline, project) if can?(current_user, :create_pipeline, project)
return error("Insufficient permissions for protected ref '#{ref}'") return error("Insufficient permissions for protected ref '#{ref}'")
else else
return error('Insufficient permissions to create a new pipeline') return error('Insufficient permissions to create a new pipeline')
...@@ -67,7 +67,9 @@ module Ci ...@@ -67,7 +67,9 @@ module Ci
unless commit unless commit
return error('Commit not found') return error('Commit not found')
end end
end
def validate_pipeline(ignore_skip_ci:, save_on_errors:)
unless pipeline.config_processor unless pipeline.config_processor
unless pipeline.ci_yaml_file unless pipeline.ci_yaml_file
return error("Missing #{pipeline.ci_yaml_file_path} file") return error("Missing #{pipeline.ci_yaml_file_path} file")
...@@ -85,18 +87,18 @@ module Ci ...@@ -85,18 +87,18 @@ module Ci
end end
end end
def allowed_to_trigger_pipeline?(triggering_user) def allowed_to_trigger_pipeline?
if triggering_user if current_user
allowed_to_create?(triggering_user) allowed_to_create?
else # legacy triggers don't have a corresponding user else # legacy triggers don't have a corresponding user
!project.protected_for?(ref) !project.protected_for?(ref)
end end
end end
def allowed_to_create?(triggering_user) def allowed_to_create?
access = Gitlab::UserAccess.new(triggering_user, project: project) access = Gitlab::UserAccess.new(current_user, project: project)
can?(triggering_user, :create_pipeline, project) && can?(current_user, :create_pipeline, project) &&
if branch? if branch?
access.can_update_branch?(ref) access.can_update_branch?(ref)
elsif tag? elsif tag?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment