Commit 09b2c17a authored by lauraMon's avatar lauraMon

Updates method name, spec, and finder name

* Uses a more generic `with_preloads` method in models
* Updates spec since authorization was updated
* Updates jobs and bridges API to used newly modified JobsFinder
parent 2b9ec7b8
......@@ -21,6 +21,8 @@ module Ci
validates :ref, presence: true
scope :order_id_desc, -> { order('ci_builds.id DESC') }
# rubocop:disable Cop/ActiveRecordSerialize
serialize :options
serialize :yaml_variables, ::Gitlab::Serializer::Ci::Variables
......@@ -48,7 +50,7 @@ module Ci
raise NotImplementedError
end
def self.preload_metadata
def self.with_preloads
preload(
:metadata,
downstream_pipeline: [project: [:route, { namespace: :route }]],
......
......@@ -214,7 +214,7 @@ module Ci
# rubocop: enable CodeReuse/ServiceClass
end
def preload_job_artifacts
def with_preloads
preload(:job_artifacts_archive, :job_artifacts, project: [:namespace])
end
end
......
......@@ -124,10 +124,14 @@ module API
end
get ':id/pipelines/:pipeline_id/jobs' do
authenticate!
authorize!(:read_pipeline, user_project)
builds = ::Ci::PipelineJobsFinder.new(current_user, user_project, params).execute
builds = builds.preload_job_artifacts
pipeline = user_project.all_pipelines.find(params[:pipeline_id])
builds = ::Ci::JobsFinder
.new(current_user: current_user, pipeline: pipeline, params: params)
.execute
builds = builds.with_preloads
present paginate(builds), with: Entities::Job
end
......@@ -142,14 +146,15 @@ module API
end
get ':id/pipelines/:pipeline_id/bridges' do
authenticate!
bridges = ::Ci::PipelineJobsFinder.new(
current_user,
user_project,
params.merge(type: :bridges)
).execute
bridges = bridges.preload_metadata
authorize!(:read_build, user_project)
pipeline = user_project.all_pipelines.find(params[:pipeline_id])
bridges = ::Ci::JobsFinder
.new(current_user: current_user, pipeline: pipeline, params: params, type: ::Ci::Bridge)
.execute
bridges = bridges.with_preloads
present paginate(bridges), with: Entities::Bridge
end
......
......@@ -411,7 +411,8 @@ RSpec.describe API::Ci::Pipelines do
let(:api_user) { nil }
it 'does not return jobs' do
expect(response).to have_gitlab_http_status(:unauthorized)
expect(json_response['message']).to eq '404 Project Not Found'
expect(response).to have_gitlab_http_status(:not_found)
end
end
......@@ -427,7 +428,7 @@ RSpec.describe API::Ci::Pipelines do
end
describe 'GET /projects/:id/pipelines/:pipeline_id/bridges' do
let!(:bridge) { create(:ci_bridge, pipeline: pipeline) }
let_it_be(:bridge) { create(:ci_bridge, pipeline: pipeline) }
let(:downstream_pipeline) { create(:ci_pipeline) }
let!(:pipeline_source) do
......@@ -564,7 +565,8 @@ RSpec.describe API::Ci::Pipelines do
let(:api_user) { nil }
it 'does not return bridges' do
expect(response).to have_gitlab_http_status(:unauthorized)
expect(json_response['message']).to eq '404 Project Not Found'
expect(response).to have_gitlab_http_status(:not_found)
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