mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 01:16:19 +00:00
users: Avoid unchecked cast.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
086a3ef18b
commit
1e4fc8f2bf
@@ -10,7 +10,7 @@ ViewFuncT = TypeVar('ViewFuncT', bound=Callable[..., HttpResponse])
|
|||||||
ResultT = TypeVar("ResultT")
|
ResultT = TypeVar("ResultT")
|
||||||
Validator = Callable[[str, object], ResultT]
|
Validator = Callable[[str, object], ResultT]
|
||||||
ExtendedValidator = Callable[[str, str, object], str]
|
ExtendedValidator = Callable[[str, str, object], str]
|
||||||
RealmUserValidator = Callable[[int, List[int], bool], List[int]]
|
RealmUserValidator = Callable[[int, object, bool], List[int]]
|
||||||
|
|
||||||
class ProfileDataElementBase(TypedDict):
|
class ProfileDataElementBase(TypedDict):
|
||||||
id: int
|
id: int
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union, cast
|
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
@@ -269,7 +269,7 @@ def validate_user_custom_profile_field(realm_id: int, field: CustomProfileField,
|
|||||||
return choice_field_validator(var_name, field_data, value)
|
return choice_field_validator(var_name, field_data, value)
|
||||||
elif field_type == CustomProfileField.USER:
|
elif field_type == CustomProfileField.USER:
|
||||||
user_field_validator = CustomProfileField.USER_FIELD_VALIDATORS[field_type]
|
user_field_validator = CustomProfileField.USER_FIELD_VALIDATORS[field_type]
|
||||||
return user_field_validator(realm_id, cast(List[int], value), False)
|
return user_field_validator(realm_id, value, False)
|
||||||
else:
|
else:
|
||||||
raise AssertionError("Invalid field type")
|
raise AssertionError("Invalid field type")
|
||||||
|
|
||||||
|
|||||||
@@ -2754,9 +2754,9 @@ class UserHotspot(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ("user", "hotspot")
|
unique_together = ("user", "hotspot")
|
||||||
|
|
||||||
def check_valid_user_ids(realm_id: int, user_ids: List[int],
|
def check_valid_user_ids(realm_id: int, val: object,
|
||||||
allow_deactivated: bool=False) -> List[int]:
|
allow_deactivated: bool=False) -> List[int]:
|
||||||
check_list(check_int)("User IDs", user_ids)
|
user_ids = check_list(check_int)("User IDs", val)
|
||||||
realm = Realm.objects.get(id=realm_id)
|
realm = Realm.objects.get(id=realm_id)
|
||||||
for user_id in user_ids:
|
for user_id in user_ids:
|
||||||
# TODO: Structurally, we should be doing a bulk fetch query to
|
# TODO: Structurally, we should be doing a bulk fetch query to
|
||||||
|
|||||||
@@ -876,7 +876,7 @@ class UserProfileTest(ZulipTestCase):
|
|||||||
bot = self.example_user("default_bot")
|
bot = self.example_user("default_bot")
|
||||||
|
|
||||||
# Invalid user ID
|
# Invalid user ID
|
||||||
invalid_uid: Any = 1000
|
invalid_uid: object = 1000
|
||||||
with self.assertRaisesRegex(ValidationError, r"User IDs is not a list"):
|
with self.assertRaisesRegex(ValidationError, r"User IDs is not a list"):
|
||||||
check_valid_user_ids(realm.id, invalid_uid)
|
check_valid_user_ids(realm.id, invalid_uid)
|
||||||
with self.assertRaisesRegex(ValidationError, rf"Invalid user ID: {invalid_uid}"):
|
with self.assertRaisesRegex(ValidationError, rf"Invalid user ID: {invalid_uid}"):
|
||||||
|
|||||||
Reference in New Issue
Block a user