diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-06-29 13:04:13 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-06-29 13:04:13 +0000 |
commit | 46def2045ec8ca560a7ba04cef3feac42c52e6cb (patch) | |
tree | 372da4d4a9a4ed0022a08fb3e4d716867be3ff8d /lib/api | |
parent | 572fa2cb0263b87b5323ebb0d72bc71fa252df78 (diff) | |
parent | e8ebad15e3d6f5ddbe3596a6616aafec95725261 (diff) | |
download | gitlab-ce-46def2045ec8ca560a7ba04cef3feac42c52e6cb.tar.gz |
Merge branch 'add-members-count-and-parent-id-data-on-namespaces-api' into 'master'
Add group members counting related data on namespaces API
See merge request !12497
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/entities.rb | 10 | ||||
-rw-r--r-- | lib/api/namespaces.rb | 2 |
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index aa91451c9f4..cef5a0abe12 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -444,7 +444,15 @@ module API end class Namespace < Grape::Entity - expose :id, :name, :path, :kind, :full_path + expose :id, :name, :path, :kind, :full_path, :parent_id + + 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 class MemberAccess < Grape::Entity diff --git a/lib/api/namespaces.rb b/lib/api/namespaces.rb index 30761cb9b55..f1eaff6b0eb 100644 --- a/lib/api/namespaces.rb +++ b/lib/api/namespaces.rb @@ -17,7 +17,7 @@ module API namespaces = namespaces.search(params[:search]) if params[:search].present? - present paginate(namespaces), with: Entities::Namespace + present paginate(namespaces), with: Entities::Namespace, current_user: current_user end end end |