urls.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.teams.urls import router as teamsRouter
  13. from apps.users.urls import router as usersRouter
  14. from apps.users.views import SocialAccountDisconnectView
  15. from . import social
  16. from .api import api
  17. from .views import APIRootView, health
  18. router = routers.DefaultRouter()
  19. router.registry.extend(projectsRouter.registry)
  20. router.registry.extend(organizationsRouter.registry)
  21. router.registry.extend(teamsRouter.registry)
  22. router.registry.extend(usersRouter.registry)
  23. if settings.BILLING_ENABLED:
  24. from apps.djstripe_ext.urls import router as djstripeRouter
  25. router.registry.extend(djstripeRouter.registry)
  26. urlpatterns = [
  27. path("_health/", health),
  28. re_path(
  29. r"^favicon\.ico$",
  30. RedirectView.as_view(url=settings.STATIC_URL + "favicon.ico", permanent=True),
  31. ),
  32. path(
  33. "robots.txt",
  34. TemplateView.as_view(template_name="robots.txt", content_type="text/plain"),
  35. ),
  36. path("api/", RedirectView.as_view(url="/profile/auth-tokens")),
  37. # OSS Sentry compat - redirect the non-api prefix url to the more typical api prefix
  38. path(
  39. "organizations/<slug:organization_slug>/issues/<int:issue_id>/events/<event_id>/json/",
  40. RedirectView.as_view(
  41. url="/api/0/organizations/%(organization_slug)s/issues/%(issue_id)s/events/%(event_id)s/json/",
  42. ),
  43. ),
  44. path("api/", api.urls),
  45. path("api/0/", APIRootView.as_view(), name="api-root-view"),
  46. path("api/0/", include(router.urls)),
  47. ]
  48. if "django.contrib.admin" in settings.INSTALLED_APPS:
  49. urlpatterns += [
  50. path("admin/", include("django_rest_mfa.mfa_admin.urls")),
  51. path("admin/", admin.site.urls),
  52. ]
  53. if settings.BILLING_ENABLED:
  54. urlpatterns += [
  55. path("api/0/", include("apps.djstripe_ext.urls")),
  56. ]
  57. urlpatterns += [
  58. path("api/0/", include("apps.projects.urls")),
  59. path("api/0/", include("apps.users.urls")),
  60. path("api/0/", include("apps.organizations_ext.urls")),
  61. path("api/0/", include("apps.teams.urls")),
  62. path("api/0/", include("apps.files.urls")),
  63. path("api/0/", include("apps.difs.urls")),
  64. path("api/0/", include("apps.stats.urls")),
  65. path("api/0/", include("apps.wizard.urls")),
  66. path("api/mfa/", include("django_rest_mfa.urls")),
  67. path("", include("apps.uptime.urls")),
  68. path("api/test/", include("test_api.urls")),
  69. path("rest-auth/login/", MFALoginView.as_view()),
  70. path("rest-auth/", include("dj_rest_auth.urls")),
  71. path("rest-auth/registration/", include("dj_rest_auth.registration.urls")),
  72. re_path(
  73. r"^api/socialaccounts/(?P<pk>\d+)/disconnect/$",
  74. SocialAccountDisconnectView.as_view(),
  75. name="social_account_disconnect",
  76. ),
  77. path("rest-auth/<slug:provider>/", social.MFASocialLoginView().as_view()),
  78. path(
  79. "rest-auth/<slug:provider>/connect/",
  80. social.GlitchTipSocialConnectView().as_view(),
  81. ),
  82. path("accounts/", include("allauth.urls")), # Required for allauth
  83. # These routes belong to the Angular single page app
  84. re_path(r"^$", TemplateView.as_view(template_name="index.html")),
  85. re_path(
  86. r"^(auth|login|register|(.*)/issues|(.*)/settings|(.*)/performance|(.*)/projects|(.*)/releases|organizations|profile|(.*)/uptime-monitors|accept|reset-password).*$",
  87. TemplateView.as_view(template_name="index.html"),
  88. ),
  89. # These URLS are for generating reverse urls in django, but are not really present
  90. # Change the activate_url in the confirm emails
  91. re_path(
  92. r"^profile/confirm-email/(?P<key>[-:\w]+)/$",
  93. TemplateView.as_view(),
  94. name="account_confirm_email",
  95. ),
  96. # Change the password_reset_confirm in the reset password emails
  97. re_path(
  98. 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})/$",
  99. TemplateView.as_view(),
  100. name="password_reset_confirm",
  101. ),
  102. path("accept/", include(invitation_backend().get_urls())),
  103. path("api/0/observability/", include("apps.observability.urls")),
  104. ]
  105. if settings.BILLING_ENABLED:
  106. urlpatterns.append(path("stripe/", include("djstripe.urls", namespace="djstripe")))
  107. if settings.DEBUG_TOOLBAR:
  108. urlpatterns.append(path("__debug__/", include("debug_toolbar.urls")))
  109. if settings.DEBUG:
  110. urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)