Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
invites: Update error message when max limit for the day is reached.
Sahil Batrae6106cb33463
diff --git a/static/js/invite.js b/static/js/invite.jsindex ab3a613e0dc..a6c7dbf3c9c 100644--- a/static/js/invite.js+++ b/static/js/invite.js@@ -109,6 +109,7 @@ function submit_invitation_form() {is_invitee_deactivated,license_limit_reached: arr.license_limit_reached,has_billing_access: page_params.is_owner || page_params.is_billing_admin,+ daily_limit_reached: arr.daily_limit_reached,});ui_report.message(error_response, invite_status, "alert-warning");invitee_emails_group.addClass("warning");diff --git a/static/templates/invitation_failed_error.hbs b/static/templates/invitation_failed_error.hbsindex 126c53a6a19..1df7eba4b94 100644--- a/static/templates/invitation_failed_error.hbs+++ b/static/templates/invitation_failed_error.hbs@@ -1,4 +1,11 @@<p id="invitation_error_message">{{ error_message }}</p>+{{#if daily_limit_reached}}+ {{#tr}}+ Please <z-link-support>contact support</z-link-support> for an exception or <z-link-invite-help>add users with a reusable invite link</z-link-invite-help>.+ {{#*inline "z-link-support"}}<a href="https://zulip.com/help/contact-support">{{> @partial-block}}</a>{{/inline}}+ {{#*inline "z-link-invite-help"}}<a href="https://zulip.com/help/invite-new-users#send-invitations">{{> @partial-block}}</a>{{/inline}}+ {{/tr}}+{{/if}}<ul>{{#each error_list}}<li>{{this}}</li>diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex 23cca14175f..b9476a3f0e5 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -7021,16 +7021,19 @@ def estimate_recent_invites(realms: Collection[Realm], *, days: int) -> int:def check_invite_limit(realm: Realm, num_invitees: int) -> None:"""Discourage using invitation emails as a vector for carrying spam."""msg = _(- "You do not have enough remaining invites for today. "- "Please contact {email} to have your limit raised. "- "No invitations were sent."- ).format(email=settings.ZULIP_ADMINISTRATOR)+ "To protect users, Zulip limits the number of invitations you can send in one day. Because you have reached the limit, no invitations were sent."+ )if not settings.OPEN_REALM_CREATION:returnrecent_invites = estimate_recent_invites([realm], days=1)if num_invitees + recent_invites > realm.max_invites:- raise InvitationError(msg, [], sent_invitations=False)+ raise InvitationError(+ msg,+ [],+ sent_invitations=False,+ daily_limit_reached=True,+ )default_max = settings.INVITES_DEFAULT_REALM_DAILY_MAXnewrealm_age = datetime.timedelta(days=settings.INVITES_NEW_REALM_DAYS)@@ -7053,7 +7056,12 @@ def check_invite_limit(realm: Realm, num_invitees: int) -> None:for days, count in settings.INVITES_NEW_REALM_LIMIT_DAYS:recent_invites = estimate_recent_invites(new_realms, days=days)if num_invitees + recent_invites > count:- raise InvitationError(msg, [], sent_invitations=False)+ raise InvitationError(+ msg,+ [],+ sent_invitations=False,+ daily_limit_reached=True,+ )def do_invite_users(diff --git a/zerver/lib/exceptions.py b/zerver/lib/exceptions.pyindex 8a3d3775784..74598f301b9 100644--- a/zerver/lib/exceptions.py+++ b/zerver/lib/exceptions.py@@ -360,7 +360,12 @@ class ZephyrMessageAlreadySentException(Exception):class InvitationError(JsonableError):code = ErrorCode.INVITATION_FAILED- data_fields = ["errors", "sent_invitations", "license_limit_reached"]+ data_fields = [+ "errors",+ "sent_invitations",+ "license_limit_reached",+ "daily_limit_reached",+ ]def __init__(self,@@ -368,11 +373,13 @@ class InvitationError(JsonableError):errors: List[Tuple[str, str, bool]],sent_invitations: bool,license_limit_reached: bool = False,+ daily_limit_reached: bool = False,) -> None:self._msg: str = msgself.errors: List[Tuple[str, str, bool]] = errorsself.sent_invitations: bool = sent_invitationsself.license_limit_reached: bool = license_limit_reached+ self.daily_limit_reached: bool = daily_limit_reachedclass AccessDeniedError(JsonableError):diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 03b83ba79d0..7b18da6daf7 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -1123,7 +1123,7 @@ class InviteUserTest(InviteUserBase):return resultresult = try_invite()- self.assert_json_error_contains(result, "enough remaining invites")+ self.assert_json_error_contains(result, "reached the limit")# Next show that aggregate limits expire once the realm is old# enough.@@ -1624,9 +1624,7 @@ [email protected]""",invitee_emails = ", ".join(str(i) for i in range(get_realm("zulip").max_invites - 1))self.assert_json_error(self.invite(invitee_emails, ["Denmark"]),- "You do not have enough remaining invites for today. "- "Please contact [email protected] to have your limit raised. "- "No invitations were sent.",+ "To protect users, Zulip limits the number of invitations you can send in one day. Because you have reached the limit, no invitations were sent.",)def test_missing_or_invalid_params(self) -> None: