Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
billing: Allow exempt_from_license_number_check any number of licenses.
Mateusz Manderaef42065cec63
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex 97a6a4e58d8..c2a65d60925 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -95,14 +95,19 @@ def unsign_string(signed_string: str, salt: str) -> str:return signer.unsign(signed_string)-def validate_licenses(charge_automatically: bool, licenses: Optional[int], seat_count: int) -> None:+def validate_licenses(+ charge_automatically: bool,+ licenses: Optional[int],+ seat_count: int,+ exempt_from_license_number_check: bool,+) -> None:min_licenses = seat_countmax_licenses = Noneif not charge_automatically:min_licenses = max(seat_count, MIN_INVOICED_LICENSES)max_licenses = MAX_INVOICED_LICENSES- if licenses is None or licenses < min_licenses:+ if licenses is None or (not exempt_from_license_number_check and licenses < min_licenses):raise BillingError("not enough licenses", _("You must invoice for at least {} users.").format(min_licenses))diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.pyindex 80658942a5c..34d5c153f84 100644--- a/corporate/tests/test_stripe.py+++ b/corporate/tests/test_stripe.py@@ -2061,6 +2061,14 @@ class StripeTest(StripeTestCase):# Invoicecheck_success(True, MAX_INVOICED_LICENSES)+ # By default, an organization on a "Pay by card" plan with Manual license+ # management cannot purchase less licenses than the current seat count.+ # If exempt_from_license_number_check is enabled, they should be able to though.+ customer = Customer.objects.get_or_create(realm=hamlet.realm)[0]+ customer.exempt_from_license_number_check = True+ customer.save()+ check_success(False, self.seat_count - 1, {"license_management": "manual"})+def test_upgrade_with_uncaught_exception(self) -> None:hamlet = self.example_user("hamlet")self.login_user(hamlet)diff --git a/corporate/views/billing_page.py b/corporate/views/billing_page.pyindex 214928e348d..2cf85d1f781 100644--- a/corporate/views/billing_page.py+++ b/corporate/views/billing_page.py@@ -237,7 +237,12 @@ def update_plan(licenses=licenses))- validate_licenses(plan.charge_automatically, licenses, get_latest_seat_count(user.realm))+ validate_licenses(+ plan.charge_automatically,+ licenses,+ get_latest_seat_count(user.realm),+ plan.customer.exempt_from_license_number_check,+ )update_license_ledger_for_manual_plan(plan, timezone_now(), licenses=licenses)return json_success(request)@@ -258,6 +263,7 @@ def update_plan(plan.charge_automatically,licenses_at_next_renewal,get_latest_seat_count(user.realm),+ plan.customer.exempt_from_license_number_check,)update_license_ledger_for_manual_plan(plan, timezone_now(), licenses_at_next_renewal=licenses_at_next_renewaldiff --git a/corporate/views/upgrade.py b/corporate/views/upgrade.pyindex 958930f2da4..3f446995a0e 100644--- a/corporate/views/upgrade.py+++ b/corporate/views/upgrade.py@@ -65,6 +65,7 @@ def check_upgrade_parameters(license_management: Optional[str],licenses: Optional[int],seat_count: int,+ exempt_from_license_number_check: bool,) -> None:if billing_modality not in VALID_BILLING_MODALITY_VALUES: # nocoverageraise BillingError("unknown billing_modality", "")@@ -72,7 +73,12 @@ def check_upgrade_parameters(raise BillingError("unknown schedule")if license_management not in VALID_LICENSE_MANAGEMENT_VALUES: # nocoverageraise BillingError("unknown license_management")- validate_licenses(billing_modality == "charge_automatically", licenses, seat_count)+ validate_licenses(+ billing_modality == "charge_automatically",+ licenses,+ seat_count,+ exempt_from_license_number_check,+ )def setup_upgrade_checkout_session_and_payment_intent(@@ -171,8 +177,18 @@ def upgrade(if billing_modality == "send_invoice":schedule = "annual"license_management = "manual"++ customer = get_customer_by_realm(user.realm)+ exempt_from_license_number_check = (+ customer is not None and customer.exempt_from_license_number_check+ )check_upgrade_parameters(- billing_modality, schedule, license_management, licenses, seat_count+ billing_modality,+ schedule,+ license_management,+ licenses,+ seat_count,+ exempt_from_license_number_check,)assert licenses is not None and license_management is not Noneautomanage_licenses = license_management == "automatic"@@ -258,6 +274,10 @@ def initial_upgrade(if customer is not None and customer.default_discount is not None:percent_off = customer.default_discount+ exempt_from_license_number_check = (+ customer is not None and customer.exempt_from_license_number_check+ )+seat_count = get_latest_seat_count(user.realm)signed_seat_count, salt = sign_string(str(seat_count))context: Dict[str, Any] = {@@ -268,6 +288,7 @@ def initial_upgrade("salt": salt,"min_invoiced_licenses": max(seat_count, MIN_INVOICED_LICENSES),"default_invoice_days_until_due": DEFAULT_INVOICE_DAYS_UNTIL_DUE,+ "exempt_from_license_number_check": exempt_from_license_number_check,"plan": "Zulip Cloud Standard","free_trial_days": settings.FREE_TRIAL_DAYS,"onboarding": onboarding,diff --git a/templates/corporate/upgrade.html b/templates/corporate/upgrade.htmlindex de91bb249a1..5d51bfa1e64 100644--- a/templates/corporate/upgrade.html+++ b/templates/corporate/upgrade.html@@ -151,8 +151,8 @@{% endif %}</p>- <h4>Number of licenses (minimum {{ seat_count }})</h4>- <input type="number" name="licenses" min="{{ seat_count }}" autocomplete="off" id="manual_license_count" required/><br />+ <h4>Number of licenses {% if not exempt_from_license_number_check %}(minimum {{ seat_count }}){% endif %}</h4>+ <input type="number" name="licenses" {% if not exempt_from_license_number_check %}min="{{ seat_count }}"{% endif %} autocomplete="off" id="manual_license_count" required/><br /></div><!-- Disabled buttons do not fire any events, so we need a container div that isn't disabled for tippyjs to work --><div class="upgrade-button-container" {% if is_demo_organization %}data-tippy-content="{% trans %}Convert demo organization before upgrading.{% endtrans %}"{% endif %}>diff --git a/web/tests/upgrade.test.js b/web/tests/upgrade.test.jsindex f4a8e28a3f9..b345665ed23 100644--- a/web/tests/upgrade.test.js+++ b/web/tests/upgrade.test.js@@ -187,10 +187,6 @@ run_test("autopay_form_fields", () => {document.querySelector("#autopay-form #automatic_license_count").value,"{{ seat_count }}",);- assert.equal(- document.querySelector("#autopay-form #manual_license_count").min,- "{{ seat_count }}",- );const license_options = document.querySelectorAll("#autopay-form input[type=radio][name=license_management]",