mirror of https://github.com/zulip/zulip.git
mypy: Almost migrate views/streams.py to python3.5 annotations.
One remaining issue with FuncKwargPair use.
This commit is contained in:
parent
3710252eba
commit
6bda59f3d7
|
@ -40,17 +40,14 @@ class PrincipalError(JsonableError):
|
||||||
data_fields = ['principal']
|
data_fields = ['principal']
|
||||||
http_status_code = 403
|
http_status_code = 403
|
||||||
|
|
||||||
def __init__(self, principal):
|
def __init__(self, principal: Text) -> None:
|
||||||
# type: (Text) -> None
|
|
||||||
self.principal = principal # type: Text
|
self.principal = principal # type: Text
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def msg_format():
|
def msg_format() -> Text:
|
||||||
# type: () -> Text
|
|
||||||
return _("User not authorized to execute queries on behalf of '{principal}'")
|
return _("User not authorized to execute queries on behalf of '{principal}'")
|
||||||
|
|
||||||
def principal_to_user_profile(agent, principal):
|
def principal_to_user_profile(agent: UserProfile, principal: Text) -> UserProfile:
|
||||||
# type: (UserProfile, Text) -> UserProfile
|
|
||||||
try:
|
try:
|
||||||
return get_user(principal, agent.realm)
|
return get_user(principal, agent.realm)
|
||||||
except UserProfile.DoesNotExist:
|
except UserProfile.DoesNotExist:
|
||||||
|
@ -61,16 +58,18 @@ def principal_to_user_profile(agent, principal):
|
||||||
raise PrincipalError(principal)
|
raise PrincipalError(principal)
|
||||||
|
|
||||||
@require_realm_admin
|
@require_realm_admin
|
||||||
def deactivate_stream_backend(request, user_profile, stream_id):
|
def deactivate_stream_backend(request: HttpRequest,
|
||||||
# type: (HttpRequest, UserProfile, int) -> HttpResponse
|
user_profile: UserProfile,
|
||||||
|
stream_id: int) -> HttpResponse:
|
||||||
stream = access_stream_for_delete(user_profile, stream_id)
|
stream = access_stream_for_delete(user_profile, stream_id)
|
||||||
do_deactivate_stream(stream)
|
do_deactivate_stream(stream)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
@require_realm_admin
|
@require_realm_admin
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def add_default_stream(request, user_profile, stream_name=REQ()):
|
def add_default_stream(request: HttpRequest,
|
||||||
# type: (HttpRequest, UserProfile, Text) -> HttpResponse
|
user_profile: UserProfile,
|
||||||
|
stream_name: Text=REQ()) -> HttpResponse:
|
||||||
(stream, recipient, sub) = access_stream_by_name(user_profile, stream_name)
|
(stream, recipient, sub) = access_stream_by_name(user_profile, stream_name)
|
||||||
do_add_default_stream(stream)
|
do_add_default_stream(stream)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
@ -133,8 +132,9 @@ def remove_default_stream_group(request: HttpRequest, user_profile: UserProfile,
|
||||||
|
|
||||||
@require_realm_admin
|
@require_realm_admin
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def remove_default_stream(request, user_profile, stream_name=REQ()):
|
def remove_default_stream(request: HttpRequest,
|
||||||
# type: (HttpRequest, UserProfile, Text) -> HttpResponse
|
user_profile: UserProfile,
|
||||||
|
stream_name: Text=REQ()) -> HttpResponse:
|
||||||
(stream, recipient, sub) = access_stream_by_name(user_profile, stream_name)
|
(stream, recipient, sub) = access_stream_by_name(user_profile, stream_name)
|
||||||
do_remove_default_stream(stream)
|
do_remove_default_stream(stream)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
@ -165,8 +165,7 @@ def update_stream_backend(
|
||||||
do_change_stream_invite_only(stream, is_private)
|
do_change_stream_invite_only(stream, is_private)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
def list_subscriptions_backend(request, user_profile):
|
def list_subscriptions_backend(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile) -> HttpResponse
|
|
||||||
return json_success({"subscriptions": gather_subscriptions(user_profile)[0]})
|
return json_success({"subscriptions": gather_subscriptions(user_profile)[0]})
|
||||||
|
|
||||||
FuncKwargPair = Tuple[Callable[..., HttpResponse], Dict[str, Union[int, Iterable[Any]]]]
|
FuncKwargPair = Tuple[Callable[..., HttpResponse], Dict[str, Union[int, Iterable[Any]]]]
|
||||||
|
@ -252,8 +251,9 @@ def remove_subscriptions_backend(
|
||||||
|
|
||||||
return json_success(result)
|
return json_success(result)
|
||||||
|
|
||||||
def you_were_just_subscribed_message(acting_user, stream_names, private_stream_names):
|
def you_were_just_subscribed_message(acting_user: UserProfile,
|
||||||
# type: (UserProfile, Set[Text], Set[Text]) -> Text
|
stream_names: Set[Text],
|
||||||
|
private_stream_names: Set[Text]) -> Text:
|
||||||
|
|
||||||
# stream_names is the list of streams for which we should send notifications.
|
# stream_names is the list of streams for which we should send notifications.
|
||||||
#
|
#
|
||||||
|
@ -470,14 +470,18 @@ def json_stream_exists(request: HttpRequest, user_profile: UserProfile, stream_n
|
||||||
return json_success(result) # results are ignored for HEAD requests
|
return json_success(result) # results are ignored for HEAD requests
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def json_get_stream_id(request, user_profile, stream_name=REQ('stream')):
|
def json_get_stream_id(request: HttpRequest,
|
||||||
# type: (HttpRequest, UserProfile, Text) -> HttpResponse
|
user_profile: UserProfile,
|
||||||
|
stream_name: Text=REQ('stream')) -> HttpResponse:
|
||||||
(stream, recipient, sub) = access_stream_by_name(user_profile, stream_name)
|
(stream, recipient, sub) = access_stream_by_name(user_profile, stream_name)
|
||||||
return json_success({'stream_id': stream.id})
|
return json_success({'stream_id': stream.id})
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def update_subscriptions_property(request, user_profile, stream_id=REQ(), property=REQ(), value=REQ()):
|
def update_subscriptions_property(request: HttpRequest,
|
||||||
# type: (HttpRequest, UserProfile, int, str, str) -> HttpResponse
|
user_profile: UserProfile,
|
||||||
|
stream_id: int=REQ(),
|
||||||
|
property: str=REQ(),
|
||||||
|
value: str=REQ()) -> HttpResponse:
|
||||||
subscription_data = [{"property": property,
|
subscription_data = [{"property": property,
|
||||||
"stream_id": stream_id,
|
"stream_id": stream_id,
|
||||||
"value": value}]
|
"value": value}]
|
||||||
|
|
Loading…
Reference in New Issue