summaryrefslogtreecommitdiff
path: root/app/finders/packages/maven/package_finder.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/packages/maven/package_finder.rb')
-rw-r--r--app/finders/packages/maven/package_finder.rb37
1 files changed, 27 insertions, 10 deletions
diff --git a/app/finders/packages/maven/package_finder.rb b/app/finders/packages/maven/package_finder.rb
index ba3d4631f55..eefcdaba3c8 100644
--- a/app/finders/packages/maven/package_finder.rb
+++ b/app/finders/packages/maven/package_finder.rb
@@ -3,13 +3,15 @@
module Packages
module Maven
class PackageFinder
- attr_reader :path, :current_user, :project, :group
+ include ::Packages::FinderHelper
+ include Gitlab::Utils::StrongMemoize
- def initialize(path, current_user, project: nil, group: nil)
+ def initialize(path, current_user, project: nil, group: nil, order_by_package_file: false)
@path = path
@current_user = current_user
@project = project
@group = group
+ @order_by_package_file = order_by_package_file
end
def execute
@@ -23,9 +25,9 @@ module Packages
private
def base
- if project
+ if @project
packages_for_a_single_project
- elsif group
+ elsif @group
packages_for_multiple_projects
else
::Packages::Package.none
@@ -33,8 +35,13 @@ module Packages
end
def packages_with_path
- matching_packages = base.only_maven_packages_with_path(path)
- matching_packages = matching_packages.order_by_package_file if versionless_package?(matching_packages)
+ matching_packages = base.only_maven_packages_with_path(@path, use_cte: @group.present?)
+
+ if group_level_improvements?
+ matching_packages = matching_packages.order_by_package_file if @order_by_package_file
+ else
+ matching_packages = matching_packages.order_by_package_file if versionless_package?(matching_packages)
+ end
matching_packages
end
@@ -48,19 +55,29 @@ module Packages
# Produces a query that retrieves packages from a single project.
def packages_for_a_single_project
- project.packages
+ @project.packages
end
# Produces a query that retrieves packages from multiple projects that
# the current user can view within a group.
def packages_for_multiple_projects
- ::Packages::Package.for_projects(projects_visible_to_current_user)
+ if group_level_improvements?
+ packages_visible_to_user(@current_user, within_group: @group)
+ else
+ ::Packages::Package.for_projects(projects_visible_to_current_user)
+ end
end
# Returns the projects that the current user can view within a group.
def projects_visible_to_current_user
- group.all_projects
- .public_or_visible_to_user(current_user)
+ @group.all_projects
+ .public_or_visible_to_user(@current_user)
+ end
+
+ def group_level_improvements?
+ strong_memoize(:group_level_improvements) do
+ Feature.enabled?(:maven_packages_group_level_improvements, default_enabled: :yaml)
+ end
end
end
end