urls.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. from django.conf import settings
  2. from django.conf.urls.static import static
  3. from django.contrib import admin
  4. from django.urls import include, path, re_path
  5. from django.views.generic import TemplateView
  6. from django.views.generic.base import RedirectView
  7. from organizations.backends import invitation_backend
  8. from rest_framework_nested import routers
  9. from apps.organizations_ext.urls import router as organizationsRouter
  10. from apps.projects.urls import router as projectsRouter
  11. from apps.teams.urls import router as teamsRouter
  12. from apps.users.urls import router as usersRouter
  13. from .api import api
  14. from .views import APIRootView, health
  15. router = routers.DefaultRouter()
  16. router.registry.extend(projectsRouter.registry)
  17. router.registry.extend(organizationsRouter.registry)
  18. router.registry.extend(teamsRouter.registry)
  19. router.registry.extend(usersRouter.registry)
  20. if settings.BILLING_ENABLED:
  21. from apps.djstripe_ext.urls import router as djstripeRouter
  22. router.registry.extend(djstripeRouter.registry)
  23. urlpatterns = [
  24. path("_health/", health),
  25. re_path(
  26. r"^favicon\.ico$",
  27. RedirectView.as_view(url=settings.STATIC_URL + "favicon.ico", permanent=True),
  28. ),
  29. path(
  30. "robots.txt",
  31. TemplateView.as_view(template_name="robots.txt", content_type="text/plain"),
  32. ),
  33. path("api/", RedirectView.as_view(url="/profile/auth-tokens")),
  34. # OSS Sentry compat - redirect the non-api prefix url to the more typical api prefix
  35. path(
  36. "organizations/<slug:organization_slug>/issues/<int:issue_id>/events/<event_id>/json/",
  37. RedirectView.as_view(
  38. url="/api/0/organizations/%(organization_slug)s/issues/%(issue_id)s/events/%(event_id)s/json/",
  39. ),
  40. ),
  41. path("api/", api.urls),
  42. path("api/0/", APIRootView.as_view(), name="api-root-view"),
  43. path("api/0/", include(router.urls)),
  44. ]
  45. if "django.contrib.admin" in settings.INSTALLED_APPS:
  46. urlpatterns += [
  47. path("admin/", include("django_rest_mfa.mfa_admin.urls")),
  48. path("admin/", admin.site.urls),
  49. ]
  50. if settings.BILLING_ENABLED:
  51. urlpatterns += [
  52. path("api/0/", include("apps.djstripe_ext.urls")),
  53. ]
  54. urlpatterns += [
  55. path("api/0/", include("apps.projects.urls")),
  56. path("api/0/", include("apps.users.urls")),
  57. path("api/0/", include("apps.organizations_ext.urls")),
  58. path("api/0/", include("apps.teams.urls")),
  59. path("api/0/", include("apps.files.urls")),
  60. path("api/0/", include("apps.difs.urls")),
  61. path("api/0/", include("apps.stats.urls")),
  62. path("api/0/", include("apps.wizard.urls")),
  63. path("api/mfa/", include("django_rest_mfa.urls")),
  64. path("", include("apps.uptime.urls")),
  65. path("api/test/", include("test_api.urls")),
  66. path("accounts/", include("allauth.urls")),
  67. path("_allauth/", include("allauth.headless.urls")),
  68. # These routes belong to the Angular single page app
  69. re_path(r"^$", TemplateView.as_view(template_name="index.html")),
  70. re_path(
  71. r"^(auth|login|register|(.*)/issues|(.*)/settings|(.*)/performance|(.*)/projects|(.*)/releases|organizations|profile|(.*)/uptime-monitors|accept|reset-password).*$",
  72. TemplateView.as_view(template_name="index.html"),
  73. ),
  74. # These URLS are for generating reverse urls in django, but are not really present
  75. # Change the activate_url in the confirm emails
  76. re_path(
  77. r"^profile/confirm-email/(?P<key>[-:\w]+)/$",
  78. TemplateView.as_view(),
  79. name="account_confirm_email",
  80. ),
  81. # Change the password_reset_confirm in the reset password emails
  82. re_path(
  83. r"^reset-password/set-new-password/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,93}-[0-9A-Za-z]{1,90})/$",
  84. TemplateView.as_view(),
  85. name="password_reset_confirm",
  86. ),
  87. path("accept/", include(invitation_backend().get_urls())),
  88. path("api/0/observability/", include("apps.observability.urls")),
  89. ]
  90. if settings.BILLING_ENABLED:
  91. urlpatterns.append(path("stripe/", include("djstripe.urls", namespace="djstripe")))
  92. if settings.DEBUG_TOOLBAR:
  93. urlpatterns.append(path("__debug__/", include("debug_toolbar.urls")))
  94. if settings.DEBUG:
  95. urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)