mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 16:43:57 +00:00
mypy: Use Python 3 type syntax in zerver/views/streams.py.
[greg: small formatting tweaks]
This commit is contained in:
committed by
Greg Price
parent
aa9567ce37
commit
00178d114b
@@ -141,11 +141,13 @@ def remove_default_stream(request, user_profile, stream_name=REQ()):
|
||||
|
||||
@require_realm_admin
|
||||
@has_request_variables
|
||||
def update_stream_backend(request, user_profile, stream_id,
|
||||
description=REQ(validator=check_string, default=None),
|
||||
is_private=REQ(validator=check_bool, default=None),
|
||||
new_name=REQ(validator=check_string, default=None)):
|
||||
# type: (HttpRequest, UserProfile, int, Optional[Text], Optional[bool], Optional[Text]) -> HttpResponse
|
||||
def update_stream_backend(
|
||||
request: HttpRequest, user_profile: UserProfile,
|
||||
stream_id: int,
|
||||
description: Optional[Text]=REQ(validator=check_string, default=None),
|
||||
is_private: Optional[bool]=REQ(validator=check_bool, default=None),
|
||||
new_name: Optional[Text]=REQ(validator=check_string, default=None),
|
||||
) -> HttpResponse:
|
||||
(stream, recipient, sub) = access_stream_by_id(user_profile, stream_id)
|
||||
|
||||
if description is not None:
|
||||
@@ -170,11 +172,12 @@ def list_subscriptions_backend(request, user_profile):
|
||||
FuncKwargPair = Tuple[Callable[..., HttpResponse], Dict[str, Union[int, Iterable[Any]]]]
|
||||
|
||||
@has_request_variables
|
||||
def update_subscriptions_backend(request, user_profile,
|
||||
delete=REQ(validator=check_list(check_string), default=[]),
|
||||
add=REQ(validator=check_list(check_dict([('name', check_string)])),
|
||||
default=[])):
|
||||
# type: (HttpRequest, UserProfile, Iterable[Text], Iterable[Mapping[str, Any]]) -> HttpResponse
|
||||
def update_subscriptions_backend(
|
||||
request: HttpRequest, user_profile: UserProfile,
|
||||
delete: Iterable[Text]=REQ(validator=check_list(check_string), default=[]),
|
||||
add: Iterable[Mapping[str, Any]]=REQ(
|
||||
validator=check_list(check_dict([('name', check_string)])), default=[]),
|
||||
) -> HttpResponse:
|
||||
if not add and not delete:
|
||||
return json_error(_('Nothing to do. Specify at least one of "add" or "delete".'))
|
||||
|
||||
@@ -206,10 +209,11 @@ def compose_views(request, user_profile, method_kwarg_pairs):
|
||||
return json_success(json_dict)
|
||||
|
||||
@has_request_variables
|
||||
def remove_subscriptions_backend(request, user_profile,
|
||||
streams_raw = REQ("subscriptions", validator=check_list(check_string)),
|
||||
principals = REQ(validator=check_list(check_string), default=None)):
|
||||
# type: (HttpRequest, UserProfile, Iterable[Text], Optional[Iterable[Text]]) -> HttpResponse
|
||||
def remove_subscriptions_backend(
|
||||
request: HttpRequest, user_profile: UserProfile,
|
||||
streams_raw: Iterable[Text]=REQ("subscriptions", validator=check_list(check_string)),
|
||||
principals: Optional[Iterable[Text]]=REQ(validator=check_list(check_string), default=None),
|
||||
) -> HttpResponse:
|
||||
|
||||
removing_someone_else = principals and \
|
||||
set(principals) != set((user_profile.email,))
|
||||
@@ -280,14 +284,15 @@ def you_were_just_subscribed_message(acting_user, stream_names, private_stream_n
|
||||
return msg
|
||||
|
||||
@has_request_variables
|
||||
def add_subscriptions_backend(request, user_profile,
|
||||
streams_raw = REQ("subscriptions",
|
||||
validator=check_list(check_dict([('name', check_string)]))),
|
||||
invite_only = REQ(validator=check_bool, default=False),
|
||||
announce = REQ(validator=check_bool, default=False),
|
||||
principals = REQ(validator=check_list(check_string), default=[]),
|
||||
authorization_errors_fatal = REQ(validator=check_bool, default=True)):
|
||||
# type: (HttpRequest, UserProfile, Iterable[Mapping[str, Text]], bool, bool, List[Text], bool) -> HttpResponse
|
||||
def add_subscriptions_backend(
|
||||
request: HttpRequest, user_profile: UserProfile,
|
||||
streams_raw: Iterable[Mapping[str, Text]]=REQ(
|
||||
"subscriptions", validator=check_list(check_dict([('name', check_string)]))),
|
||||
invite_only: bool=REQ(validator=check_bool, default=False),
|
||||
announce: bool=REQ(validator=check_bool, default=False),
|
||||
principals: List[Text]=REQ(validator=check_list(check_string), default=[]),
|
||||
authorization_errors_fatal: bool=REQ(validator=check_bool, default=True),
|
||||
) -> HttpResponse:
|
||||
stream_dicts = []
|
||||
for stream_dict in streams_raw:
|
||||
stream_dict_copy = {} # type: Dict[str, Any]
|
||||
@@ -405,9 +410,8 @@ def add_subscriptions_backend(request, user_profile,
|
||||
return json_success(result)
|
||||
|
||||
@has_request_variables
|
||||
def get_subscribers_backend(request, user_profile,
|
||||
stream_id=REQ('stream', converter=to_non_negative_int)):
|
||||
# type: (HttpRequest, UserProfile, int) -> HttpResponse
|
||||
def get_subscribers_backend(request: HttpRequest, user_profile: UserProfile,
|
||||
stream_id: int=REQ('stream', converter=to_non_negative_int)) -> HttpResponse:
|
||||
(stream, recipient, sub) = access_stream_by_id(user_profile, stream_id)
|
||||
subscribers = get_subscriber_emails(stream, user_profile)
|
||||
|
||||
@@ -416,12 +420,11 @@ def get_subscribers_backend(request, user_profile,
|
||||
# By default, lists all streams that the user has access to --
|
||||
# i.e. public streams plus invite-only streams that the user is on
|
||||
@has_request_variables
|
||||
def get_streams_backend(request, user_profile,
|
||||
include_public=REQ(validator=check_bool, default=True),
|
||||
include_subscribed=REQ(validator=check_bool, default=True),
|
||||
include_all_active=REQ(validator=check_bool, default=False),
|
||||
include_default=REQ(validator=check_bool, default=False)):
|
||||
# type: (HttpRequest, UserProfile, bool, bool, bool, bool) -> HttpResponse
|
||||
def get_streams_backend(request: HttpRequest, user_profile: UserProfile,
|
||||
include_public: bool=REQ(validator=check_bool, default=True),
|
||||
include_subscribed: bool=REQ(validator=check_bool, default=True),
|
||||
include_all_active: bool=REQ(validator=check_bool, default=False),
|
||||
include_default: bool=REQ(validator=check_bool, default=False)) -> HttpResponse:
|
||||
|
||||
streams = do_get_streams(user_profile, include_public=include_public,
|
||||
include_subscribed=include_subscribed,
|
||||
@@ -430,9 +433,8 @@ def get_streams_backend(request, user_profile,
|
||||
return json_success({"streams": streams})
|
||||
|
||||
@has_request_variables
|
||||
def get_topics_backend(request, user_profile,
|
||||
stream_id=REQ(converter=to_non_negative_int)):
|
||||
# type: (HttpRequest, UserProfile, int) -> HttpResponse
|
||||
def get_topics_backend(request: HttpRequest, user_profile: UserProfile,
|
||||
stream_id: int=REQ(converter=to_non_negative_int)) -> HttpResponse:
|
||||
(stream, recipient, sub) = access_stream_by_id(user_profile, stream_id)
|
||||
|
||||
result = get_topic_history_for_stream(
|
||||
@@ -444,9 +446,8 @@ def get_topics_backend(request, user_profile,
|
||||
|
||||
@authenticated_json_post_view
|
||||
@has_request_variables
|
||||
def json_stream_exists(request, user_profile, stream_name=REQ("stream"),
|
||||
autosubscribe=REQ(validator=check_bool, default=False)):
|
||||
# type: (HttpRequest, UserProfile, Text, bool) -> HttpResponse
|
||||
def json_stream_exists(request: HttpRequest, user_profile: UserProfile, stream_name: Text=REQ("stream"),
|
||||
autosubscribe: bool=REQ(validator=check_bool, default=False)) -> HttpResponse:
|
||||
check_stream_name(stream_name)
|
||||
|
||||
try:
|
||||
@@ -483,13 +484,16 @@ def update_subscriptions_property(request, user_profile, stream_id=REQ(), proper
|
||||
subscription_data=subscription_data)
|
||||
|
||||
@has_request_variables
|
||||
def update_subscription_properties_backend(request, user_profile, subscription_data=REQ(
|
||||
validator=check_list(
|
||||
check_dict([("stream_id", check_int),
|
||||
("property", check_string),
|
||||
("value", check_variable_type(
|
||||
[check_string, check_bool]))])))):
|
||||
# type: (HttpRequest, UserProfile, List[Dict[str, Any]]) -> HttpResponse
|
||||
def update_subscription_properties_backend(
|
||||
request: HttpRequest, user_profile: UserProfile,
|
||||
subscription_data: List[Dict[str, Any]]=REQ(
|
||||
validator=check_list(
|
||||
check_dict([("stream_id", check_int),
|
||||
("property", check_string),
|
||||
("value", check_variable_type([check_string, check_bool]))])
|
||||
)
|
||||
),
|
||||
) -> HttpResponse:
|
||||
"""
|
||||
This is the entry point to changing subscription properties. This
|
||||
is a bulk endpoint: requestors always provide a subscription_data
|
||||
|
||||
Reference in New Issue
Block a user