summaryrefslogtreecommitdiff
path: root/lib/api/entities/namespace.rb
blob: a7e06cc3e020a4022d3b32f64f5559a258dfa9ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# frozen_string_literal: true

module API
  module Entities
    class Namespace < Entities::NamespaceBasic
      expose :members_count_with_descendants, if: -> (namespace, opts) { expose_members_count_with_descendants?(namespace, opts) } do |namespace, _|
        namespace.users_with_descendants.count
      end

      def expose_members_count_with_descendants?(namespace, opts)
        namespace.kind == 'group' && Ability.allowed?(opts[:current_user], :admin_group, namespace)
      end
    end
  end
end

API::Entities::Namespace.prepend_if_ee('EE::API::Entities::Namespace')