urls.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 django_rest_mfa.rest_auth_helpers.views import MFALoginView
  8. from organizations.backends import invitation_backend
  9. from rest_framework_nested import routers
  10. from apps.organizations_ext.urls import router as organizationsRouter
  11. from apps.projects.urls import router as projectsRouter
  12. from apps.users.urls import router as usersRouter
  13. from . import social
  14. from .api.api import api
  15. from .views import health
  16. router = routers.DefaultRouter()
  17. router.registry.extend(projectsRouter.registry)
  18. router.registry.extend(organizationsRouter.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/", include(router.urls)),
  43. ]
  44. if "django.contrib.admin" in settings.INSTALLED_APPS:
  45. urlpatterns += [
  46. path("admin/", include("django_rest_mfa.mfa_admin.urls")),
  47. path("admin/", admin.site.urls),
  48. ]
  49. if settings.BILLING_ENABLED:
  50. urlpatterns += [
  51. path("api/0/", include("apps.djstripe_ext.urls")),
  52. ]
  53. urlpatterns += [
  54. path("api/0/", include("apps.projects.urls")),
  55. path("api/0/", include("apps.users.urls")),
  56. path("api/0/", include("apps.organizations_ext.urls")),
  57. path("api/0/", include("apps.difs.urls")),
  58. path("api/mfa/", include("django_rest_mfa.urls")),
  59. path("", include("apps.uptime.urls")),
  60. path("api/test/", include("test_api.urls")),
  61. path("rest-auth/login/", MFALoginView.as_view()),
  62. path("rest-auth/", include("dj_rest_auth.urls")),
  63. path("rest-auth/registration/", include("dj_rest_auth.registration.urls")),
  64. path("rest-auth/<slug:provider>/", social.MFASocialLoginView().as_view()),
  65. path(
  66. "rest-auth/<slug:provider>/connect/",
  67. social.GlitchTipSocialConnectView().as_view(),
  68. ),
  69. path("accounts/", include("allauth.urls")),
  70. path("_allauth/", include("allauth.headless.urls")),
  71. # These routes belong to the Angular single page app
  72. re_path(r"^$", TemplateView.as_view(template_name="index.html")),
  73. re_path(
  74. r"^(auth|login|register|(.*)/issues|(.*)/settings|(.*)/performance|(.*)/projects|(.*)/releases|organizations|profile|(.*)/uptime-monitors|accept|reset-password).*$",
  75. TemplateView.as_view(template_name="index.html"),
  76. ),
  77. # These URLS are for generating reverse urls in django, but are not really present
  78. # Change the activate_url in the confirm emails
  79. re_path(
  80. r"^profile/confirm-email/(?P<key>[-:\w]+)/$",
  81. TemplateView.as_view(),
  82. name="account_confirm_email",
  83. ),
  84. # Change the password_reset_confirm in the reset password emails
  85. re_path(
  86. 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})/$",
  87. TemplateView.as_view(),
  88. name="password_reset_confirm",
  89. ),
  90. path("accept/", include(invitation_backend().get_urls())),
  91. path("api/0/observability/", include("apps.observability.urls")),
  92. ]
  93. if settings.BILLING_ENABLED:
  94. urlpatterns.append(path("stripe/", include("djstripe.urls", namespace="djstripe")))
  95. if settings.DEBUG_TOOLBAR:
  96. urlpatterns.append(path("__debug__/", include("debug_toolbar.urls")))
  97. if settings.DEBUG:
  98. urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)