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

listing.rb « catalog « ci « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 92464cb645fbafba047faea34aaf2a5a82728934 (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
# frozen_string_literal: true

module Ci
  module Catalog
    class Listing
      # This class is the SSoT to displaying the list of resources in the
      # CI/CD Catalog given a namespace as a scope.
      # This model is not directly backed by a table and joins catalog resources
      # with projects to return relevant data.
      def initialize(namespace, current_user)
        raise ArgumentError, 'Namespace is not a root namespace' unless namespace.root?

        @namespace = namespace
        @current_user = current_user
      end

      def resources
        Ci::Catalog::Resource
          .joins(:project).includes(:project)
          .merge(projects_in_namespace_visible_to_user)
      end

      private

      attr_reader :namespace, :current_user

      def projects_in_namespace_visible_to_user
        Project
          .in_namespace(namespace.self_and_descendant_ids)
          .public_or_visible_to_user(current_user)
      end
    end
  end
end