mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
invites: Use check_int_in to validate invite_as.
(cherry picked from commit ea9b05d88a)
This commit is contained in:
@@ -161,6 +161,11 @@ def check_int(var_name: str, val: object) -> int:
|
||||
|
||||
|
||||
def check_int_in(possible_values: List[int]) -> Validator[int]:
|
||||
"""
|
||||
Assert that the input is an integer and is contained in `possible_values`. If the input is not in
|
||||
`possible_values`, a `ValidationError` is raised containing the failing field's name.
|
||||
"""
|
||||
|
||||
def validator(var_name: str, val: object) -> int:
|
||||
n = check_int(var_name, val)
|
||||
if n not in possible_values:
|
||||
|
||||
@@ -1501,7 +1501,7 @@ class InviteUserTest(InviteUserBase):
|
||||
self.login("iago")
|
||||
invitee = self.nonreg_email("alice")
|
||||
response = self.invite(invitee, ["Denmark"], invite_as=10)
|
||||
self.assert_json_error(response, "Must be invited as an valid type of user")
|
||||
self.assert_json_error(response, "Invalid invite_as")
|
||||
|
||||
def test_successful_invite_user_as_guest_from_normal_account(self) -> None:
|
||||
self.login("hamlet")
|
||||
|
||||
@@ -46,7 +46,12 @@ def invite_users_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: List[int] = REQ(json_validator=check_list(check_int)),
|
||||
) -> HttpResponse:
|
||||
|
||||
@@ -54,8 +59,6 @@ def invite_users_backend(
|
||||
# Guest users case will not be handled here as it will
|
||||
# be handled by the decorator above.
|
||||
raise JsonableError(_("Insufficient permission"))
|
||||
if invite_as not in PreregistrationUser.INVITE_AS.values():
|
||||
raise JsonableError(_("Must be invited as an valid type of user"))
|
||||
check_if_owner_required(invite_as, user_profile)
|
||||
if (
|
||||
invite_as
|
||||
|
||||
Reference in New Issue
Block a user