diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /app/finders/releases_finder.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) | |
download | gitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'app/finders/releases_finder.rb')
-rw-r--r-- | app/finders/releases_finder.rb | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/app/finders/releases_finder.rb b/app/finders/releases_finder.rb index 6a754fdb5a1..e961ad4c0ca 100644 --- a/app/finders/releases_finder.rb +++ b/app/finders/releases_finder.rb @@ -1,19 +1,20 @@ # frozen_string_literal: true class ReleasesFinder - attr_reader :project, :current_user, :params + include Gitlab::Utils::StrongMemoize - def initialize(project, current_user = nil, params = {}) - @project = project + attr_reader :parent, :current_user, :params + + def initialize(parent, current_user = nil, params = {}) + @parent = parent @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 if projects.empty? - # See https://gitlab.com/gitlab-org/gitlab/-/issues/211988 - releases = project.releases.where.not(tag: nil) # rubocop:disable CodeReuse/ActiveRecord + releases = get_releases releases = by_tag(releases) releases = releases.preloaded if preload releases.sorted @@ -21,6 +22,34 @@ class ReleasesFinder private + def get_releases + Release.where(project_id: projects).where.not(tag: nil) # rubocop: disable CodeReuse/ActiveRecord + end + + def include_subgroups? + params.fetch(:include_subgroups, false) + end + + def projects + strong_memoize(:projects) do + if parent.is_a?(Project) + Ability.allowed?(current_user, :read_release, parent) ? [parent] : [] + elsif parent.is_a?(Group) + accessible_projects + end + end + end + + def accessible_projects + projects = if include_subgroups? + Project.for_group_and_its_subgroups(parent) + else + parent.projects + end + + projects.select { |project| Ability.allowed?(current_user, :read_release, project) } + end + # rubocop: disable CodeReuse/ActiveRecord def by_tag(releases) return releases unless params[:tag].present? |