Welcome to mirror list, hosted at ThFree Co, Russian Federation.

package_finder.rb « maven « packages « finders « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 775db12adb7ea2819415f2c79830c0efbba6a03a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true
module Packages
  module Maven
    class PackageFinder
      attr_reader :path, :current_user, :project, :group

      def initialize(path, current_user, project: nil, group: nil)
        @path = path
        @current_user = current_user
        @project = project
        @group = group
      end

      def execute
        packages_with_path.last
      end

      def execute!
        packages_with_path.last!
      end

      private

      def base
        if project
          packages_for_a_single_project
        elsif group
          packages_for_multiple_projects
        else
          packages
        end
      end

      def packages_with_path
        base.only_maven_packages_with_path(path)
      end

      # Produces a query that returns all packages.
      def packages
        ::Packages::Package.all
      end

      # Produces a query that retrieves packages from a single project.
      def packages_for_a_single_project
        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)
      end

      # Returns the projects that the current user can view within a group.
      def projects_visible_to_current_user
        ::Project
          .in_namespace(group.self_and_descendants.select(:id))
          .public_or_visible_to_user(current_user)
      end
    end
  end
end