urls.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 drf_yasg import openapi
  9. from drf_yasg.views import get_schema_view
  10. from organizations.backends import invitation_backend
  11. from rest_framework import permissions
  12. from rest_framework_nested import routers
  13. from api_tokens.urls import router as apiTokensRouter
  14. from issues.urls import router as issuesRouter
  15. from issues.views import EventJsonView
  16. from organizations_ext.urls import router as organizationsRouter
  17. from projects.urls import router as projectsRouter
  18. from teams.urls import router as teamsRouter
  19. from users.urls import router as usersRouter
  20. from users.views import SocialAccountDisconnectView
  21. from . import social
  22. from .views import APIRootView, SettingsView, health
  23. from .yasg import CustomOpenAPISchemaGenerator
  24. router = routers.DefaultRouter()
  25. router.registry.extend(projectsRouter.registry)
  26. router.registry.extend(issuesRouter.registry)
  27. router.registry.extend(organizationsRouter.registry)
  28. router.registry.extend(teamsRouter.registry)
  29. router.registry.extend(usersRouter.registry)
  30. router.registry.extend(apiTokensRouter.registry)
  31. if settings.BILLING_ENABLED:
  32. from djstripe_ext.urls import router as djstripeRouter
  33. router.registry.extend(djstripeRouter.registry)
  34. schema_view = get_schema_view(
  35. openapi.Info(
  36. title="GlitchTip API",
  37. default_version="v1",
  38. description="GlitchTip Backend API",
  39. terms_of_service="https://glitchtip.com",
  40. contact=openapi.Contact(email="info@burkesoftware.com"),
  41. license=openapi.License(name="MIT License"),
  42. ),
  43. public=True,
  44. permission_classes=(permissions.AllowAny,),
  45. generator_class=CustomOpenAPISchemaGenerator,
  46. )
  47. urlpatterns = [
  48. path("_health/", health),
  49. path("admin/", include("django_rest_mfa.mfa_admin.urls")),
  50. path("admin/", admin.site.urls),
  51. re_path(
  52. r"^favicon\.ico$",
  53. RedirectView.as_view(url=settings.STATIC_URL + "favicon.ico", permanent=True),
  54. ),
  55. path(
  56. "robots.txt",
  57. TemplateView.as_view(template_name="robots.txt", content_type="text/plain"),
  58. ),
  59. path("api/", RedirectView.as_view(url="/profile/auth-tokens")),
  60. path("api/0/", APIRootView.as_view(), name="api-root-view"),
  61. path("api/0/", include(router.urls)),
  62. ]
  63. if settings.BILLING_ENABLED:
  64. urlpatterns += [
  65. path("api/0/", include("djstripe_ext.urls")),
  66. ]
  67. urlpatterns += [
  68. path("api/0/", include("projects.urls")),
  69. path("api/0/", include("issues.urls")),
  70. path("api/0/", include("users.urls")),
  71. path("api/0/", include("organizations_ext.urls")),
  72. path("api/0/", include("teams.urls")),
  73. path("api/0/", include("api_tokens.urls")),
  74. path("api/0/", include("files.urls")),
  75. path("api/0/", include("difs.urls")),
  76. path("api/0/", include("glitchtip.importer.urls")),
  77. path("api/0/", include("glitchtip.stats.urls")),
  78. path("api/0/", include("glitchtip.wizard.urls")),
  79. path("api/mfa/", include("django_rest_mfa.urls")),
  80. path("api/", include("events.urls")),
  81. path("api/embed/", include("user_reports.urls")),
  82. path("", include("glitchtip.uptime.urls")),
  83. # What an oddball API endpoint
  84. path(
  85. "organizations/<slug:org>/issues/<int:issue>/events/<str:event>/json/",
  86. EventJsonView.as_view(),
  87. name="event_json",
  88. ),
  89. path("api/settings/", SettingsView.as_view(), name="settings"),
  90. path("rest-auth/login/", MFALoginView.as_view()),
  91. path("rest-auth/", include("dj_rest_auth.urls")),
  92. path("rest-auth/registration/", include("dj_rest_auth.registration.urls")),
  93. re_path(
  94. r"^api/socialaccounts/(?P<pk>\d+)/disconnect/$",
  95. SocialAccountDisconnectView.as_view(),
  96. name="social_account_disconnect",
  97. ),
  98. path("rest-auth/<slug:provider>/", social.MFASocialLoginView().as_view()),
  99. path(
  100. "rest-auth/<slug:provider>/connect/",
  101. social.GlitchTipSocialConnectView().as_view(),
  102. ),
  103. path("docs/", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc"),
  104. path("accounts/", include("allauth.urls")), # Required for allauth
  105. # These routes belong to the Angular single page app
  106. re_path(r"^$", TemplateView.as_view(template_name="index.html")),
  107. re_path(
  108. r"^(auth|login|register|(.*)/issues|(.*)/settings|(.*)/performance|(.*)/projects|(.*)/releases|organizations|profile|(.*)/uptime-monitors|accept|reset-password).*$",
  109. TemplateView.as_view(template_name="index.html"),
  110. ),
  111. # These URLS are for generating reverse urls in django, but are not really present
  112. # Change the activate_url in the confirm emails
  113. re_path(
  114. r"^profile/confirm-email/(?P<key>[-:\w]+)/$",
  115. TemplateView.as_view(),
  116. name="account_confirm_email",
  117. ),
  118. # Change the password_reset_confirm in the reset password emails
  119. re_path(
  120. 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})/$",
  121. TemplateView.as_view(),
  122. name="password_reset_confirm",
  123. ),
  124. path("accept/", include(invitation_backend().get_urls())),
  125. path("api/0/observability/", include("observability.urls")),
  126. ]
  127. if settings.BILLING_ENABLED:
  128. urlpatterns.append(path("stripe/", include("djstripe.urls", namespace="djstripe")))
  129. if settings.ENABLE_TEST_API:
  130. urlpatterns.append(path("api/test/", include("test_api.urls")))
  131. if settings.DEBUG_TOOLBAR:
  132. urlpatterns.append(path("__debug__/", include("debug_toolbar.urls")))
  133. if settings.DEBUG:
  134. urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)