2020-06-11 00:54:34 +02:00
|
|
|
import os
|
2020-04-04 01:47:18 +02:00
|
|
|
from urllib.parse import urlsplit
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2016-06-25 03:44:32 +02:00
|
|
|
from django.conf import settings
|
2020-04-04 01:47:18 +02:00
|
|
|
from django.conf.urls.static import static
|
|
|
|
from django.contrib.staticfiles.views import serve as staticfiles_serve
|
2021-08-10 15:07:40 +02:00
|
|
|
from django.http.request import HttpRequest
|
2021-08-15 18:32:51 +02:00
|
|
|
from django.http.response import FileResponse
|
2020-09-12 04:18:53 +02:00
|
|
|
from django.urls import path
|
2017-06-14 02:01:01 +02:00
|
|
|
from django.views.generic import TemplateView
|
2016-10-27 13:29:44 +02:00
|
|
|
from django.views.static import serve
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2020-06-17 14:25:25 +02:00
|
|
|
from zerver.views.auth import config_error, login_page
|
2021-03-24 12:18:30 +01:00
|
|
|
from zerver.views.development.cache import remove_caches
|
2021-05-07 00:38:24 +02:00
|
|
|
from zerver.views.development.camo import handle_camo_url
|
2021-04-23 11:01:20 +02:00
|
|
|
from zerver.views.development.dev_login import (
|
|
|
|
api_dev_fetch_api_key,
|
|
|
|
api_dev_list_users,
|
|
|
|
dev_direct_login,
|
|
|
|
)
|
2020-09-22 05:31:38 +02:00
|
|
|
from zerver.views.development.email_log import clear_emails, email_page, generate_all_emails
|
|
|
|
from zerver.views.development.integrations import (
|
|
|
|
check_send_webhook_fixture_message,
|
|
|
|
dev_panel,
|
|
|
|
get_fixtures,
|
|
|
|
send_all_webhook_fixture_messages,
|
|
|
|
)
|
|
|
|
from zerver.views.development.registration import (
|
|
|
|
confirmation_key,
|
2021-08-13 20:37:15 +02:00
|
|
|
register_demo_development_realm,
|
2020-09-22 05:31:38 +02:00
|
|
|
register_development_realm,
|
|
|
|
register_development_user,
|
|
|
|
)
|
2016-06-25 03:44:32 +02:00
|
|
|
|
|
|
|
# These URLs are available only in the development environment
|
|
|
|
|
2019-07-18 11:36:56 +02:00
|
|
|
use_prod_static = not settings.DEBUG
|
2016-06-25 03:44:32 +02:00
|
|
|
|
2017-03-18 01:58:45 +01:00
|
|
|
urls = [
|
2017-06-02 21:44:09 +02:00
|
|
|
# Serve useful development environment resources (docs, coverage reports, etc.)
|
2021-02-12 08:19:30 +01:00
|
|
|
path(
|
2021-02-12 08:20:45 +01:00
|
|
|
"coverage/<path:path>",
|
2021-02-12 08:19:30 +01:00
|
|
|
serve,
|
2021-02-12 08:20:45 +01:00
|
|
|
{"document_root": os.path.join(settings.DEPLOY_ROOT, "var/coverage"), "show_indexes": True},
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
|
|
|
path(
|
2021-02-12 08:20:45 +01:00
|
|
|
"node-coverage/<path:path>",
|
2021-02-12 08:19:30 +01:00
|
|
|
serve,
|
|
|
|
{
|
2021-02-12 08:20:45 +01:00
|
|
|
"document_root": os.path.join(settings.DEPLOY_ROOT, "var/node-coverage/lcov-report"),
|
|
|
|
"show_indexes": True,
|
2021-02-12 08:19:30 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
path(
|
2021-02-12 08:20:45 +01:00
|
|
|
"docs/<path:path>",
|
2021-02-12 08:19:30 +01:00
|
|
|
serve,
|
2021-02-12 08:20:45 +01:00
|
|
|
{"document_root": os.path.join(settings.DEPLOY_ROOT, "docs/_build/html")},
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
2017-06-02 21:44:09 +02:00
|
|
|
# The special no-password login endpoint for development
|
2021-04-16 17:37:13 +02:00
|
|
|
path(
|
|
|
|
"devlogin/",
|
|
|
|
login_page,
|
|
|
|
{"template_name": "zerver/development/dev_login.html"},
|
|
|
|
name="login_page",
|
|
|
|
),
|
2017-06-08 02:47:44 +02:00
|
|
|
# Page for testing email templates
|
2021-02-12 08:20:45 +01:00
|
|
|
path("emails/", email_page),
|
|
|
|
path("emails/generate/", generate_all_emails),
|
|
|
|
path("emails/clear/", clear_emails),
|
2017-06-14 02:01:01 +02:00
|
|
|
# Listing of useful URLs and various tools for development
|
2021-04-16 17:37:13 +02:00
|
|
|
path("devtools/", TemplateView.as_view(template_name="zerver/development/dev_tools.html")),
|
2021-05-10 07:02:14 +02:00
|
|
|
# Register new user and realm
|
2021-02-12 08:20:45 +01:00
|
|
|
path("devtools/register_user/", register_development_user, name="register_dev_user"),
|
|
|
|
path("devtools/register_realm/", register_development_realm, name="register_dev_realm"),
|
2021-08-13 20:37:15 +02:00
|
|
|
path(
|
|
|
|
"devtools/register_demo_realm/",
|
|
|
|
register_demo_development_realm,
|
|
|
|
name="register_demo_dev_realm",
|
|
|
|
),
|
2017-06-15 05:42:27 +02:00
|
|
|
# Have easy access for error pages
|
2021-02-12 08:20:45 +01:00
|
|
|
path("errors/404/", TemplateView.as_view(template_name="404.html")),
|
|
|
|
path("errors/5xx/", TemplateView.as_view(template_name="500.html")),
|
2020-03-28 01:25:56 +01:00
|
|
|
# Add a convenient way to generate webhook messages from fixtures.
|
2021-02-12 08:20:45 +01:00
|
|
|
path("devtools/integrations/", dev_panel),
|
2021-02-12 08:19:30 +01:00
|
|
|
path(
|
2021-02-12 08:20:45 +01:00
|
|
|
"devtools/integrations/check_send_webhook_fixture_message",
|
2021-02-12 08:19:30 +01:00
|
|
|
check_send_webhook_fixture_message,
|
|
|
|
),
|
|
|
|
path(
|
2021-02-12 08:20:45 +01:00
|
|
|
"devtools/integrations/send_all_webhook_fixture_messages", send_all_webhook_fixture_messages
|
2021-02-12 08:19:30 +01:00
|
|
|
),
|
2021-02-12 08:20:45 +01:00
|
|
|
path("devtools/integrations/<integration_name>/fixtures", get_fixtures),
|
|
|
|
path("config-error/<error_category_name>", config_error, name="config_error"),
|
|
|
|
path("config-error/remoteuser/<error_category_name>", config_error),
|
2021-03-24 12:18:30 +01:00
|
|
|
# Special endpoint to remove all the server-side caches.
|
|
|
|
path("flush_caches", remove_caches),
|
2021-05-07 00:38:24 +02:00
|
|
|
# Redirect camo URLs for development
|
|
|
|
path("external_content/<digest>/<received_url>", handle_camo_url),
|
2017-03-18 01:58:45 +01:00
|
|
|
]
|
2017-03-23 19:59:24 +01:00
|
|
|
|
2021-04-23 11:01:20 +02:00
|
|
|
v1_api_mobile_patterns = [
|
|
|
|
# This is for the signing in through the devAuthBackEnd on mobile apps.
|
|
|
|
path("dev_fetch_api_key", api_dev_fetch_api_key),
|
|
|
|
# This is for fetching the emails of the admins and the users.
|
|
|
|
path("dev_list_users", api_dev_list_users),
|
|
|
|
]
|
2019-07-18 11:27:16 +02:00
|
|
|
# Serve static assets via the Django server
|
|
|
|
if use_prod_static:
|
|
|
|
urls += [
|
2021-02-12 08:20:45 +01:00
|
|
|
path("static/<path:path>", serve, {"document_root": settings.STATIC_ROOT}),
|
2019-07-18 11:27:16 +02:00
|
|
|
]
|
|
|
|
else:
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-08-15 18:32:51 +02:00
|
|
|
def serve_static(request: HttpRequest, path: str) -> FileResponse:
|
2020-04-04 01:47:18 +02:00
|
|
|
response = staticfiles_serve(request, path)
|
|
|
|
response["Access-Control-Allow-Origin"] = "*"
|
|
|
|
return response
|
|
|
|
|
|
|
|
urls += static(urlsplit(settings.STATIC_URL).path, view=serve_static)
|
2019-07-18 11:27:16 +02:00
|
|
|
|
2017-03-18 01:58:45 +01:00
|
|
|
i18n_urls = [
|
2021-04-23 11:01:20 +02:00
|
|
|
path("accounts/login/local/", dev_direct_login, name="login-local"),
|
2021-02-12 08:20:45 +01:00
|
|
|
path("confirmation_key/", confirmation_key),
|
2017-03-18 01:58:45 +01:00
|
|
|
]
|
2020-09-01 02:56:35 +02:00
|
|
|
urls += i18n_urls
|