Commit 7047e0ee authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'awaiting-member-subgroup-user-cap-reached' into 'master'

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

See merge request gitlab-org/gitlab!71507
parents 45eb2da6 30576e75
...@@ -475,12 +475,12 @@ module EE ...@@ -475,12 +475,12 @@ module EE
end end
def user_cap_reached?(requested_hosted_plan = nil) 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 user_cap = root_ancestor.namespace_settings&.new_user_signups_cap
return false unless user_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 end
private private
......
...@@ -143,7 +143,7 @@ module EE ...@@ -143,7 +143,7 @@ module EE
end end
def set_membership_activation 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 self.state = group.user_cap_reached? ? STATE_AWAITING : STATE_ACTIVE
end end
......
...@@ -1518,7 +1518,8 @@ RSpec.describe Group do ...@@ -1518,7 +1518,8 @@ RSpec.describe Group do
let(:new_user_signups_cap) { 100 } let(:new_user_signups_cap) { 100 }
before do 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 end
context 'when this cap is higher than the number of billable members' do context 'when this cap is higher than the number of billable members' do
......
...@@ -163,44 +163,48 @@ RSpec.describe Member, type: :model do ...@@ -163,44 +163,48 @@ RSpec.describe Member, type: :model do
end end
context 'check if user cap has been reached' do context 'check if user cap has been reached' do
let_it_be(:group) { create(:group_with_plan, plan: :ultimate_plan) } let_it_be(:group, refind: true) do
let_it_be(:project) { create(:project, namespace: group)} 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 context 'when the :saas_user_caps feature flag is disabled' do
before do before do
stub_feature_flags(saas_user_caps: false) stub_feature_flags(saas_user_caps: false)
end end
it 'leaves the group member state to created' do it 'sets the group member state to created' do
add_user_to_group group.add_developer(user)
expect(user.group_members.last).to be_created expect(user.group_members.last).to be_created
end end
it 'leaves the project member state to created' do it 'sets the project member state to created' do
project.add_developer(user) project.add_developer(user)
expect(user.project_members.last).to be_created expect(user.project_members.last).to be_created
end end
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 before do
stub_feature_flags(saas_user_caps: group) 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 end
context 'when the user cap for this group has not been reached' do context 'when the user cap has not been reached' do
let(:user_cap_reached) { false } before do
group.namespace_settings.update!(new_user_signups_cap: 10)
end
it 'sets the group member to active' do it 'sets the group member to active' do
add_user_to_group group.add_developer(user)
expect(user.group_members.last).to be_active expect(user.group_members.last).to be_active
end end
...@@ -212,11 +216,17 @@ RSpec.describe Member, type: :model do ...@@ -212,11 +216,17 @@ RSpec.describe Member, type: :model do
end end
end end
context 'when the user cap for this group has been reached' do context 'when the user cap has been reached' do
let(:user_cap_reached) { true }
it 'sets the group member to awaiting' 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 expect(user.group_members.last).to be_awaiting
end 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