Commit a0f9e4d6 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Add members_count and parent_id info on /namespaces API

parent 9c50fa7c
......@@ -29,18 +29,27 @@ Example response:
{
"id": 1,
"path": "user1",
"kind": "user"
"kind": "user",
"full_path": "user1",
"parent_id": "null",
"members_count": "null"
},
{
"id": 2,
"path": "group1",
"kind": "group"
"full_path": "group1",
"parent_id": "null",
"members_count": 2
},
{
"id": 3,
"path": "bar",
"kind": "group",
"full_path": "foo/bar",
"parent_id": "9",
"members_count": 5
},
}
]
```
......@@ -72,6 +81,8 @@ Example response:
"path": "twitter",
"kind": "group",
"full_path": "twitter",
"parent_id": "null",
"members_count": 2
}
]
```
......@@ -513,6 +513,11 @@ module API
expose :id, :name, :path, :kind, :full_path
# EE-only
expose :parent_id
expose :members_count do |namespace, _|
namespace.users_with_descendants.count if namespace.kind == 'group'
end
expose :shared_runners_minutes_limit, if: lambda { |_, options| options[:current_user]&.admin? }
expose :plan, if: lambda { |_, options| options[:current_user]&.admin? }
end
......
......@@ -15,6 +15,14 @@ describe API::Namespaces do
end
context "when authenticated as admin" do
it "returns correct attributes" do
get api("/namespaces", admin)
expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response.first).to include('id', 'name', 'path', 'full_path', 'parent_id', 'members_count')
end
it "admin: returns an array of all namespaces" do
get api("/namespaces", admin)
......@@ -37,6 +45,14 @@ describe API::Namespaces do
end
context "when authenticated as a regular user" do
it "returns correct attributes" do
get api("/namespaces", user)
expect(response).to have_http_status(200)
expect(response).to include_pagination_headers
expect(json_response.first).to include('id', 'name', 'path', 'full_path', 'parent_id', 'members_count')
end
it "user: returns an array of namespaces" do
get api("/namespaces", user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment