mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
views: split events_register.py from main views file.
This commit is contained in:
@@ -58,7 +58,7 @@ from zerver.lib.validator import (
|
||||
equals, check_none_or, Validator
|
||||
)
|
||||
|
||||
from zerver.views import _default_all_public_streams, _default_narrow
|
||||
from zerver.views.events_register import _default_all_public_streams, _default_narrow
|
||||
|
||||
from zerver.tornadoviews import get_events_backend
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from typing import Any, List, Dict, Optional, Tuple, Iterable, Sequence
|
||||
from typing import Any, List, Dict, Optional
|
||||
|
||||
from django.utils import translation
|
||||
from django.utils.translation import ugettext as _
|
||||
@@ -35,7 +35,7 @@ from zerver.forms import RegistrationForm, HomepageForm, RealmCreationForm, ToSF
|
||||
CreateUserForm
|
||||
from zerver.lib.actions import is_inactive
|
||||
from django_auth_ldap.backend import LDAPBackend, _LDAPUser
|
||||
from zerver.lib.validator import check_string, check_list, check_bool
|
||||
from zerver.lib.validator import check_string, check_list
|
||||
from zerver.decorator import require_post, authenticated_json_post_view, \
|
||||
has_request_variables, \
|
||||
JsonableError, get_user_profile_by_email, REQ, \
|
||||
@@ -654,45 +654,6 @@ def is_buggy_ua(agent):
|
||||
return ("Humbug Desktop/" in agent or "Zulip Desktop/" in agent or "ZulipDesktop/" in agent) and \
|
||||
"Mac" not in agent
|
||||
|
||||
# Does not need to be authenticated because it's called from rest_dispatch
|
||||
@has_request_variables
|
||||
def api_events_register(request, user_profile,
|
||||
apply_markdown=REQ(default=False, validator=check_bool),
|
||||
all_public_streams=REQ(default=None, validator=check_bool)):
|
||||
# type: (HttpRequest, UserProfile, bool, Optional[bool]) -> HttpResponse
|
||||
return events_register_backend(request, user_profile,
|
||||
apply_markdown=apply_markdown,
|
||||
all_public_streams=all_public_streams)
|
||||
|
||||
def _default_all_public_streams(user_profile, all_public_streams):
|
||||
# type: (UserProfile, Optional[bool]) -> bool
|
||||
if all_public_streams is not None:
|
||||
return all_public_streams
|
||||
else:
|
||||
return user_profile.default_all_public_streams
|
||||
|
||||
def _default_narrow(user_profile, narrow):
|
||||
# type: (UserProfile, Iterable[Sequence[text_type]]) -> Iterable[Sequence[text_type]]
|
||||
default_stream = user_profile.default_events_register_stream
|
||||
if not narrow and user_profile.default_events_register_stream is not None:
|
||||
narrow = [['stream', default_stream.name]]
|
||||
return narrow
|
||||
|
||||
@has_request_variables
|
||||
def events_register_backend(request, user_profile, apply_markdown=True,
|
||||
all_public_streams=None,
|
||||
event_types=REQ(validator=check_list(check_string), default=None),
|
||||
narrow=REQ(validator=check_list(check_list(check_string, length=2)), default=[]),
|
||||
queue_lifespan_secs=REQ(converter=int, default=0)):
|
||||
# type: (HttpRequest, UserProfile, bool, Optional[bool], Optional[Iterable[str]], Iterable[Sequence[text_type]], int) -> HttpResponse
|
||||
all_public_streams = _default_all_public_streams(user_profile, all_public_streams)
|
||||
narrow = _default_narrow(user_profile, narrow)
|
||||
|
||||
ret = do_events_register(user_profile, request.client, apply_markdown,
|
||||
event_types, queue_lifespan_secs, all_public_streams,
|
||||
narrow=narrow)
|
||||
return json_success(ret)
|
||||
|
||||
@authenticated_json_post_view
|
||||
@has_request_variables
|
||||
def json_set_muted_topics(request, user_profile,
|
||||
|
||||
51
zerver/views/events_register.py
Normal file
51
zerver/views/events_register.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from six import text_type
|
||||
from typing import Iterable, Optional, Sequence
|
||||
|
||||
from zerver.lib.actions import do_events_register
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.validator import check_string, check_list, check_bool
|
||||
from zerver.models import UserProfile
|
||||
|
||||
def _default_all_public_streams(user_profile, all_public_streams):
|
||||
# type: (UserProfile, Optional[bool]) -> bool
|
||||
if all_public_streams is not None:
|
||||
return all_public_streams
|
||||
else:
|
||||
return user_profile.default_all_public_streams
|
||||
|
||||
def _default_narrow(user_profile, narrow):
|
||||
# type: (UserProfile, Iterable[Sequence[text_type]]) -> Iterable[Sequence[text_type]]
|
||||
default_stream = user_profile.default_events_register_stream
|
||||
if not narrow and user_profile.default_events_register_stream is not None:
|
||||
narrow = [['stream', default_stream.name]]
|
||||
return narrow
|
||||
|
||||
# Does not need to be authenticated because it's called from rest_dispatch
|
||||
@has_request_variables
|
||||
def api_events_register(request, user_profile,
|
||||
apply_markdown=REQ(default=False, validator=check_bool),
|
||||
all_public_streams=REQ(default=None, validator=check_bool)):
|
||||
# type: (HttpRequest, UserProfile, bool, Optional[bool]) -> HttpResponse
|
||||
return events_register_backend(request, user_profile,
|
||||
apply_markdown=apply_markdown,
|
||||
all_public_streams=all_public_streams)
|
||||
|
||||
@has_request_variables
|
||||
def events_register_backend(request, user_profile, apply_markdown=True,
|
||||
all_public_streams=None,
|
||||
event_types=REQ(validator=check_list(check_string), default=None),
|
||||
narrow=REQ(validator=check_list(check_list(check_string, length=2)), default=[]),
|
||||
queue_lifespan_secs=REQ(converter=int, default=0)):
|
||||
# type: (HttpRequest, UserProfile, bool, Optional[bool], Optional[Iterable[str]], Iterable[Sequence[text_type]], int) -> HttpResponse
|
||||
all_public_streams = _default_all_public_streams(user_profile, all_public_streams)
|
||||
narrow = _default_narrow(user_profile, narrow)
|
||||
|
||||
ret = do_events_register(user_profile, request.client, apply_markdown,
|
||||
event_types, queue_lifespan_secs, all_public_streams,
|
||||
narrow=narrow)
|
||||
return json_success(ret)
|
||||
|
||||
@@ -225,7 +225,7 @@ v1_api_and_json_patterns = [
|
||||
|
||||
# used to register for an event queue in tornado
|
||||
url(r'^register$', 'zerver.lib.rest.rest_dispatch',
|
||||
{'POST': 'zerver.views.api_events_register'}),
|
||||
{'POST': 'zerver.views.events_register.api_events_register'}),
|
||||
|
||||
# events -> zerver.tornadoviews
|
||||
url(r'^events$', 'zerver.lib.rest.rest_dispatch',
|
||||
|
||||
Reference in New Issue
Block a user