mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	invites: Validation error instead of DB exception on overflowed SMALLINT.
If `invite_as` is passed as a number outside the range of a PostgreSQL `SMALLINT` field, the database throws an exception. Move this exception to the glass as a validation error to allow better client-side error handling and reduce database round-trips.
This commit is contained in:
		@@ -3220,6 +3220,17 @@ class MultiuseInviteTest(ZulipTestCase):
 | 
				
			|||||||
        )
 | 
					        )
 | 
				
			||||||
        self.assert_json_error(result, "Invalid stream ID 54321. No invites were sent.")
 | 
					        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):
 | 
					class EmailUnsubscribeTests(ZulipTestCase):
 | 
				
			||||||
    def test_error_unsubscribe(self) -> None:
 | 
					    def test_error_unsubscribe(self) -> None:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,7 @@ from zerver.lib.exceptions import JsonableError, OrganizationOwnerRequiredError
 | 
				
			|||||||
from zerver.lib.request import REQ, has_request_variables
 | 
					from zerver.lib.request import REQ, has_request_variables
 | 
				
			||||||
from zerver.lib.response import json_success
 | 
					from zerver.lib.response import json_success
 | 
				
			||||||
from zerver.lib.streams import access_stream_by_id
 | 
					from 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_or
 | 
				
			||||||
from zerver.models import MultiuseInvite, PreregistrationUser, Stream, UserProfile
 | 
					from zerver.models import MultiuseInvite, PreregistrationUser, Stream, UserProfile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Convert INVITATION_LINK_VALIDITY_DAYS into minutes.
 | 
					# Convert INVITATION_LINK_VALIDITY_DAYS into minutes.
 | 
				
			||||||
@@ -190,7 +190,12 @@ def generate_multiuse_invite_backend(
 | 
				
			|||||||
    invite_expires_in_minutes: Optional[int] = REQ(
 | 
					    invite_expires_in_minutes: Optional[int] = REQ(
 | 
				
			||||||
        json_validator=check_none_or(check_int), default=INVITATION_LINK_VALIDITY_MINUTES
 | 
					        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=[]),
 | 
					    stream_ids: Sequence[int] = REQ(json_validator=check_list(check_int), default=[]),
 | 
				
			||||||
) -> HttpResponse:
 | 
					) -> HttpResponse:
 | 
				
			||||||
    check_if_owner_required(invite_as, user_profile)
 | 
					    check_if_owner_required(invite_as, user_profile)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user