summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-26 00:06:28 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-26 00:06:28 +0000
commit9615736987b94a783845354ba881008e49d39238 (patch)
tree0620a1d06e44df92fa936b7a86e57d282f690181 /app
parenteb7390edf3afd52174b786fff1e06d5ffae0cec5 (diff)
downloadgitlab-ce-9615736987b94a783845354ba881008e49d39238.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/jobs_controller.rb20
-rw-r--r--app/controllers/projects/jobs_controller.rb29
-rw-r--r--app/finders/jobs_finder.rb51
-rw-r--r--app/models/ci/build.rb15
-rw-r--r--app/models/ci/pipeline.rb12
5 files changed, 77 insertions, 50 deletions
diff --git a/app/controllers/admin/jobs_controller.rb b/app/controllers/admin/jobs_controller.rb
index 0c1afdc3d3b..892f6dc657c 100644
--- a/app/controllers/admin/jobs_controller.rb
+++ b/app/controllers/admin/jobs_controller.rb
@@ -1,25 +1,15 @@
# frozen_string_literal: true
class Admin::JobsController < Admin::ApplicationController
- # rubocop: disable CodeReuse/ActiveRecord
def index
+ # We need all builds for tabs counters
+ @all_builds = JobsFinder.new(current_user: current_user).execute
+
@scope = params[:scope]
- @all_builds = Ci::Build
- @builds = @all_builds.order('id DESC')
- @builds =
- case @scope
- when 'pending'
- @builds.pending.reverse_order
- when 'running'
- @builds.running.reverse_order
- when 'finished'
- @builds.finished
- else
- @builds
- end
+ @builds = JobsFinder.new(current_user: current_user, params: params).execute
+ @builds = @builds.eager_load_everything
@builds = @builds.page(params[:page]).per(30)
end
- # rubocop: enable CodeReuse/ActiveRecord
def cancel_all
Ci::Build.running_or_pending.each(&:cancel)
diff --git a/app/controllers/projects/jobs_controller.rb b/app/controllers/projects/jobs_controller.rb
index 1d914ab6011..9480900b57a 100644
--- a/app/controllers/projects/jobs_controller.rb
+++ b/app/controllers/projects/jobs_controller.rb
@@ -17,34 +17,15 @@ class Projects::JobsController < Projects::ApplicationController
layout 'project'
- # rubocop: disable CodeReuse/ActiveRecord
def index
+ # We need all builds for tabs counters
+ @all_builds = JobsFinder.new(current_user: current_user, project: @project).execute
+
@scope = params[:scope]
- @all_builds = project.builds.relevant
- @builds = @all_builds.order('ci_builds.id DESC')
- @builds =
- case @scope
- when 'pending'
- @builds.pending.reverse_order
- when 'running'
- @builds.running.reverse_order
- when 'finished'
- @builds.finished
- else
- @builds
- end
- @builds = @builds.includes([
- { pipeline: [:project, :user] },
- :job_artifacts_archive,
- :metadata,
- :trigger_request,
- :project,
- :user,
- :tags
- ])
+ @builds = JobsFinder.new(current_user: current_user, project: @project, params: params).execute
+ @builds = @builds.eager_load_everything
@builds = @builds.page(params[:page]).per(30).without_count
end
- # rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def show
diff --git a/app/finders/jobs_finder.rb b/app/finders/jobs_finder.rb
new file mode 100644
index 00000000000..bac18e69618
--- /dev/null
+++ b/app/finders/jobs_finder.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+class JobsFinder
+ include Gitlab::Allowable
+
+ def initialize(current_user:, project: nil, params: {})
+ @current_user = current_user
+ @project = project
+ @params = params
+ end
+
+ def execute
+ builds = init_collection.order_id_desc
+ filter_by_scope(builds)
+ rescue Gitlab::Access::AccessDeniedError
+ Ci::Build.none
+ end
+
+ private
+
+ attr_reader :current_user, :project, :params
+
+ def init_collection
+ project ? project_builds : all_builds
+ end
+
+ def all_builds
+ raise Gitlab::Access::AccessDeniedError unless current_user&.admin?
+
+ Ci::Build.all
+ end
+
+ def project_builds
+ raise Gitlab::Access::AccessDeniedError unless can?(current_user, :read_build, project)
+
+ project.builds.relevant
+ end
+
+ def filter_by_scope(builds)
+ case params[:scope]
+ when 'pending'
+ builds.pending.reverse_order
+ when 'running'
+ builds.running.reverse_order
+ when 'finished'
+ builds.finished
+ else
+ builds
+ end
+ end
+end
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 59bff4e2d2b..4679e8b74d7 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -120,6 +120,20 @@ module Ci
scope :eager_load_job_artifacts, -> { includes(:job_artifacts) }
+ scope :eager_load_everything, -> do
+ includes(
+ [
+ { pipeline: [:project, :user] },
+ :job_artifacts_archive,
+ :metadata,
+ :trigger_request,
+ :project,
+ :user,
+ :tags
+ ]
+ )
+ end
+
scope :with_exposed_artifacts, -> do
joins(:metadata).merge(Ci::BuildMetadata.with_exposed_artifacts)
.includes(:metadata, :job_artifacts_metadata)
@@ -161,6 +175,7 @@ module Ci
end
scope :queued_before, ->(time) { where(arel_table[:queued_at].lt(time)) }
+ scope :order_id_desc, -> { order('ci_builds.id DESC') }
acts_as_taggable
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 6d38b58c301..b411bc296c5 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -772,18 +772,10 @@ module Ci
triggered_by_merge_request? && target_sha.present?
end
- def merge_train_pipeline?
- merge_request_pipeline? && merge_train_ref?
- end
-
def merge_request_ref?
MergeRequest.merge_request_ref?(ref)
end
- def merge_train_ref?
- MergeRequest.merge_train_ref?(ref)
- end
-
def matches_sha_or_source_sha?(sha)
self.sha == sha || self.source_sha == sha
end
@@ -816,9 +808,7 @@ module Ci
return unless merge_request_event?
strong_memoize(:merge_request_event_type) do
- if merge_train_pipeline?
- :merge_train
- elsif merge_request_pipeline?
+ if merge_request_pipeline?
:merged_result
elsif detached_merge_request_pipeline?
:detached