2022-05-29 21:52:25 +02:00
|
|
|
from typing import Any, Dict, Mapping, Optional
|
2019-05-16 14:07:12 +02:00
|
|
|
from urllib.parse import urljoin
|
|
|
|
|
2012-10-15 22:52:08 +02:00
|
|
|
from django.conf import settings
|
2020-06-11 00:54:34 +02:00
|
|
|
from django.http import HttpRequest
|
2020-09-16 19:30:05 +02:00
|
|
|
from django.utils.html import escape
|
|
|
|
from django.utils.safestring import SafeString
|
2021-04-24 01:32:32 +02:00
|
|
|
from django.utils.translation import get_language
|
2016-11-08 10:00:31 +01:00
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
from version import (
|
|
|
|
LATEST_MAJOR_VERSION,
|
|
|
|
LATEST_RELEASE_ANNOUNCEMENT,
|
|
|
|
LATEST_RELEASE_VERSION,
|
|
|
|
ZULIP_VERSION,
|
|
|
|
)
|
2020-09-01 13:56:15 +02:00
|
|
|
from zerver.lib.exceptions import InvalidSubdomainError
|
2023-09-12 21:58:58 +02:00
|
|
|
from zerver.lib.i18n import get_language_list
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.realm_description import get_realm_rendered_description, get_realm_text_description
|
|
|
|
from zerver.lib.realm_icon import get_realm_icon_url
|
2021-08-21 19:24:20 +02:00
|
|
|
from zerver.lib.request import RequestNotes
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.send_email import FromAddress
|
2023-03-01 10:47:38 +01:00
|
|
|
from zerver.lib.subdomains import get_subdomain, is_root_domain_available
|
2023-12-15 02:14:24 +01:00
|
|
|
from zerver.models import Realm, UserProfile
|
|
|
|
from zerver.models.realms import get_realm
|
2017-04-20 21:02:56 +02:00
|
|
|
from zproject.backends import (
|
2020-06-11 00:54:34 +02:00
|
|
|
AUTH_BACKEND_NAME_MAP,
|
|
|
|
auth_enabled_helper,
|
2019-12-08 23:11:25 +01:00
|
|
|
get_external_method_dicts,
|
2017-04-20 21:02:56 +02:00
|
|
|
password_auth_enabled,
|
2017-09-10 20:42:07 +02:00
|
|
|
require_email_format_usernames,
|
2017-04-20 21:02:56 +02:00
|
|
|
)
|
2023-03-07 21:48:35 +01:00
|
|
|
from zproject.config import get_config
|
2017-04-18 07:10:41 +02:00
|
|
|
|
2022-05-29 21:52:25 +02:00
|
|
|
DEFAULT_PAGE_PARAMS: Mapping[str, Any] = {
|
2024-02-16 22:56:36 +01:00
|
|
|
"page_type": "default",
|
2021-05-20 20:14:17 +02:00
|
|
|
"development_environment": settings.DEVELOPMENT,
|
2021-04-24 01:32:32 +02:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:00:31 +01:00
|
|
|
|
2017-11-27 07:33:05 +01:00
|
|
|
def common_context(user: UserProfile) -> Dict[str, Any]:
|
2017-05-02 00:45:12 +02:00
|
|
|
"""Common context used for things like outgoing emails that don't
|
|
|
|
have a request.
|
|
|
|
"""
|
2016-11-08 10:07:47 +01:00
|
|
|
return {
|
2024-05-06 15:27:22 +02:00
|
|
|
"realm_uri": user.realm.url,
|
2021-02-12 08:20:45 +01:00
|
|
|
"realm_name": user.realm.name,
|
2023-04-09 06:10:04 +02:00
|
|
|
"root_domain_url": settings.ROOT_DOMAIN_URI,
|
2023-04-26 02:24:11 +02:00
|
|
|
"external_url_scheme": settings.EXTERNAL_URI_SCHEME,
|
2021-02-12 08:20:45 +01:00
|
|
|
"external_host": settings.EXTERNAL_HOST,
|
|
|
|
"user_name": user.full_name,
|
2023-05-01 12:47:38 +02:00
|
|
|
"corporate_enabled": settings.CORPORATE_ENABLED,
|
2016-11-08 10:07:47 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-05-04 04:47:44 +02:00
|
|
|
def get_realm_from_request(request: HttpRequest) -> Optional[Realm]:
|
2021-08-21 19:24:20 +02:00
|
|
|
request_notes = RequestNotes.get_notes(request)
|
2022-07-14 15:34:17 +02:00
|
|
|
if request.user.is_authenticated:
|
2017-05-04 01:12:34 +02:00
|
|
|
return request.user.realm
|
2021-07-09 17:16:26 +02:00
|
|
|
if not request_notes.has_fetched_realm:
|
|
|
|
# We cache the realm object from this function on the request data,
|
2019-03-17 22:08:53 +01:00
|
|
|
# so that functions that call get_realm_from_request don't
|
|
|
|
# need to do duplicate queries on the same realm while
|
|
|
|
# processing a single request.
|
|
|
|
subdomain = get_subdomain(request)
|
2021-08-21 19:24:20 +02:00
|
|
|
request_notes = RequestNotes.get_notes(request)
|
2019-05-04 04:47:44 +02:00
|
|
|
try:
|
2021-07-09 17:16:26 +02:00
|
|
|
request_notes.realm = get_realm(subdomain)
|
2019-05-04 04:47:44 +02:00
|
|
|
except Realm.DoesNotExist:
|
2021-07-09 17:16:26 +02:00
|
|
|
request_notes.realm = None
|
|
|
|
request_notes.has_fetched_realm = True
|
|
|
|
return request_notes.realm
|
2017-05-04 01:12:34 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-09-01 13:56:15 +02:00
|
|
|
def get_valid_realm_from_request(request: HttpRequest) -> Realm:
|
|
|
|
realm = get_realm_from_request(request)
|
|
|
|
if realm is None:
|
2023-02-04 02:07:20 +01:00
|
|
|
raise InvalidSubdomainError
|
2020-09-01 13:56:15 +02:00
|
|
|
return realm
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-06-15 14:15:17 +02:00
|
|
|
def get_apps_page_url() -> str:
|
apps: Fix redirect from /apps -> https://zulip.com/apps/.
When this code was moved from being in zerver in 21a2fd482eae, it kept
the `if ZILENCER_ENABLED` blocks. Since ZILENCER and CORPORATE are
generally either both on or both off, the if statement became
mostly-unnecessary.
However, because tests cannot easily remove elements from
INSTALLED_APPS and re-determine URL resolution, we switch to checking
`if CORPORATE_ENABLED` as a guard, and leave these in-place.
The other side effect of this is that with e54ded49c44c, most Zulip
deployments started to 404 requests for `/apps` instead of redirecting
them to `https://zulip.com/apps/` since they no longer had any path
configured for `/apps`. Unfortunately, this URL is in widespread use
in the app (e.g. in links from the Welcome Bot), so we should ensure
that it does successfully redirect.
Add the `/apps` path to `zerver`, but only if not CORPORATE_ENABLED,
so the URLs do not overlap.
2022-12-16 15:17:00 +01:00
|
|
|
if settings.CORPORATE_ENABLED:
|
2021-06-15 14:15:17 +02:00
|
|
|
return "/apps/"
|
2021-06-16 10:23:05 +02:00
|
|
|
return "https://zulip.com/apps/"
|
2021-06-15 14:15:17 +02:00
|
|
|
|
|
|
|
|
2021-11-03 21:36:54 +01:00
|
|
|
def is_isolated_page(request: HttpRequest) -> bool:
|
|
|
|
"""Accept a GET param `?nav=no` to render an isolated, navless page."""
|
|
|
|
return request.GET.get("nav") == "no"
|
|
|
|
|
|
|
|
|
2023-12-08 20:39:39 +01:00
|
|
|
def zulip_default_corporate_context(request: HttpRequest) -> Dict[str, Any]:
|
|
|
|
from corporate.lib.decorator import is_self_hosting_management_subdomain
|
|
|
|
|
|
|
|
# Check if view function is in corporate app.
|
2023-12-05 18:45:07 +01:00
|
|
|
if request.resolver_match is not None and not request.resolver_match.func.__module__.startswith(
|
|
|
|
"corporate"
|
2023-12-08 20:39:39 +01:00
|
|
|
):
|
|
|
|
return {
|
|
|
|
"is_self_hosting_management_page": False,
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add common context variables that are only used on the corporate site.
|
|
|
|
return {
|
|
|
|
"is_self_hosting_management_page": is_self_hosting_management_subdomain(request),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-27 07:33:05 +01:00
|
|
|
def zulip_default_context(request: HttpRequest) -> Dict[str, Any]:
|
2017-05-02 00:45:12 +02:00
|
|
|
"""Context available to all Zulip Jinja2 templates that have a request
|
|
|
|
passed in. Designed to provide the long list of variables at the
|
|
|
|
bottom of this function in a wide range of situations: logged-in
|
|
|
|
or logged-out, subdomains or not, etc.
|
|
|
|
|
2017-10-02 08:32:09 +02:00
|
|
|
The main variable in the below is whether we know what realm the
|
|
|
|
user is trying to interact with.
|
2017-05-02 00:45:12 +02:00
|
|
|
"""
|
2017-05-04 01:12:34 +02:00
|
|
|
realm = get_realm_from_request(request)
|
2016-11-08 10:00:31 +01:00
|
|
|
|
2017-08-04 07:53:19 +02:00
|
|
|
if realm is None:
|
2017-08-28 23:01:18 +02:00
|
|
|
realm_uri = settings.ROOT_DOMAIN_URI
|
2017-08-04 07:53:19 +02:00
|
|
|
realm_name = None
|
|
|
|
realm_icon = None
|
|
|
|
else:
|
2024-05-06 15:27:22 +02:00
|
|
|
realm_uri = realm.url
|
2017-04-18 07:10:41 +02:00
|
|
|
realm_name = realm.name
|
|
|
|
realm_icon = get_realm_icon_url(realm)
|
2016-08-14 00:57:45 +02:00
|
|
|
|
2023-08-09 19:15:36 +02:00
|
|
|
skip_footer = False
|
2016-09-14 08:00:27 +02:00
|
|
|
register_link_disabled = settings.REGISTER_LINK_DISABLED
|
|
|
|
login_link_disabled = settings.LOGIN_LINK_DISABLED
|
|
|
|
find_team_link_disabled = settings.FIND_TEAM_LINK_DISABLED
|
2018-05-01 20:59:24 +02:00
|
|
|
allow_search_engine_indexing = False
|
2017-07-28 01:18:37 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
if (
|
|
|
|
settings.ROOT_DOMAIN_LANDING_PAGE
|
|
|
|
and get_subdomain(request) == Realm.SUBDOMAIN_FOR_ROOT_DOMAIN
|
|
|
|
):
|
2016-09-14 08:00:27 +02:00
|
|
|
register_link_disabled = True
|
|
|
|
login_link_disabled = True
|
|
|
|
find_team_link_disabled = False
|
2018-05-01 20:59:24 +02:00
|
|
|
allow_search_engine_indexing = True
|
2023-08-09 19:15:36 +02:00
|
|
|
elif realm is None:
|
|
|
|
register_link_disabled = True
|
|
|
|
login_link_disabled = True
|
|
|
|
find_team_link_disabled = False
|
|
|
|
skip_footer = True
|
2016-09-14 08:00:27 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
apps_page_web = settings.ROOT_DOMAIN_URI + "/accounts/go/"
|
2020-05-26 22:27:48 +02:00
|
|
|
|
2017-08-07 17:38:25 +02:00
|
|
|
if settings.DEVELOPMENT:
|
|
|
|
secrets_path = "zproject/dev-secrets.conf"
|
|
|
|
settings_path = "zproject/dev_settings.py"
|
|
|
|
settings_comments_path = "zproject/prod_settings_template.py"
|
|
|
|
else:
|
|
|
|
secrets_path = "/etc/zulip/zulip-secrets.conf"
|
|
|
|
settings_path = "/etc/zulip/settings.py"
|
|
|
|
settings_comments_path = "/etc/zulip/settings.py"
|
|
|
|
|
2022-07-21 08:44:45 +02:00
|
|
|
# Used to remove links to Zulip docs and landing page from footer of self-hosted pages.
|
|
|
|
corporate_enabled = settings.CORPORATE_ENABLED
|
|
|
|
|
2020-09-16 19:30:05 +02:00
|
|
|
support_email = FromAddress.SUPPORT
|
2021-02-12 08:19:30 +01:00
|
|
|
support_email_html_tag = SafeString(
|
|
|
|
f'<a href="mailto:{escape(support_email)}">{escape(support_email)}</a>'
|
|
|
|
)
|
2020-09-16 19:30:05 +02:00
|
|
|
|
2024-02-16 22:56:36 +01:00
|
|
|
# Sync this with default_params_schema in base_page_params.ts.
|
2023-03-07 21:48:35 +01:00
|
|
|
default_page_params: Dict[str, Any] = {
|
2021-04-24 01:32:32 +02:00
|
|
|
**DEFAULT_PAGE_PARAMS,
|
2023-03-07 21:48:35 +01:00
|
|
|
"server_sentry_dsn": settings.SENTRY_FRONTEND_DSN,
|
2021-04-24 01:32:32 +02:00
|
|
|
"request_language": get_language(),
|
|
|
|
}
|
2023-03-07 21:48:35 +01:00
|
|
|
if settings.SENTRY_FRONTEND_DSN is not None:
|
|
|
|
if realm is not None:
|
|
|
|
default_page_params["realm_sentry_key"] = realm.string_id
|
|
|
|
default_page_params["server_sentry_environment"] = get_config(
|
|
|
|
"machine", "deploy_type", "development"
|
|
|
|
)
|
|
|
|
default_page_params["server_sentry_sample_rate"] = settings.SENTRY_FRONTEND_SAMPLE_RATE
|
|
|
|
default_page_params["server_sentry_trace_rate"] = settings.SENTRY_FRONTEND_TRACE_RATE
|
2021-04-24 01:32:32 +02:00
|
|
|
|
2018-12-19 01:02:22 +01:00
|
|
|
context = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"root_domain_landing_page": settings.ROOT_DOMAIN_LANDING_PAGE,
|
|
|
|
"custom_logo_url": settings.CUSTOM_LOGO_URL,
|
|
|
|
"register_link_disabled": register_link_disabled,
|
|
|
|
"login_link_disabled": login_link_disabled,
|
2021-11-03 21:36:54 +01:00
|
|
|
"terms_of_service": settings.TERMS_OF_SERVICE_VERSION is not None,
|
2021-02-12 08:20:45 +01:00
|
|
|
"login_url": settings.HOME_NOT_LOGGED_IN,
|
|
|
|
"only_sso": settings.ONLY_SSO,
|
|
|
|
"external_host": settings.EXTERNAL_HOST,
|
2023-04-26 02:24:11 +02:00
|
|
|
"external_url_scheme": settings.EXTERNAL_URI_SCHEME,
|
2021-02-12 08:20:45 +01:00
|
|
|
"realm_uri": realm_uri,
|
|
|
|
"realm_name": realm_name,
|
|
|
|
"realm_icon": realm_icon,
|
2023-04-09 06:10:04 +02:00
|
|
|
"root_domain_url": settings.ROOT_DOMAIN_URI,
|
2021-06-15 14:15:17 +02:00
|
|
|
"apps_page_url": get_apps_page_url(),
|
2021-02-12 08:20:45 +01:00
|
|
|
"apps_page_web": apps_page_web,
|
|
|
|
"open_realm_creation": settings.OPEN_REALM_CREATION,
|
|
|
|
"development_environment": settings.DEVELOPMENT,
|
|
|
|
"support_email": support_email,
|
|
|
|
"support_email_html_tag": support_email_html_tag,
|
|
|
|
"find_team_link_disabled": find_team_link_disabled,
|
|
|
|
"password_min_length": settings.PASSWORD_MIN_LENGTH,
|
|
|
|
"password_min_guesses": settings.PASSWORD_MIN_GUESSES,
|
|
|
|
"zulip_version": ZULIP_VERSION,
|
2022-07-14 15:34:17 +02:00
|
|
|
"user_is_authenticated": request.user.is_authenticated,
|
2021-02-12 08:20:45 +01:00
|
|
|
"settings_path": settings_path,
|
|
|
|
"secrets_path": secrets_path,
|
|
|
|
"settings_comments_path": settings_comments_path,
|
2021-08-21 19:24:20 +02:00
|
|
|
"platform": RequestNotes.get_notes(request).client_name,
|
2021-02-12 08:20:45 +01:00
|
|
|
"allow_search_engine_indexing": allow_search_engine_indexing,
|
|
|
|
"landing_page_navbar_message": settings.LANDING_PAGE_NAVBAR_MESSAGE,
|
2021-11-03 21:36:54 +01:00
|
|
|
"is_isolated_page": is_isolated_page(request),
|
2023-08-09 19:15:36 +02:00
|
|
|
"skip_footer": skip_footer,
|
2021-04-24 01:32:32 +02:00
|
|
|
"default_page_params": default_page_params,
|
2022-07-21 08:44:45 +02:00
|
|
|
"corporate_enabled": corporate_enabled,
|
2012-10-17 20:34:38 +02:00
|
|
|
}
|
2018-12-19 01:02:22 +01:00
|
|
|
|
2022-09-05 16:12:21 +02:00
|
|
|
context["PAGE_METADATA_URL"] = f"{realm_uri}{request.path}"
|
2019-04-26 15:02:16 +02:00
|
|
|
if realm is not None and realm.icon_source == realm.ICON_UPLOADED:
|
2022-09-05 16:12:21 +02:00
|
|
|
context["PAGE_METADATA_IMAGE"] = urljoin(realm_uri, realm_icon)
|
2019-04-26 15:02:16 +02:00
|
|
|
|
2019-03-20 13:13:44 +01:00
|
|
|
return context
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-03-20 13:13:44 +01:00
|
|
|
def login_context(request: HttpRequest) -> Dict[str, Any]:
|
|
|
|
realm = get_realm_from_request(request)
|
|
|
|
|
|
|
|
if realm is None:
|
|
|
|
realm_description = None
|
|
|
|
realm_invite_required = False
|
2020-10-07 07:10:02 +02:00
|
|
|
realm_web_public_access_enabled = False
|
2019-03-20 13:13:44 +01:00
|
|
|
else:
|
|
|
|
realm_description = get_realm_rendered_description(realm)
|
|
|
|
realm_invite_required = realm.invite_required
|
2022-01-29 00:54:13 +01:00
|
|
|
# We offer web-public access only if the realm has actual web
|
2020-10-07 07:10:02 +02:00
|
|
|
# public streams configured, in addition to having it enabled.
|
2021-10-03 14:16:07 +02:00
|
|
|
realm_web_public_access_enabled = realm.allow_web_public_streams_access()
|
2019-03-20 13:13:44 +01:00
|
|
|
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
context: Dict[str, Any] = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"realm_invite_required": realm_invite_required,
|
|
|
|
"realm_description": realm_description,
|
|
|
|
"require_email_format_usernames": require_email_format_usernames(realm),
|
|
|
|
"password_auth_enabled": password_auth_enabled(realm),
|
|
|
|
"two_factor_authentication_enabled": settings.TWO_FACTOR_AUTHENTICATION_ENABLED,
|
2020-10-07 07:10:02 +02:00
|
|
|
"realm_web_public_access_enabled": realm_web_public_access_enabled,
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
}
|
2019-03-20 13:13:44 +01:00
|
|
|
|
2019-04-24 04:30:15 +02:00
|
|
|
if realm is not None and realm.description:
|
2022-09-05 16:12:21 +02:00
|
|
|
context["PAGE_TITLE"] = realm.name
|
|
|
|
context["PAGE_DESCRIPTION"] = get_realm_text_description(realm)
|
2019-04-24 04:30:15 +02:00
|
|
|
|
2018-12-19 01:02:22 +01:00
|
|
|
# Add the keys for our standard authentication backends.
|
2019-03-17 22:29:42 +01:00
|
|
|
no_auth_enabled = True
|
2018-12-19 01:02:22 +01:00
|
|
|
for auth_backend_name in AUTH_BACKEND_NAME_MAP:
|
|
|
|
name_lower = auth_backend_name.lower()
|
2020-06-10 06:41:04 +02:00
|
|
|
key = f"{name_lower}_auth_enabled"
|
2019-03-17 22:29:42 +01:00
|
|
|
is_enabled = auth_enabled_helper([auth_backend_name], realm)
|
|
|
|
context[key] = is_enabled
|
|
|
|
if is_enabled:
|
|
|
|
no_auth_enabled = False
|
2019-03-05 18:30:10 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
context["external_authentication_methods"] = get_external_method_dicts(realm)
|
|
|
|
context["no_auth_enabled"] = no_auth_enabled
|
2019-03-05 18:30:10 +01:00
|
|
|
|
2018-12-19 01:02:22 +01:00
|
|
|
return context
|
2019-03-20 13:13:44 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-03-20 13:13:44 +01:00
|
|
|
def latest_info_context() -> Dict[str, str]:
|
|
|
|
context = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"latest_release_version": LATEST_RELEASE_VERSION,
|
|
|
|
"latest_major_version": LATEST_MAJOR_VERSION,
|
|
|
|
"latest_release_announcement": LATEST_RELEASE_ANNOUNCEMENT,
|
2019-03-20 13:13:44 +01:00
|
|
|
}
|
|
|
|
return context
|
2023-03-01 10:47:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_realm_create_form_context() -> Dict[str, Any]:
|
|
|
|
context = {
|
2023-09-12 21:58:58 +02:00
|
|
|
"language_list": get_language_list(),
|
2023-03-01 10:47:38 +01:00
|
|
|
"MAX_REALM_NAME_LENGTH": str(Realm.MAX_REALM_NAME_LENGTH),
|
|
|
|
"MAX_REALM_SUBDOMAIN_LENGTH": str(Realm.MAX_REALM_SUBDOMAIN_LENGTH),
|
|
|
|
"root_domain_available": is_root_domain_available(),
|
|
|
|
"sorted_realm_types": sorted(Realm.ORG_TYPES.values(), key=lambda d: d["display_order"]),
|
|
|
|
}
|
|
|
|
return context
|