Commit d7bea09c authored by rpereira2's avatar rpereira2

Return max_seats_used in namespaces list API

If a namespace has a GitLab subscription, return the subscription's
max_seats_used value.
parent 58f318e0
---
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