billing: Enforce manual billing renewal licenses for new users.

In addition to checking for available licenses in the current
billing period when adding or inviting new non-guest users, for
manual billing, we also verify that the number of licenses set
for the next billing period will be enough when adding/inviting
new users.

Realms that are exempt from license number checks do not have
this restriction applied.

Admins are notified via group direct message when a user fails
to register due to this restriction.
This commit is contained in:
Lauryn Menard
2024-09-05 20:16:54 +02:00
committed by Tim Abbott
parent 73cb08265c
commit 7861c1ba63
3 changed files with 45 additions and 20 deletions

View File

@@ -3026,7 +3026,7 @@ class UserSignUpTest(ZulipTestCase):
last_message = Message.objects.last()
assert last_message is not None
self.assertIn(
f"A new member ({self.nonreg_email('test')}) was unable to join your organization because all Zulip",
f"A new user ({self.nonreg_email('test')}) was unable to join because your organization",
last_message.content,
)
self.assertEqual(
@@ -3044,7 +3044,27 @@ class UserSignUpTest(ZulipTestCase):
)
ledger.licenses = 50
ledger.save(update_fields=["licenses"])
ledger.licenses_at_next_renewal = 5
ledger.save(update_fields=["licenses", "licenses_at_next_renewal"])
with self.settings(BILLING_ENABLED=True):
form = HomepageForm({"email": self.nonreg_email("test")}, realm=realm)
self.assertIn(
"New members cannot join this organization because all Zulip licenses",
form.errors["email"][0],
)
last_message = Message.objects.last()
assert last_message is not None
self.assertIn(
f"A new user ({self.nonreg_email('test')}) was unable to join because your organization",
last_message.content,
)
self.assertEqual(
set(get_direct_message_group_user_ids(last_message.recipient)),
expected_group_direct_message_user_ids,
)
ledger.licenses_at_next_renewal = 50
ledger.save(update_fields=["licenses_at_next_renewal"])
with self.settings(BILLING_ENABLED=True):
form = HomepageForm({"email": self.nonreg_email("test")}, realm=realm)
self.assertEqual(form.errors, {})