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 ...@@ -21,6 +21,8 @@ module Ci
validates :ref, presence: true validates :ref, presence: true
scope :order_id_desc, -> { order('ci_builds.id DESC') }
# rubocop:disable Cop/ActiveRecordSerialize # rubocop:disable Cop/ActiveRecordSerialize
serialize :options serialize :options
serialize :yaml_variables, ::Gitlab::Serializer::Ci::Variables serialize :yaml_variables, ::Gitlab::Serializer::Ci::Variables
...@@ -48,7 +50,7 @@ module Ci ...@@ -48,7 +50,7 @@ module Ci
raise NotImplementedError raise NotImplementedError
end end
def self.preload_metadata def self.with_preloads
preload( preload(
:metadata, :metadata,
downstream_pipeline: [project: [:route, { namespace: :route }]], downstream_pipeline: [project: [:route, { namespace: :route }]],
......
...@@ -214,7 +214,7 @@ module Ci ...@@ -214,7 +214,7 @@ module Ci
# rubocop: enable CodeReuse/ServiceClass # rubocop: enable CodeReuse/ServiceClass
end end
def preload_job_artifacts def with_preloads
preload(:job_artifacts_archive, :job_artifacts, project: [:namespace]) preload(:job_artifacts_archive, :job_artifacts, project: [:namespace])
end end
end end
......
...@@ -124,10 +124,14 @@ module API ...@@ -124,10 +124,14 @@ module API
end end
get ':id/pipelines/:pipeline_id/jobs' do get ':id/pipelines/:pipeline_id/jobs' do
authenticate! authorize!(:read_pipeline, user_project)
builds = ::Ci::PipelineJobsFinder.new(current_user, user_project, params).execute pipeline = user_project.all_pipelines.find(params[:pipeline_id])
builds = builds.preload_job_artifacts builds = ::Ci::JobsFinder
.new(current_user: current_user, pipeline: pipeline, params: params)
.execute
builds = builds.with_preloads
present paginate(builds), with: Entities::Job present paginate(builds), with: Entities::Job
end end
...@@ -142,14 +146,15 @@ module API ...@@ -142,14 +146,15 @@ module API
end end
get ':id/pipelines/:pipeline_id/bridges' do get ':id/pipelines/:pipeline_id/bridges' do
authenticate! authorize!(:read_build, user_project)
bridges = ::Ci::PipelineJobsFinder.new( pipeline = user_project.all_pipelines.find(params[:pipeline_id])
current_user,
user_project, bridges = ::Ci::JobsFinder
params.merge(type: :bridges) .new(current_user: current_user, pipeline: pipeline, params: params, type: ::Ci::Bridge)
).execute .execute
bridges = bridges.preload_metadata
bridges = bridges.with_preloads
present paginate(bridges), with: Entities::Bridge present paginate(bridges), with: Entities::Bridge
end end
......
...@@ -411,7 +411,8 @@ RSpec.describe API::Ci::Pipelines do ...@@ -411,7 +411,8 @@ RSpec.describe API::Ci::Pipelines do
let(:api_user) { nil } let(:api_user) { nil }
it 'does not return jobs' do 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
end end
...@@ -427,7 +428,7 @@ RSpec.describe API::Ci::Pipelines do ...@@ -427,7 +428,7 @@ RSpec.describe API::Ci::Pipelines do
end end
describe 'GET /projects/:id/pipelines/:pipeline_id/bridges' do 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(:downstream_pipeline) { create(:ci_pipeline) }
let!(:pipeline_source) do let!(:pipeline_source) do
...@@ -564,7 +565,8 @@ RSpec.describe API::Ci::Pipelines do ...@@ -564,7 +565,8 @@ RSpec.describe API::Ci::Pipelines do
let(:api_user) { nil } let(:api_user) { nil }
it 'does not return bridges' do 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
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