mirror of https://github.com/zulip/zulip.git
push_notifications: Fix mypy annotation logic around push tokens.
I'm not 100% confident this is long-term correct, but at least it's consistent.
This commit is contained in:
parent
919c610abf
commit
d6e0960ca2
|
@ -393,7 +393,7 @@ def send_notifications_to_bouncer(user_profile_id, apns_payload, gcm_payload):
|
|||
send_json_to_push_bouncer('POST', 'notify', post_data)
|
||||
|
||||
def add_push_device_token(user_profile, token_str, kind, ios_app_id=None):
|
||||
# type: (UserProfile, str, int, Optional[str]) -> None
|
||||
# type: (UserProfile, bytes, int, Optional[str]) -> None
|
||||
|
||||
# If we're sending things to the push notification bouncer
|
||||
# register this user with them here
|
||||
|
@ -426,7 +426,7 @@ def add_push_device_token(user_profile, token_str, kind, ios_app_id=None):
|
|||
token.save(update_fields=['last_updated'])
|
||||
|
||||
def remove_push_device_token(user_profile, token_str, kind):
|
||||
# type: (UserProfile, str, int) -> None
|
||||
# type: (UserProfile, bytes, int) -> None
|
||||
|
||||
# If we're sending things to the push notification bouncer
|
||||
# register this user with them here
|
||||
|
|
|
@ -17,7 +17,7 @@ from zerver.lib.validator import check_string, check_list, check_bool
|
|||
from zerver.models import PushDeviceToken, UserProfile
|
||||
|
||||
def validate_token(token_str, kind):
|
||||
# type: (str, int) -> None
|
||||
# type: (bytes, int) -> None
|
||||
if token_str == '' or len(token_str) > 4096:
|
||||
raise JsonableError(_('Empty or invalid length token'))
|
||||
if kind == PushDeviceToken.APNS:
|
||||
|
@ -30,28 +30,28 @@ def validate_token(token_str, kind):
|
|||
@has_request_variables
|
||||
def add_apns_device_token(request, user_profile, token=REQ(),
|
||||
appid=REQ(default=settings.ZULIP_IOS_APP_ID)):
|
||||
# type: (HttpRequest, UserProfile, str, str) -> HttpResponse
|
||||
# type: (HttpRequest, UserProfile, bytes, str) -> HttpResponse
|
||||
validate_token(token, PushDeviceToken.APNS)
|
||||
add_push_device_token(user_profile, token, PushDeviceToken.APNS, ios_app_id=appid)
|
||||
return json_success()
|
||||
|
||||
@has_request_variables
|
||||
def add_android_reg_id(request, user_profile, token=REQ()):
|
||||
# type: (HttpRequest, UserProfile, str) -> HttpResponse
|
||||
# type: (HttpRequest, UserProfile, bytes) -> HttpResponse
|
||||
validate_token(token, PushDeviceToken.GCM)
|
||||
add_push_device_token(user_profile, token, PushDeviceToken.GCM)
|
||||
return json_success()
|
||||
|
||||
@has_request_variables
|
||||
def remove_apns_device_token(request, user_profile, token=REQ()):
|
||||
# type: (HttpRequest, UserProfile, str) -> HttpResponse
|
||||
# type: (HttpRequest, UserProfile, bytes) -> HttpResponse
|
||||
validate_token(token, PushDeviceToken.APNS)
|
||||
remove_push_device_token(user_profile, token, PushDeviceToken.APNS)
|
||||
return json_success()
|
||||
|
||||
@has_request_variables
|
||||
def remove_android_reg_id(request, user_profile, token=REQ()):
|
||||
# type: (HttpRequest, UserProfile, str) -> HttpResponse
|
||||
# type: (HttpRequest, UserProfile, bytes) -> HttpResponse
|
||||
validate_token(token, PushDeviceToken.GCM)
|
||||
remove_push_device_token(user_profile, token, PushDeviceToken.GCM)
|
||||
return json_success()
|
||||
|
|
|
@ -24,7 +24,7 @@ def validate_entity(entity):
|
|||
raise JsonableError(_("Must validate with valid Zulip server API key"))
|
||||
|
||||
def validate_bouncer_token_request(entity, token, kind):
|
||||
# type: (Union[UserProfile, RemoteZulipServer], str, int) -> None
|
||||
# type: (Union[UserProfile, RemoteZulipServer], bytes, int) -> None
|
||||
if kind not in [RemotePushDeviceToken.APNS, RemotePushDeviceToken.GCM]:
|
||||
raise JsonableError(_("Invalid token type"))
|
||||
validate_entity(entity)
|
||||
|
@ -38,7 +38,7 @@ def report_error(request, deployment, type=REQ(), report=REQ(validator=check_dic
|
|||
@has_request_variables
|
||||
def remote_server_register_push(request, entity, user_id=REQ(),
|
||||
token=REQ(), token_kind=REQ(validator=check_int), ios_app_id=None):
|
||||
# type: (HttpRequest, Union[UserProfile, RemoteZulipServer], int, str, int, Optional[Text]) -> HttpResponse
|
||||
# type: (HttpRequest, Union[UserProfile, RemoteZulipServer], int, bytes, int, Optional[Text]) -> HttpResponse
|
||||
validate_bouncer_token_request(entity, token, token_kind)
|
||||
server = cast(RemoteZulipServer, entity)
|
||||
|
||||
|
@ -63,7 +63,7 @@ def remote_server_register_push(request, entity, user_id=REQ(),
|
|||
@has_request_variables
|
||||
def remote_server_unregister_push(request, entity, token=REQ(),
|
||||
token_kind=REQ(validator=check_int), ios_app_id=None):
|
||||
# type: (HttpRequest, Union[UserProfile, RemoteZulipServer], str, int, Optional[Text]) -> HttpResponse
|
||||
# type: (HttpRequest, Union[UserProfile, RemoteZulipServer], bytes, int, Optional[Text]) -> HttpResponse
|
||||
validate_bouncer_token_request(entity, token, token_kind)
|
||||
server = cast(RemoteZulipServer, entity)
|
||||
deleted = RemotePushDeviceToken.objects.filter(token=token,
|
||||
|
|
Loading…
Reference in New Issue