Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
invites: Validation error instead of DB exception on overflowed SMALLINT.
Josh Klarebc6ab4744ca
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 8a39c7d275f..3bd0e44da11 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -3220,6 +3220,17 @@ class MultiuseInviteTest(ZulipTestCase):)self.assert_json_error(result, "Invalid stream ID 54321. No invites were sent.")+ def test_create_multiuse_link_invalid_invite_as_api_call(self) -> None:+ self.login("iago")+ result = self.client_post(+ "/json/invites/multiuse",+ {+ "invite_as": orjson.dumps(PreregistrationUser.INVITE_AS["GUEST_USER"] + 1).decode(),+ "invite_expires_in_minutes": 2 * 24 * 60,+ },+ )+ self.assert_json_error(result, "Invalid invite_as")+class EmailUnsubscribeTests(ZulipTestCase):def test_error_unsubscribe(self) -> None:diff --git a/zerver/views/invite.py b/zerver/views/invite.pyindex 9a175832866..c06df847c7b 100644--- a/zerver/views/invite.py+++ b/zerver/views/invite.py@@ -19,7 +19,7 @@ from zerver.lib.exceptions import JsonableError, OrganizationOwnerRequiredErrorfrom zerver.lib.request import REQ, has_request_variablesfrom zerver.lib.response import json_successfrom zerver.lib.streams import access_stream_by_id-from zerver.lib.validator import check_int, check_list, check_none_or+from zerver.lib.validator import check_int, check_int_in, check_list, check_none_orfrom zerver.models import MultiuseInvite, PreregistrationUser, Stream, UserProfile# Convert INVITATION_LINK_VALIDITY_DAYS into minutes.@@ -190,7 +190,12 @@ def generate_multiuse_invite_backend(invite_expires_in_minutes: Optional[int] = REQ(json_validator=check_none_or(check_int), default=INVITATION_LINK_VALIDITY_MINUTES),- invite_as: int = REQ(json_validator=check_int, default=PreregistrationUser.INVITE_AS["MEMBER"]),+ invite_as: int = REQ(+ json_validator=check_int_in(+ list(PreregistrationUser.INVITE_AS.values()),+ ),+ default=PreregistrationUser.INVITE_AS["MEMBER"],+ ),stream_ids: Sequence[int] = REQ(json_validator=check_list(check_int), default=[]),) -> HttpResponse:check_if_owner_required(invite_as, user_profile)