2022-05-07 20:08:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
module Releases
|
|
|
|
##
|
|
|
|
# The GroupReleasesFinder does not support all the options of ReleasesFinder
|
|
|
|
# due to use of InOperatorOptimization for finding subprojects/subgroups
|
|
|
|
#
|
|
|
|
# order_by - only ordering by released_at is supported
|
|
|
|
# filter by tag - currently not supported
|
2022-06-21 17:19:12 +05:30
|
|
|
# include_subgroups - always true for group releases finder
|
2022-05-07 20:08:51 +05:30
|
|
|
class GroupReleasesFinder
|
|
|
|
attr_reader :parent, :current_user, :params
|
|
|
|
|
|
|
|
def initialize(parent, current_user = nil, params = {})
|
|
|
|
@parent = parent
|
|
|
|
@current_user = current_user
|
|
|
|
@params = params
|
|
|
|
|
|
|
|
params[:sort] ||= 'desc'
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute(preload: true)
|
|
|
|
return Release.none unless Ability.allowed?(current_user, :read_release, parent)
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
releases = get_releases
|
|
|
|
releases.preloaded if preload
|
|
|
|
releases
|
2022-05-07 20:08:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2022-06-21 17:19:12 +05:30
|
|
|
def get_releases
|
2022-05-07 20:08:51 +05:30
|
|
|
Gitlab::Pagination::Keyset::InOperatorOptimization::QueryBuilder.new(
|
2022-06-21 17:19:12 +05:30
|
|
|
scope: releases_scope,
|
2022-08-27 11:52:29 +05:30
|
|
|
array_scope: Project.for_group_and_its_subgroups(parent).select(:id),
|
2022-05-07 20:08:51 +05:30
|
|
|
array_mapping_scope: -> (project_id_expression) { Release.where(Release.arel_table[:project_id].eq(project_id_expression)) },
|
|
|
|
finder_query: -> (order_by, id_expression) { Release.where(Release.arel_table[:id].eq(id_expression)) }
|
|
|
|
)
|
|
|
|
.execute
|
|
|
|
end
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
def releases_scope
|
|
|
|
Release.sort_by_attribute("released_at_#{params[:sort]}").order(id: params[:sort])
|
2022-05-07 20:08:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
end
|
|
|
|
end
|