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

group_detail.rb « entities « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9f3ced7d717e04e75e3843937637711b991a4ae9 (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
# frozen_string_literal: true

module API
  module Entities
    class GroupDetail < Group
      expose :shared_with_groups do |group, options|
        SharedGroupWithGroup.represent(group.shared_with_group_links_visible_to_user(options[:current_user]))
      end
      expose :runners_token, if: ->(_, options) { options[:user_can_admin_group] }
      expose :enabled_git_access_protocol, if: ->(group, options) { group.root? && options[:user_can_admin_group] }
      expose :prevent_sharing_groups_outside_hierarchy,
        if: ->(group) { group.root? && group.namespace_settings.present? }

      expose :projects,
        if: ->(_, options) { options[:with_projects] },
        using: Entities::Project do |group, options|
        projects = GroupProjectsFinder.new(
          group: group,
          current_user: options[:current_user],
          options: { exclude_shared: true, limit: projects_limit }
        ).execute

        Entities::Project.prepare_relation(projects, options)
      end

      expose :shared_projects,
        if: ->(_, options) { options[:with_projects] },
        using: Entities::Project do |group, options|
        projects = GroupProjectsFinder.new(
          group: group,
          current_user: options[:current_user],
          options: { only_shared: true, limit: projects_limit }
        ).execute

        Entities::Project.prepare_relation(projects, options)
      end

      def projects_limit
        GroupProjectsFinder::DEFAULT_PROJECTS_LIMIT
      end
    end
  end
end

API::Entities::GroupDetail.prepend_mod_with('API::Entities::GroupDetail')