File: group_project_params.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (54 lines) | stat: -rw-r--r-- 1,698 bytes parent folder | download
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
# frozen_string_literal: true

# This DRYs up some methods used by both the GraphQL and REST milestone APIs
module API
  module Concerns
    module Milestones
      module GroupProjectParams
        extend ActiveSupport::Concern

        private

        def project_finder_params(parent, params)
          return { project_ids: parent.id } unless params[:include_ancestors].present? && parent.group.present?

          {
            group_ids: parent.group.self_and_ancestors.select(:id),
            project_ids: parent.id
          }
        end

        def group_finder_params(parent, params)
          include_ancestors = params[:include_ancestors].present?
          include_descendants = params[:include_descendants].present?
          return { group_ids: parent.id } unless include_ancestors || include_descendants

          group_ids = if include_ancestors && include_descendants
                        parent.self_and_hierarchy
                      elsif include_ancestors
                        parent.self_and_ancestors
                      else
                        parent.self_and_descendants
                      end

          if include_descendants
            project_ids = group_projects(parent).with_issues_or_mrs_available_for_user(current_user)
          end

          {
            group_ids: group_ids.public_or_visible_to_user(current_user).select(:id),
            project_ids: project_ids
          }
        end

        def group_projects(parent)
          GroupProjectsFinder.new(
            group: parent,
            current_user: current_user,
            options: { include_subgroups: true }
          ).execute
        end
      end
    end
  end
end