Commit 30576e75 authored by Jason Goodman's avatar Jason Goodman Committed by Etienne Baqué

Set New Subgroup Members to Awaiting if Root Group User Cap Reached

parent 934fa18b
......@@ -475,12 +475,12 @@ module EE
end
def user_cap_reached?(requested_hosted_plan = nil)
return false unless ::Feature.enabled?(:saas_user_caps, self, default_enabled: :yaml)
return false unless ::Feature.enabled?(:saas_user_caps, root_ancestor, default_enabled: :yaml)
user_cap = root_ancestor.namespace_settings&.new_user_signups_cap
return false unless user_cap
user_cap <= billable_members_count(requested_hosted_plan)
user_cap <= root_ancestor.billable_members_count(requested_hosted_plan)
end
private
......
......@@ -143,7 +143,7 @@ module EE
end
def set_membership_activation
return unless group && ::Feature.enabled?(:saas_user_caps, group, default_enabled: :yaml)
return unless group && ::Feature.enabled?(:saas_user_caps, group.root_ancestor, default_enabled: :yaml)
self.state = group.user_cap_reached? ? STATE_AWAITING : STATE_ACTIVE
end
......
......@@ -1518,7 +1518,8 @@ RSpec.describe Group do
let(:new_user_signups_cap) { 100 }
before do
allow(group).to receive(:billable_members_count).and_return(billable_members_count)
allow(root_group).to receive(:billable_members_count).and_return(billable_members_count)
allow(group).to receive(:root_ancestor).and_return(root_group)
end
context 'when this cap is higher than the number of billable members' do
......
......@@ -163,44 +163,48 @@ RSpec.describe Member, type: :model do
end
context 'check if user cap has been reached' do
let_it_be(:group) { create(:group_with_plan, plan: :ultimate_plan) }
let_it_be(:project) { create(:project, namespace: group)}
let_it_be(:group, refind: true) do
create(:group_with_plan, plan: :ultimate_plan,
namespace_settings: create(:namespace_settings, new_user_signups_cap: 1))
end
let!(:user) { create(:user) }
let_it_be(:project, refind: true) { create(:project, namespace: group)}
let_it_be(:user) { create(:user) }
subject(:add_user_to_group) { group.add_developer(user) }
before_all do
group.add_developer(create(:user))
end
context 'when the :saas_user_caps feature flag is disabled' do
before do
stub_feature_flags(saas_user_caps: false)
end
it 'leaves the group member state to created' do
add_user_to_group
it 'sets the group member state to created' do
group.add_developer(user)
expect(user.group_members.last).to be_created
end
it 'leaves the project member state to created' do
it 'sets the project member state to created' do
project.add_developer(user)
expect(user.project_members.last).to be_created
end
end
context 'when the :saas_user_caps feature flag is enabled' do
context 'when the :saas_user_caps feature flag is enabled for the root group' do
before do
stub_feature_flags(saas_user_caps: group)
allow(project.group).to receive(:user_cap_reached?).and_return(user_cap_reached)
allow(group).to receive(:user_cap_reached?).and_return(user_cap_reached)
end
context 'when the user cap for this group has not been reached' do
let(:user_cap_reached) { false }
context 'when the user cap has not been reached' do
before do
group.namespace_settings.update!(new_user_signups_cap: 10)
end
it 'sets the group member to active' do
add_user_to_group
group.add_developer(user)
expect(user.group_members.last).to be_active
end
......@@ -212,11 +216,17 @@ RSpec.describe Member, type: :model do
end
end
context 'when the user cap for this group has been reached' do
let(:user_cap_reached) { true }
context 'when the user cap has been reached' do
it 'sets the group member to awaiting' do
add_user_to_group
group.add_developer(user)
expect(user.group_members.last).to be_awaiting
end
it 'sets the group member to awaiting when added to a subgroup' do
subgroup = create(:group, parent: group)
subgroup.add_developer(user)
expect(user.group_members.last).to be_awaiting
end
......
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