debian-mirror-gitlab/app/finders/releases_finder.rb

32 lines
838 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
class ReleasesFinder
2020-05-24 23:13:21 +05:30
attr_reader :project, :current_user, :params
def initialize(project, current_user = nil, params = {})
2019-02-15 15:39:39 +05:30
@project = project
@current_user = current_user
2020-05-24 23:13:21 +05:30
@params = params
2019-02-15 15:39:39 +05:30
end
2019-12-26 22:10:19 +05:30
def execute(preload: true)
2020-05-24 23:13:21 +05:30
return Release.none unless Ability.allowed?(current_user, :read_release, project)
2019-02-15 15:39:39 +05:30
2020-04-22 19:07:51 +05:30
# See https://gitlab.com/gitlab-org/gitlab/-/issues/211988
2020-05-24 23:13:21 +05:30
releases = project.releases.where.not(tag: nil) # rubocop:disable CodeReuse/ActiveRecord
releases = by_tag(releases)
2019-12-26 22:10:19 +05:30
releases = releases.preloaded if preload
releases.sorted
2019-02-15 15:39:39 +05:30
end
2020-05-24 23:13:21 +05:30
private
# rubocop: disable CodeReuse/ActiveRecord
def by_tag(releases)
return releases unless params[:tag].present?
releases.where(tag: params[:tag])
end
# rubocop: enable CodeReuse/ActiveRecord
2019-02-15 15:39:39 +05:30
end