diff options
Diffstat (limited to 'app/finders/releases_finder.rb')
-rw-r--r-- | app/finders/releases_finder.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/app/finders/releases_finder.rb b/app/finders/releases_finder.rb index e58a90922a5..6a754fdb5a1 100644 --- a/app/finders/releases_finder.rb +++ b/app/finders/releases_finder.rb @@ -1,17 +1,31 @@ # frozen_string_literal: true class ReleasesFinder - def initialize(project, current_user = nil) + attr_reader :project, :current_user, :params + + def initialize(project, current_user = nil, params = {}) @project = project @current_user = current_user + @params = params end def execute(preload: true) - return Release.none unless Ability.allowed?(@current_user, :read_release, @project) + return Release.none unless Ability.allowed?(current_user, :read_release, project) # See https://gitlab.com/gitlab-org/gitlab/-/issues/211988 - releases = @project.releases.where.not(tag: nil) # rubocop:disable CodeReuse/ActiveRecord + releases = project.releases.where.not(tag: nil) # rubocop:disable CodeReuse/ActiveRecord + releases = by_tag(releases) releases = releases.preloaded if preload releases.sorted end + + 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 end |