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
|
|
|
|
from django.http import HttpRequest, HttpResponse
|
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
|
|
|
|
2017-03-18 01:58:45 +01:00
|
|
|
import zerver.views.auth
|
2019-01-11 20:11:31 +01:00
|
|
|
import zerver.views.development.email_log
|
2019-04-14 15:28:19 +02:00
|
|
|
import zerver.views.development.integrations
|
2020-06-11 00:54:34 +02:00
|
|
|
import zerver.views.development.registration
|
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.)
|
2020-05-05 13:39:57 +02:00
|
|
|
path('coverage/<path:path>',
|
|
|
|
serve, {'document_root':
|
|
|
|
os.path.join(settings.DEPLOY_ROOT, 'var/coverage'),
|
|
|
|
'show_indexes': True}),
|
|
|
|
path('node-coverage/<path:path>',
|
|
|
|
serve, {'document_root':
|
|
|
|
os.path.join(settings.DEPLOY_ROOT, 'var/node-coverage/lcov-report'),
|
|
|
|
'show_indexes': True}),
|
|
|
|
path('docs/<path:path>',
|
|
|
|
serve, {'document_root':
|
|
|
|
os.path.join(settings.DEPLOY_ROOT, 'docs/_build/html')}),
|
2017-06-02 21:44:09 +02:00
|
|
|
|
|
|
|
# The special no-password login endpoint for development
|
2020-05-05 13:39:57 +02:00
|
|
|
path('devlogin/', zerver.views.auth.login_page,
|
|
|
|
{'template_name': 'zerver/dev_login.html'}, name='zerver.views.auth.login_page'),
|
2017-06-08 02:47:44 +02:00
|
|
|
|
|
|
|
# Page for testing email templates
|
2020-05-05 13:39:57 +02:00
|
|
|
path('emails/', zerver.views.development.email_log.email_page),
|
|
|
|
path('emails/generate/', zerver.views.development.email_log.generate_all_emails),
|
|
|
|
path('emails/clear/', zerver.views.development.email_log.clear_emails),
|
2017-06-14 02:01:01 +02:00
|
|
|
|
|
|
|
# Listing of useful URLs and various tools for development
|
2020-05-05 13:39:57 +02:00
|
|
|
path('devtools/', TemplateView.as_view(template_name='zerver/dev_tools.html')),
|
2019-03-13 18:26:01 +01:00
|
|
|
# Register New User and Realm
|
2020-05-05 13:39:57 +02:00
|
|
|
path('devtools/register_user/',
|
|
|
|
zerver.views.development.registration.register_development_user,
|
|
|
|
name='zerver.views.development.registration.register_development_user'),
|
|
|
|
path('devtools/register_realm/',
|
|
|
|
zerver.views.development.registration.register_development_realm,
|
|
|
|
name='zerver.views.development.registration.register_development_realm'),
|
2017-06-15 05:42:27 +02:00
|
|
|
|
|
|
|
# Have easy access for error pages
|
2020-05-05 13:39:57 +02:00
|
|
|
path('errors/404/', TemplateView.as_view(template_name='404.html')),
|
|
|
|
path('errors/5xx/', TemplateView.as_view(template_name='500.html')),
|
2019-04-14 15:28:19 +02:00
|
|
|
|
2020-03-28 01:25:56 +01:00
|
|
|
# Add a convenient way to generate webhook messages from fixtures.
|
2020-05-05 13:39:57 +02:00
|
|
|
path('devtools/integrations/', zerver.views.development.integrations.dev_panel),
|
|
|
|
path('devtools/integrations/check_send_webhook_fixture_message',
|
|
|
|
zerver.views.development.integrations.check_send_webhook_fixture_message),
|
|
|
|
path('devtools/integrations/send_all_webhook_fixture_messages',
|
|
|
|
zerver.views.development.integrations.send_all_webhook_fixture_messages),
|
2020-09-12 04:25:00 +02:00
|
|
|
path('devtools/integrations/<integration_name>/fixtures',
|
2020-05-05 13:39:57 +02:00
|
|
|
zerver.views.development.integrations.get_fixtures),
|
2017-03-18 01:58:45 +01:00
|
|
|
]
|
2017-03-23 19:59:24 +01:00
|
|
|
|
2019-07-18 11:27:16 +02:00
|
|
|
# Serve static assets via the Django server
|
|
|
|
if use_prod_static:
|
|
|
|
urls += [
|
2020-09-12 04:18:53 +02:00
|
|
|
path('static/<path:path>', serve, {'document_root': settings.STATIC_ROOT}),
|
2019-07-18 11:27:16 +02:00
|
|
|
]
|
|
|
|
else:
|
2020-04-04 01:47:18 +02:00
|
|
|
def serve_static(request: HttpRequest, path: str) -> HttpResponse:
|
|
|
|
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 = [
|
2020-05-05 13:39:57 +02:00
|
|
|
path('confirmation_key/', zerver.views.development.registration.confirmation_key),
|
2017-03-18 01:58:45 +01:00
|
|
|
]
|
2020-09-01 02:56:35 +02:00
|
|
|
urls += i18n_urls
|
2016-06-25 03:44:32 +02:00
|
|
|
|
2020-01-30 21:23:36 +01:00
|
|
|
# On a production instance, these files would be served by nginx.
|
2016-06-25 03:44:32 +02:00
|
|
|
if settings.LOCAL_UPLOADS_DIR is not None:
|
2020-09-12 04:18:53 +02:00
|
|
|
avatars_url = path(
|
|
|
|
'user_avatars/<path:path>',
|
2020-09-12 06:32:57 +02:00
|
|
|
serve,
|
|
|
|
{'document_root': os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars")},
|
|
|
|
)
|
|
|
|
urls += [avatars_url]
|