Commit d04148e6 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'ee-extract-job-artifacts-api-ce' into 'master'

Extract EE::API::JobArtifacts

See merge request gitlab-org/gitlab-ee!4854
parents a2e767d4 a5383054
module EE
module API
module JobArtifacts
extend ActiveSupport::Concern
prepended do
helpers do
def authorize_download_artifacts!
super
check_cross_project_pipelines_feature!
end
def check_cross_project_pipelines_feature!
if job_token_authentication? && !@project.feature_available?(:cross_project_pipelines)
not_found!('Project')
end
end
end
end
end
end
end
......@@ -2,6 +2,15 @@ module API
class JobArtifacts < Grape::API
before { authenticate_non_get! }
# EE::API::JobArtifacts would override the following helpers
helpers do
def authorize_download_artifacts!
authorize_read_builds!
end
end
prepend EE::API::JobArtifacts
params do
requires :id, type: String, desc: 'The ID of a project'
end
......@@ -16,8 +25,7 @@ module API
route_setting :authentication, job_token_allowed: true
get ':id/jobs/artifacts/:ref_name/download',
requirements: { ref_name: /.+/ } do
authorize_read_builds!
check_cross_project_pipelines_feature!
authorize_download_artifacts!
builds = user_project.latest_successful_builds_for(params[:ref_name])
latest_build = builds.find_by!(name: params[:job])
......@@ -33,8 +41,7 @@ module API
end
route_setting :authentication, job_token_allowed: true
get ':id/jobs/:job_id/artifacts' do
authorize_read_builds!
check_cross_project_pipelines_feature!
authorize_download_artifacts!
build = find_build!(params[:job_id])
......@@ -80,13 +87,5 @@ module API
present build, with: Entities::Job
end
end
helpers do
def check_cross_project_pipelines_feature!
if job_token_authentication? && !@project.feature_available?(:cross_project_pipelines)
not_found!('Project')
end
end
end
end
end
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