mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
zerver/views: Use python 3 syntax for typing.
This commit is contained in:
@@ -11,12 +11,10 @@ from zerver.lib.validator import check_list, check_string
|
|||||||
from zerver.lib.actions import do_add_alert_words, do_remove_alert_words
|
from zerver.lib.actions import do_add_alert_words, do_remove_alert_words
|
||||||
from zerver.lib.alert_words import user_alert_words
|
from zerver.lib.alert_words import user_alert_words
|
||||||
|
|
||||||
def list_alert_words(request, user_profile):
|
def list_alert_words(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile) -> HttpResponse
|
|
||||||
return json_success({'alert_words': user_alert_words(user_profile)})
|
return json_success({'alert_words': user_alert_words(user_profile)})
|
||||||
|
|
||||||
def clean_alert_words(alert_words):
|
def clean_alert_words(alert_words: List[Text]) -> List[Text]:
|
||||||
# type: (List[Text]) -> List[Text]
|
|
||||||
alert_words = [w.strip() for w in alert_words]
|
alert_words = [w.strip() for w in alert_words]
|
||||||
return [w for w in alert_words if w != ""]
|
return [w for w in alert_words if w != ""]
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ from typing import Any, List, Dict, Optional, Text
|
|||||||
from zerver.lib.response import json_error, json_success
|
from zerver.lib.response import json_error, json_success
|
||||||
from zerver.lib.user_agent import parse_user_agent
|
from zerver.lib.user_agent import parse_user_agent
|
||||||
|
|
||||||
def check_compatibility(request):
|
def check_compatibility(request: HttpRequest) -> HttpResponse:
|
||||||
# type: (HttpRequest) -> HttpResponse
|
|
||||||
user_agent = parse_user_agent(request.META["HTTP_USER_AGENT"])
|
user_agent = parse_user_agent(request.META["HTTP_USER_AGENT"])
|
||||||
if user_agent is None or user_agent['name'] == "ZulipInvalid":
|
if user_agent is None or user_agent['name'] == "ZulipInvalid":
|
||||||
return json_error("Client is too old")
|
return json_error("Client is too old")
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ from zerver.lib.validator import check_dict, check_list, check_int
|
|||||||
from zerver.models import (custom_profile_fields_for_realm, UserProfile,
|
from zerver.models import (custom_profile_fields_for_realm, UserProfile,
|
||||||
CustomProfileField, custom_profile_fields_for_realm)
|
CustomProfileField, custom_profile_fields_for_realm)
|
||||||
|
|
||||||
def list_realm_custom_profile_fields(request, user_profile):
|
def list_realm_custom_profile_fields(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile) -> HttpResponse
|
|
||||||
fields = custom_profile_fields_for_realm(user_profile.realm_id)
|
fields = custom_profile_fields_for_realm(user_profile.realm_id)
|
||||||
return json_success({'custom_fields': [f.as_dict() for f in fields]})
|
return json_success({'custom_fields': [f.as_dict() for f in fields]})
|
||||||
|
|
||||||
@@ -46,8 +45,8 @@ def create_realm_custom_profile_field(request, user_profile, name=REQ(),
|
|||||||
return json_error(_("A field with that name already exists."))
|
return json_error(_("A field with that name already exists."))
|
||||||
|
|
||||||
@require_realm_admin
|
@require_realm_admin
|
||||||
def delete_realm_custom_profile_field(request, user_profile, field_id):
|
def delete_realm_custom_profile_field(request: HttpRequest, user_profile: UserProfile,
|
||||||
# type: (HttpRequest, UserProfile, int) -> HttpResponse
|
field_id: int) -> HttpResponse:
|
||||||
try:
|
try:
|
||||||
field = CustomProfileField.objects.get(id=field_id)
|
field = CustomProfileField.objects.get(id=field_id)
|
||||||
except CustomProfileField.DoesNotExist:
|
except CustomProfileField.DoesNotExist:
|
||||||
@@ -59,9 +58,8 @@ def delete_realm_custom_profile_field(request, user_profile, field_id):
|
|||||||
|
|
||||||
@require_realm_admin
|
@require_realm_admin
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def update_realm_custom_profile_field(request, user_profile, field_id,
|
def update_realm_custom_profile_field(request: HttpRequest, user_profile: UserProfile,
|
||||||
name=REQ()):
|
field_id: int, name: Text=REQ()) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile, int, Text) -> HttpResponse
|
|
||||||
if not name.strip():
|
if not name.strip():
|
||||||
return json_error(_("Name cannot be blank."))
|
return json_error(_("Name cannot be blank."))
|
||||||
|
|
||||||
@@ -80,10 +78,10 @@ def update_realm_custom_profile_field(request, user_profile, field_id,
|
|||||||
@human_users_only
|
@human_users_only
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def update_user_custom_profile_data(
|
def update_user_custom_profile_data(
|
||||||
request,
|
request: HttpRequest,
|
||||||
user_profile,
|
user_profile: UserProfile,
|
||||||
data=REQ(validator=check_list(check_dict([('id', check_int)])))):
|
data: List[Dict[str, Union[int, Text]]]=REQ(validator=check_list(
|
||||||
# type: (HttpRequest, UserProfile, List[Dict[str, Union[int, Text]]]) -> HttpResponse
|
check_dict([('id', check_int)])))) -> HttpResponse:
|
||||||
for item in data:
|
for item in data:
|
||||||
field_id = item['id']
|
field_id = item['id']
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ from zerver.lib.response import json_success
|
|||||||
from zerver.lib.validator import check_string, check_list, check_bool
|
from zerver.lib.validator import check_string, check_list, check_bool
|
||||||
from zerver.models import Stream, UserProfile
|
from zerver.models import Stream, UserProfile
|
||||||
|
|
||||||
def _default_all_public_streams(user_profile, all_public_streams):
|
def _default_all_public_streams(user_profile: UserProfile,
|
||||||
# type: (UserProfile, Optional[bool]) -> bool
|
all_public_streams: Optional[bool]) -> bool:
|
||||||
if all_public_streams is not None:
|
if all_public_streams is not None:
|
||||||
return all_public_streams
|
return all_public_streams
|
||||||
else:
|
else:
|
||||||
return user_profile.default_all_public_streams
|
return user_profile.default_all_public_streams
|
||||||
|
|
||||||
def _default_narrow(user_profile, narrow):
|
def _default_narrow(user_profile: UserProfile,
|
||||||
# type: (UserProfile, Iterable[Sequence[Text]]) -> Iterable[Sequence[Text]]
|
narrow: Iterable[Sequence[Text]]) -> Iterable[Sequence[Text]]:
|
||||||
default_stream = user_profile.default_events_register_stream # type: Optional[Stream]
|
default_stream = user_profile.default_events_register_stream # type: Optional[Stream]
|
||||||
if not narrow and default_stream is not None:
|
if not narrow and default_stream is not None:
|
||||||
narrow = [['stream', default_stream.name]]
|
narrow = [['stream', default_stream.name]]
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ from zerver.models import UserProfile
|
|||||||
|
|
||||||
@human_users_only
|
@human_users_only
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def mark_hotspot_as_read(request, user, hotspot=REQ(validator=check_string)):
|
def mark_hotspot_as_read(request: HttpRequest, user: UserProfile,
|
||||||
# type: (HttpRequest, UserProfile, str) -> HttpResponse
|
hotspot: str=REQ(validator=check_string)) -> HttpResponse:
|
||||||
if hotspot not in ALL_HOTSPOTS:
|
if hotspot not in ALL_HOTSPOTS:
|
||||||
return json_error(_('Unknown hotspot: %s') % (hotspot,))
|
return json_error(_('Unknown hotspot: %s') % (hotspot,))
|
||||||
do_mark_hotspot_as_read(user, hotspot)
|
do_mark_hotspot_as_read(user, hotspot)
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ from zerver.lib.streams import access_stream_by_name, access_stream_for_unmute_t
|
|||||||
from zerver.lib.validator import check_string, check_list
|
from zerver.lib.validator import check_string, check_list
|
||||||
from zerver.models import get_stream, Stream, UserProfile
|
from zerver.models import get_stream, Stream, UserProfile
|
||||||
|
|
||||||
def mute_topic(user_profile, stream_name, topic_name):
|
def mute_topic(user_profile: UserProfile, stream_name: str,
|
||||||
# type: (UserProfile, str, str) -> HttpResponse
|
topic_name: str) -> HttpResponse:
|
||||||
(stream, recipient, sub) = access_stream_by_name(user_profile, stream_name)
|
(stream, recipient, sub) = access_stream_by_name(user_profile, stream_name)
|
||||||
|
|
||||||
if topic_is_muted(user_profile, stream.id, topic_name):
|
if topic_is_muted(user_profile, stream.id, topic_name):
|
||||||
@@ -24,8 +24,8 @@ def mute_topic(user_profile, stream_name, topic_name):
|
|||||||
do_mute_topic(user_profile, stream, recipient, topic_name)
|
do_mute_topic(user_profile, stream, recipient, topic_name)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
def unmute_topic(user_profile, stream_name, topic_name):
|
def unmute_topic(user_profile: UserProfile, stream_name: str,
|
||||||
# type: (UserProfile, str, str) -> HttpResponse
|
topic_name: str) -> HttpResponse:
|
||||||
error = _("Topic is not there in the muted_topics list")
|
error = _("Topic is not there in the muted_topics list")
|
||||||
stream = access_stream_for_unmute_topic(user_profile, stream_name, error)
|
stream = access_stream_for_unmute_topic(user_profile, stream_name, error)
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ from zerver.lib.request import has_request_variables, JsonableError, REQ
|
|||||||
from zerver.lib.response import json_success
|
from zerver.lib.response import json_success
|
||||||
from zerver.models import UserProfile, UserMessage
|
from zerver.models import UserProfile, UserMessage
|
||||||
|
|
||||||
def get_pointer_backend(request, user_profile):
|
def get_pointer_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile) -> HttpResponse
|
|
||||||
return json_success({'pointer': user_profile.pointer})
|
return json_success({'pointer': user_profile.pointer})
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
|
|||||||
@@ -17,13 +17,12 @@ from zerver.lib.timestamp import datetime_to_timestamp
|
|||||||
from zerver.lib.validator import check_bool
|
from zerver.lib.validator import check_bool
|
||||||
from zerver.models import UserActivity, UserPresence, UserProfile, get_user
|
from zerver.models import UserActivity, UserPresence, UserProfile, get_user
|
||||||
|
|
||||||
def get_status_list(requesting_user_profile):
|
def get_status_list(requesting_user_profile: UserProfile) -> Dict[str, Any]:
|
||||||
# type: (UserProfile) -> Dict[str, Any]
|
|
||||||
return {'presences': get_status_dict(requesting_user_profile),
|
return {'presences': get_status_dict(requesting_user_profile),
|
||||||
'server_timestamp': time.time()}
|
'server_timestamp': time.time()}
|
||||||
|
|
||||||
def get_presence_backend(request, user_profile, email):
|
def get_presence_backend(request: HttpRequest, user_profile: UserProfile,
|
||||||
# type: (HttpRequest, UserProfile, Text) -> HttpResponse
|
email: Text) -> HttpResponse:
|
||||||
try:
|
try:
|
||||||
target = get_user(email, user_profile.realm)
|
target = get_user(email, user_profile.realm)
|
||||||
except UserProfile.DoesNotExist:
|
except UserProfile.DoesNotExist:
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ from zerver.lib.response import json_success, json_error
|
|||||||
from zerver.lib.validator import check_string, check_list, check_bool
|
from zerver.lib.validator import check_string, check_list, check_bool
|
||||||
from zerver.models import PushDeviceToken, UserProfile
|
from zerver.models import PushDeviceToken, UserProfile
|
||||||
|
|
||||||
def validate_token(token_str, kind):
|
def validate_token(token_str: bytes, kind: int) -> None:
|
||||||
# type: (bytes, int) -> None
|
|
||||||
if token_str == '' or len(token_str) > 4096:
|
if token_str == '' or len(token_str) > 4096:
|
||||||
raise JsonableError(_('Empty or invalid length token'))
|
raise JsonableError(_('Empty or invalid length token'))
|
||||||
if kind == PushDeviceToken.APNS:
|
if kind == PushDeviceToken.APNS:
|
||||||
@@ -38,24 +37,24 @@ def add_apns_device_token(request, user_profile, token=REQ(),
|
|||||||
|
|
||||||
@human_users_only
|
@human_users_only
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def add_android_reg_id(request, user_profile, token=REQ()):
|
def add_android_reg_id(request: HttpRequest, user_profile: UserProfile,
|
||||||
# type: (HttpRequest, UserProfile, bytes) -> HttpResponse
|
token: bytes=REQ()) -> HttpResponse:
|
||||||
validate_token(token, PushDeviceToken.GCM)
|
validate_token(token, PushDeviceToken.GCM)
|
||||||
add_push_device_token(user_profile, token, PushDeviceToken.GCM)
|
add_push_device_token(user_profile, token, PushDeviceToken.GCM)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
@human_users_only
|
@human_users_only
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def remove_apns_device_token(request, user_profile, token=REQ()):
|
def remove_apns_device_token(request: HttpRequest, user_profile: UserProfile,
|
||||||
# type: (HttpRequest, UserProfile, bytes) -> HttpResponse
|
token: bytes=REQ()) -> HttpResponse:
|
||||||
validate_token(token, PushDeviceToken.APNS)
|
validate_token(token, PushDeviceToken.APNS)
|
||||||
remove_push_device_token(user_profile, token, PushDeviceToken.APNS)
|
remove_push_device_token(user_profile, token, PushDeviceToken.APNS)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
@human_users_only
|
@human_users_only
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def remove_android_reg_id(request, user_profile, token=REQ()):
|
def remove_android_reg_id(request: HttpRequest, user_profile: UserProfile,
|
||||||
# type: (HttpRequest, UserProfile, bytes) -> HttpResponse
|
token: bytes=REQ()) -> HttpResponse:
|
||||||
validate_token(token, PushDeviceToken.GCM)
|
validate_token(token, PushDeviceToken.GCM)
|
||||||
remove_push_device_token(user_profile, token, PushDeviceToken.GCM)
|
remove_push_device_token(user_profile, token, PushDeviceToken.GCM)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|||||||
@@ -13,16 +13,15 @@ from zerver.models import RealmDomain, UserProfile, get_realm_domains
|
|||||||
|
|
||||||
from typing import Text
|
from typing import Text
|
||||||
|
|
||||||
def list_realm_domains(request, user_profile):
|
def list_realm_domains(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile) -> (HttpResponse)
|
|
||||||
domains = get_realm_domains(user_profile.realm)
|
domains = get_realm_domains(user_profile.realm)
|
||||||
return json_success({'domains': domains})
|
return json_success({'domains': domains})
|
||||||
|
|
||||||
@require_realm_admin
|
@require_realm_admin
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def create_realm_domain(request, user_profile, domain=REQ(validator=check_string),
|
def create_realm_domain(request: HttpRequest, user_profile: UserProfile,
|
||||||
allow_subdomains=REQ(validator=check_bool)):
|
domain: Text=REQ(validator=check_string),
|
||||||
# type: (HttpRequest, UserProfile, Text, bool) -> (HttpResponse)
|
allow_subdomains: bool=REQ(validator=check_bool)) -> HttpResponse:
|
||||||
domain = domain.strip().lower()
|
domain = domain.strip().lower()
|
||||||
try:
|
try:
|
||||||
validate_domain(domain)
|
validate_domain(domain)
|
||||||
@@ -35,9 +34,8 @@ def create_realm_domain(request, user_profile, domain=REQ(validator=check_string
|
|||||||
|
|
||||||
@require_realm_admin
|
@require_realm_admin
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def patch_realm_domain(request, user_profile, domain,
|
def patch_realm_domain(request: HttpRequest, user_profile: UserProfile, domain: Text,
|
||||||
allow_subdomains=REQ(validator=check_bool)):
|
allow_subdomains: bool=REQ(validator=check_bool)) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile, Text, bool) -> (HttpResponse)
|
|
||||||
try:
|
try:
|
||||||
realm_domain = RealmDomain.objects.get(realm=user_profile.realm, domain=domain)
|
realm_domain = RealmDomain.objects.get(realm=user_profile.realm, domain=domain)
|
||||||
do_change_realm_domain(realm_domain, allow_subdomains)
|
do_change_realm_domain(realm_domain, allow_subdomains)
|
||||||
@@ -47,8 +45,8 @@ def patch_realm_domain(request, user_profile, domain,
|
|||||||
|
|
||||||
@require_realm_admin
|
@require_realm_admin
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def delete_realm_domain(request, user_profile, domain):
|
def delete_realm_domain(request: HttpRequest, user_profile: UserProfile,
|
||||||
# type: (HttpRequest, UserProfile, Text) -> (HttpResponse)
|
domain: Text) -> HttpResponse:
|
||||||
try:
|
try:
|
||||||
realm_domain = RealmDomain.objects.get(realm=user_profile.realm, domain=domain)
|
realm_domain = RealmDomain.objects.get(realm=user_profile.realm, domain=domain)
|
||||||
do_remove_realm_domain(realm_domain)
|
do_remove_realm_domain(realm_domain)
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ from zerver.lib.response import json_success, json_error
|
|||||||
from zerver.lib.actions import check_add_realm_emoji, do_remove_realm_emoji
|
from zerver.lib.actions import check_add_realm_emoji, do_remove_realm_emoji
|
||||||
|
|
||||||
|
|
||||||
def list_emoji(request, user_profile):
|
def list_emoji(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile) -> HttpResponse
|
|
||||||
|
|
||||||
# We don't call check_emoji_admin here because the list of realm
|
# We don't call check_emoji_admin here because the list of realm
|
||||||
# emoji is public.
|
# emoji is public.
|
||||||
@@ -23,8 +22,8 @@ def list_emoji(request, user_profile):
|
|||||||
|
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def upload_emoji(request, user_profile, emoji_name=REQ()):
|
def upload_emoji(request: HttpRequest, user_profile: UserProfile,
|
||||||
# type: (HttpRequest, UserProfile, Text) -> HttpResponse
|
emoji_name: Text=REQ()) -> HttpResponse:
|
||||||
check_valid_emoji_name(emoji_name)
|
check_valid_emoji_name(emoji_name)
|
||||||
check_emoji_admin(user_profile)
|
check_emoji_admin(user_profile)
|
||||||
if len(request.FILES) != 1:
|
if len(request.FILES) != 1:
|
||||||
@@ -42,8 +41,8 @@ def upload_emoji(request, user_profile, emoji_name=REQ()):
|
|||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
|
|
||||||
def delete_emoji(request, user_profile, emoji_name):
|
def delete_emoji(request: HttpRequest, user_profile: UserProfile,
|
||||||
# type: (HttpRequest, UserProfile, Text) -> HttpResponse
|
emoji_name: Text) -> HttpResponse:
|
||||||
check_valid_emoji(user_profile.realm, emoji_name)
|
check_valid_emoji(user_profile.realm, emoji_name)
|
||||||
check_emoji_admin(user_profile, emoji_name)
|
check_emoji_admin(user_profile, emoji_name)
|
||||||
do_remove_realm_emoji(user_profile.realm, emoji_name)
|
do_remove_realm_emoji(user_profile.realm, emoji_name)
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ from zerver.models import realm_filters_for_realm, UserProfile, RealmFilter
|
|||||||
|
|
||||||
|
|
||||||
# Custom realm filters
|
# Custom realm filters
|
||||||
def list_filters(request, user_profile):
|
def list_filters(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile) -> HttpResponse
|
|
||||||
filters = realm_filters_for_realm(user_profile.realm_id)
|
filters = realm_filters_for_realm(user_profile.realm_id)
|
||||||
return json_success({'filters': filters})
|
return json_success({'filters': filters})
|
||||||
|
|
||||||
@@ -37,8 +36,8 @@ def create_filter(request, user_profile, pattern=REQ(),
|
|||||||
|
|
||||||
|
|
||||||
@require_realm_admin
|
@require_realm_admin
|
||||||
def delete_filter(request, user_profile, filter_id):
|
def delete_filter(request: HttpRequest, user_profile: UserProfile,
|
||||||
# type: (HttpRequest, UserProfile, int) -> HttpResponse
|
filter_id: int) -> HttpResponse:
|
||||||
try:
|
try:
|
||||||
do_remove_realm_filter(realm=user_profile.realm, id=filter_id)
|
do_remove_realm_filter(realm=user_profile.realm, id=filter_id)
|
||||||
except RealmFilter.DoesNotExist:
|
except RealmFilter.DoesNotExist:
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ from zerver.models import UserProfile
|
|||||||
|
|
||||||
|
|
||||||
@require_realm_admin
|
@require_realm_admin
|
||||||
def upload_icon(request, user_profile):
|
def upload_icon(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile) -> HttpResponse
|
|
||||||
|
|
||||||
if len(request.FILES) != 1:
|
if len(request.FILES) != 1:
|
||||||
return json_error(_("You must upload exactly one icon."))
|
return json_error(_("You must upload exactly one icon."))
|
||||||
@@ -33,8 +32,7 @@ def upload_icon(request, user_profile):
|
|||||||
|
|
||||||
|
|
||||||
@require_realm_admin
|
@require_realm_admin
|
||||||
def delete_icon_backend(request, user_profile):
|
def delete_icon_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile) -> HttpResponse
|
|
||||||
# We don't actually delete the icon because it might still
|
# We don't actually delete the icon because it might still
|
||||||
# be needed if the URL was cached and it is rewrited
|
# be needed if the URL was cached and it is rewrited
|
||||||
# in any case after next update.
|
# in any case after next update.
|
||||||
@@ -46,8 +44,7 @@ def delete_icon_backend(request, user_profile):
|
|||||||
return json_success(json_result)
|
return json_success(json_result)
|
||||||
|
|
||||||
|
|
||||||
def get_icon_backend(request, user_profile):
|
def get_icon_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile) -> HttpResponse
|
|
||||||
url = realm_icon_url(user_profile.realm)
|
url = realm_icon_url(user_profile.realm)
|
||||||
|
|
||||||
# We can rely on the url already having query parameters. Because
|
# We can rely on the url already having query parameters. Because
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ import os
|
|||||||
js_source_map = None
|
js_source_map = None
|
||||||
|
|
||||||
# Read the source map information for decoding JavaScript backtraces.
|
# Read the source map information for decoding JavaScript backtraces.
|
||||||
def get_js_source_map():
|
def get_js_source_map() -> Optional[SourceMap]:
|
||||||
# type: () -> Optional[SourceMap]
|
|
||||||
global js_source_map
|
global js_source_map
|
||||||
if not js_source_map and not (settings.DEVELOPMENT or settings.TEST_SUITE):
|
if not js_source_map and not (settings.DEVELOPMENT or settings.TEST_SUITE):
|
||||||
js_source_map = SourceMap([
|
js_source_map = SourceMap([
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ from zerver.lib.actions import do_change_notification_settings, clear_scheduled_
|
|||||||
from zerver.models import UserProfile, ScheduledEmail
|
from zerver.models import UserProfile, ScheduledEmail
|
||||||
from zerver.context_processors import common_context
|
from zerver.context_processors import common_context
|
||||||
|
|
||||||
def process_unsubscribe(request, token, subscription_type, unsubscribe_function):
|
def process_unsubscribe(request: HttpRequest, token: str, subscription_type: str,
|
||||||
# type: (HttpRequest, str, str, Callable[[UserProfile], None]) -> HttpResponse
|
unsubscribe_function: Callable[[UserProfile], None]) -> HttpResponse:
|
||||||
try:
|
try:
|
||||||
confirmation = Confirmation.objects.get(confirmation_key=token)
|
confirmation = Confirmation.objects.get(confirmation_key=token)
|
||||||
except Confirmation.DoesNotExist:
|
except Confirmation.DoesNotExist:
|
||||||
@@ -25,16 +25,13 @@ def process_unsubscribe(request, token, subscription_type, unsubscribe_function)
|
|||||||
# Email unsubscribe functions. All have the function signature
|
# Email unsubscribe functions. All have the function signature
|
||||||
# processor(user_profile).
|
# processor(user_profile).
|
||||||
|
|
||||||
def do_missedmessage_unsubscribe(user_profile):
|
def do_missedmessage_unsubscribe(user_profile: UserProfile) -> None:
|
||||||
# type: (UserProfile) -> None
|
|
||||||
do_change_notification_settings(user_profile, 'enable_offline_email_notifications', False)
|
do_change_notification_settings(user_profile, 'enable_offline_email_notifications', False)
|
||||||
|
|
||||||
def do_welcome_unsubscribe(user_profile):
|
def do_welcome_unsubscribe(user_profile: UserProfile) -> None:
|
||||||
# type: (UserProfile) -> None
|
|
||||||
clear_scheduled_emails(user_profile.id, ScheduledEmail.WELCOME)
|
clear_scheduled_emails(user_profile.id, ScheduledEmail.WELCOME)
|
||||||
|
|
||||||
def do_digest_unsubscribe(user_profile):
|
def do_digest_unsubscribe(user_profile: UserProfile) -> None:
|
||||||
# type: (UserProfile) -> None
|
|
||||||
do_change_notification_settings(user_profile, 'enable_digest_emails', False)
|
do_change_notification_settings(user_profile, 'enable_digest_emails', False)
|
||||||
|
|
||||||
# The keys are part of the URL for the unsubscribe link and must be valid
|
# The keys are part of the URL for the unsubscribe link and must be valid
|
||||||
@@ -48,8 +45,8 @@ email_unsubscribers = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Login NOT required. These are for one-click unsubscribes.
|
# Login NOT required. These are for one-click unsubscribes.
|
||||||
def email_unsubscribe(request, email_type, confirmation_key):
|
def email_unsubscribe(request: HttpRequest, email_type: str,
|
||||||
# type: (HttpRequest, str, str) -> HttpResponse
|
confirmation_key: str) -> HttpResponse:
|
||||||
if email_type in email_unsubscribers:
|
if email_type in email_unsubscribers:
|
||||||
display_name, unsubscribe_function = email_unsubscribers[email_type]
|
display_name, unsubscribe_function = email_unsubscribers[email_type]
|
||||||
return process_unsubscribe(request, confirmation_key, display_name, unsubscribe_function)
|
return process_unsubscribe(request, confirmation_key, display_name, unsubscribe_function)
|
||||||
|
|||||||
Reference in New Issue
Block a user