Commit 17b5fb7a authored by Mark Chao's avatar Mark Chao

Merge branch 'rp/namespace-list-max-seats-used' into 'master'

Return max_seats_used in namespaces list API

See merge request gitlab-org/gitlab!42644
parents f3e4692f 462a1f91
......@@ -87,6 +87,23 @@ the `plan` parameter associated with a namespace:
]
```
Users on GitLab.com will also see a `max_seats_used` parameter. `max_seats_used`
is the highest number of users the group had.
`max_seats_used` will be non-zero only for namespaces on paid plans.
```json
[
{
"id": 1,
"name": "user1",
"billable_members_count": 2,
"max_seats_used": 3,
...
}
]
```
NOTE: **Note:**
Only group maintainers/owners are presented with `members_count_with_descendants`, as well as `plan` **(BRONZE ONLY)**.
......@@ -123,6 +140,7 @@ Example response:
"web_url": "https://gitlab.example.com/groups/twitter",
"members_count_with_descendants": 2,
"billable_members_count": 2,
"max_seats_used": 0,
"plan": "default",
"trial_ends_on": null,
"trial": false
......@@ -162,6 +180,7 @@ Example response:
"web_url": "https://gitlab.example.com/groups/group1",
"members_count_with_descendants": 2,
"billable_members_count": 2,
"max_seats_used": 0,
"plan": "default",
"trial_ends_on": null,
"trial": false
......@@ -188,6 +207,7 @@ Example response:
"web_url": "https://gitlab.example.com/groups/group1",
"members_count_with_descendants": 2,
"billable_members_count": 2,
"max_seats_used": 0,
"plan": "default",
"trial_ends_on": null,
"trial": false
......
---
title: Return max_seats_used in namespaces list API
merge_request: 42644
author:
type: changed
......@@ -9,6 +9,7 @@ module EE
prepended do
can_update_limits = ->(namespace, opts) { ::Ability.allowed?(opts[:current_user], :update_subscription_limit, namespace) }
can_admin_namespace = ->(namespace, opts) { ::Ability.allowed?(opts[:current_user], :admin_namespace, namespace) }
has_gitlab_subscription = ->(namespace) { namespace.gitlab_subscription.present? }
expose :shared_runners_minutes_limit, if: can_update_limits
expose :extra_shared_runners_minutes_limit, if: can_update_limits
......@@ -17,6 +18,9 @@ module EE
expose :billable_members_count do |namespace, options|
namespace.billable_members_count(options[:requested_hosted_plan])
end
expose :max_seats_used, if: has_gitlab_subscription do |namespace, _|
namespace.gitlab_subscription.max_seats_used
end
expose :plan, if: can_admin_namespace do |namespace, _|
namespace.actual_plan_name
end
......
......@@ -5,9 +5,10 @@ require 'spec_helper'
RSpec.describe API::Namespaces do
let(:admin) { create(:admin) }
let(:user) { create(:user) }
let!(:group1) { create(:group, name: 'test.test-group.2') }
let!(:group2) { create(:group, :nested) }
let!(:gold_plan) { create(:gold_plan) }
let_it_be(:group1, reload: true) { create(:group, name: 'test.test-group.2') }
let_it_be(:group2) { create(:group, :nested) }
let_it_be(:gold_plan) { create(:gold_plan) }
describe "GET /namespaces" do
context "when authenticated as admin" do
......@@ -114,6 +115,30 @@ RSpec.describe API::Namespaces do
end
end
end
context 'with gitlab subscription' do
before do
group1.add_guest(user)
create(:gitlab_subscription, namespace: group1, max_seats_used: 1)
end
it 'includes max_seats_used' do
get api("/namespaces", user)
expect(json_response.first['max_seats_used']).to eq(1)
end
end
context 'without gitlab subscription' do
it 'does not include max_seats_used' do
get api("/namespaces", user)
json_response.each do |resp|
expect(resp.keys).not_to include('max_seats_used')
end
end
end
end
describe 'PUT /namespaces/:id' do
......
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