def validate_uuid(uuid: str) -> None: try: uuid_object = UUID(uuid, version=4) # The UUID initialization under some circumstances will modify the uuid # string to create a valid UUIDv4, instead of raising a ValueError. # The submitted uuid needing to be modified means it's invalid, so # we need to check for that condition. if str(uuid_object) != uuid: raise ValidationError(err_("Invalid UUID")) except ValueError: raise ValidationError(err_("Invalid UUID"))
def validate_bouncer_token_request(entity: Union[UserProfile, RemoteZulipServer], token: bytes, kind: int) -> None: if kind not in [RemotePushDeviceToken.APNS, RemotePushDeviceToken.GCM]: raise JsonableError(err_("Invalid token type")) validate_entity(entity) validate_token(token, kind)
def unregister_remote_push_device(request: HttpRequest, entity: Union[UserProfile, RemoteZulipServer], token: bytes=REQ(), token_kind: int=REQ(validator=check_int), ios_app_id: Optional[str]=None) -> HttpResponse: validate_bouncer_token_request(entity, token, token_kind) server = cast(RemoteZulipServer, entity) deleted = RemotePushDeviceToken.objects.filter(token=token, kind=token_kind, server=server).delete() if deleted[0] == 0: return json_error(err_("Token does not exist")) return json_success()
def unregister_remote_push_device(request: HttpRequest, entity: Union[UserProfile, RemoteZulipServer], token: bytes=REQ(), token_kind: int=REQ(validator=check_int), ios_app_id: Optional[str]=None) -> HttpResponse: validate_bouncer_token_request(entity, token, token_kind) server = cast(RemoteZulipServer, entity) deleted = RemotePushDeviceToken.objects.filter(token=token, kind=token_kind, server=server).delete() if deleted[0] == 0: return json_error(err_("Token does not exist")) return json_success()
def unregister_remote_push_device( request: HttpRequest, entity: Union[UserProfile, RemoteZulipServer], token: str = REQ(), token_kind: int = REQ(json_validator=check_int), user_id: Optional[int] = REQ(json_validator=check_int, default=None), user_uuid: Optional[str] = REQ(default=None), ios_app_id: Optional[str] = None, ) -> HttpResponse: server = validate_bouncer_token_request(entity, token, token_kind) user_identity = UserPushIndentityCompat(user_id=user_id, user_uuid=user_uuid) deleted = RemotePushDeviceToken.objects.filter(user_identity.filter_q(), token=token, kind=token_kind, server=server).delete() if deleted[0] == 0: raise JsonableError(err_("Token does not exist")) return json_success(request)
def validate_bouncer_token_request(entity: Union[UserProfile, RemoteZulipServer], token: bytes, kind: int) -> None: if kind not in [RemotePushDeviceToken.APNS, RemotePushDeviceToken.GCM]: raise JsonableError(err_("Invalid token type")) validate_entity(entity) validate_token(token, kind)
def validate_entity(entity: Union[UserProfile, RemoteZulipServer]) -> None: if not isinstance(entity, RemoteZulipServer): raise JsonableError(err_("Must validate with valid Zulip server API key"))
def validate_entity(entity: Union[UserProfile, RemoteZulipServer]) -> None: if not isinstance(entity, RemoteZulipServer): raise JsonableError( err_("Must validate with valid Zulip server API key"))