From bd4c2847f4a60b392902aa1866c1ccc87cfacbf6 Mon Sep 17 00:00:00 2001 From: Oswaldo Ferreira Date: Wed, 28 Jun 2017 17:27:01 -0300 Subject: Rename members_count to members_count_with_descendants and expose only to group admins --- lib/api/entities.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/api/entities.rb') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 2fe5280bc1c..cef5a0abe12 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -446,8 +446,12 @@ module API class Namespace < Grape::Entity expose :id, :name, :path, :kind, :full_path, :parent_id - expose :members_count do |namespace, _| - namespace.users_with_descendants.count if namespace.kind == 'group' + 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 -- cgit v1.2.1