Commit e6b01aa1 authored by Sean McGivern's avatar Sean McGivern

Merge branch '332590-expose-user-cap-calculation' into 'master'

Add `user_cap_reached?` to EE::Group

See merge request gitlab-org/gitlab!66264
parents 8a2b97f7 9e3ab675
......@@ -80,7 +80,7 @@ class Group < Namespace
# debian_distributions and associated component_files must be destroyed by ruby code in order to properly remove carrierwave uploads
has_many :debian_distributions, class_name: 'Packages::Debian::GroupDistribution', dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
delegate :prevent_sharing_groups_outside_hierarchy, to: :namespace_settings
delegate :prevent_sharing_groups_outside_hierarchy, :new_user_signups_cap, to: :namespace_settings
accepts_nested_attributes_for :variables, allow_destroy: true
......
......@@ -474,6 +474,13 @@ module EE
::Feature.enabled?(:iteration_cadences, self, default_enabled: :yaml)
end
def user_cap_reached?(requested_hosted_plan = nil)
return false unless ::Feature.enabled?(:saas_user_caps, self, default_enabled: :yaml)
return false unless new_user_signups_cap
new_user_signups_cap <= billable_members_count(requested_hosted_plan)
end
private
override :post_create_hook
......
---
name: saas_user_caps
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66264
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/336251
milestone: '14.1'
type: development
group: group::utilization
default_enabled: false
......@@ -1491,6 +1491,56 @@ RSpec.describe Group do
end
end
describe '#user_cap_reached?' do
let(:new_user_signups_cap) { nil }
before do
allow(group.namespace_settings).to receive(:new_user_signups_cap).and_return(new_user_signups_cap)
end
subject(:user_cap_reached_for_group?) { group.user_cap_reached? }
context 'when the :saas_user_caps feature flag is not enabled' do
it { is_expected.to be_falsey }
end
context 'when the :saas_user_caps feature flag is enabled' do
before do
stub_feature_flags(saas_user_caps: true)
end
context 'when no user cap has been set' do
it { is_expected.to be_falsey }
end
context 'when a user cap has been set' do
let(:new_user_signups_cap) { 100 }
before do
allow(group).to receive(:billable_members_count).and_return(billable_members_count)
end
context 'when this cap is higher than the number of billable members' do
let(:billable_members_count) { new_user_signups_cap - 10 }
it { is_expected.to be_falsey }
end
context 'when this cap is the same as the number of billable members' do
let(:billable_members_count) { new_user_signups_cap }
it { is_expected.to be_truthy }
end
context 'when this cap is lower than the number of billable members' do
let(:billable_members_count) { new_user_signups_cap + 10 }
it { is_expected.to be_truthy }
end
end
end
end
it_behaves_like 'can move repository storage' do
let_it_be(:container) { create(:group, :wiki_repo) }
......
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