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

@@ -535,19 +535,24 @@ class InviteUserTest(InviteUserBase):
result = self.invite(self.nonreg_email("alice"), ["Denmark"])
self.assert_json_success(result)
ledger.licenses_at_next_renewal = 5
ledger.licenses_at_next_renewal = get_latest_seat_count(user.realm)
ledger.save(update_fields=["licenses_at_next_renewal"])
with self.settings(BILLING_ENABLED=True):
result = self.invite(self.nonreg_email("bob"), ["Denmark"])
self.assert_json_success(result)
self.assert_json_error_contains(
result,
"Your organization does not have enough Zulip licenses. Invitations were not sent.",
)
ledger.licenses_at_next_renewal = 50
ledger.licenses = get_latest_seat_count(user.realm) + 1
ledger.save(update_fields=["licenses"])
ledger.save(update_fields=["licenses", "licenses_at_next_renewal"])
with self.settings(BILLING_ENABLED=True):
invitee_emails = self.nonreg_email("bob") + "," + self.nonreg_email("alice")
result = self.invite(invitee_emails, ["Denmark"])
self.assert_json_error_contains(
result, "Your organization does not have enough unused Zulip licenses to invite 2 users"
result,
"Your organization does not have enough Zulip licenses. Invitations were not sent.",
)
ledger.licenses = get_latest_seat_count(user.realm)
@@ -555,7 +560,8 @@ class InviteUserTest(InviteUserBase):
with self.settings(BILLING_ENABLED=True):
result = self.invite(self.nonreg_email("bob"), ["Denmark"])
self.assert_json_error_contains(
result, "All Zulip licenses for this organization are currently in use"
result,
"Your organization does not have enough Zulip licenses. Invitations were not sent.",
)
with self.settings(BILLING_ENABLED=True):