urls.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. from django.conf import settings
  2. from django.contrib import admin
  3. from django.urls import path, include, re_path
  4. from django.views.generic import TemplateView
  5. from django.views.generic.base import RedirectView
  6. from rest_framework import permissions
  7. from rest_framework_nested import routers
  8. from organizations.backends import invitation_backend
  9. from drf_yasg.views import get_schema_view
  10. from drf_yasg import openapi
  11. from issues.urls import router as issuesRouter
  12. from issues.views import EventJsonView
  13. from projects.urls import router as projectsRouter
  14. from teams.urls import router as teamsRouter
  15. from organizations_ext.urls import router as organizationsRouter
  16. from users.urls import router as usersRouter
  17. from api_tokens.urls import router as apiTokensRouter
  18. from users.views import SocialAccountDisconnectView
  19. from . import social
  20. from .yasg import CustomOpenAPISchemaGenerator
  21. from .views import SettingsView, health, APIRootView
  22. router = routers.DefaultRouter()
  23. router.registry.extend(projectsRouter.registry)
  24. router.registry.extend(issuesRouter.registry)
  25. router.registry.extend(organizationsRouter.registry)
  26. router.registry.extend(teamsRouter.registry)
  27. router.registry.extend(usersRouter.registry)
  28. router.registry.extend(apiTokensRouter.registry)
  29. if settings.BILLING_ENABLED:
  30. from djstripe_ext.urls import router as djstripeRouter
  31. router.registry.extend(djstripeRouter.registry)
  32. schema_view = get_schema_view(
  33. openapi.Info(
  34. title="GlitchTip API",
  35. default_version="v1",
  36. description="GlitchTip Backend API",
  37. terms_of_service="https://glitchtip.com",
  38. contact=openapi.Contact(email="info@burkesoftware.com"),
  39. license=openapi.License(name="MIT License"),
  40. ),
  41. public=True,
  42. permission_classes=(permissions.AllowAny,),
  43. generator_class=CustomOpenAPISchemaGenerator,
  44. )
  45. urlpatterns = [
  46. path("_health/", health),
  47. path("admin/", admin.site.urls),
  48. re_path(
  49. r"^favicon\.ico$",
  50. RedirectView.as_view(url=settings.STATIC_URL + "/favicon.ico", permanent=True),
  51. ),
  52. path("api/", RedirectView.as_view(url="/profile/auth-tokens")),
  53. path("api/0/", APIRootView.as_view()),
  54. path("api/0/", include(router.urls)),
  55. ]
  56. if settings.BILLING_ENABLED:
  57. urlpatterns += [
  58. path("api/0/", include("djstripe_ext.urls")),
  59. ]
  60. urlpatterns += [
  61. path("api/0/", include("projects.urls")),
  62. path("api/0/", include("issues.urls")),
  63. path("api/0/", include("users.urls")),
  64. path("api/0/", include("organizations_ext.urls")),
  65. path("api/0/", include("teams.urls")),
  66. path("api/0/", include("api_tokens.urls")),
  67. path("api/", include("events.urls")),
  68. path("api/embed/", include("user_reports.urls")),
  69. # What an oddball API endpoint
  70. path(
  71. "organizations/<slug:org>/issues/<int:issue>/events/<str:event>/json/",
  72. EventJsonView.as_view(),
  73. name="event_json",
  74. ),
  75. path("api/settings/", SettingsView.as_view(), name="settings"),
  76. path("rest-auth/", include("dj_rest_auth.urls")),
  77. path("rest-auth/registration/", include("dj_rest_auth.registration.urls")),
  78. path("api/api-auth/", include("rest_framework.urls", namespace="rest_framework")),
  79. re_path(
  80. r"^api/socialaccounts/(?P<pk>\d+)/disconnect/$",
  81. SocialAccountDisconnectView.as_view(),
  82. name="social_account_disconnect",
  83. ),
  84. path("rest-auth/gitlab/", social.GitlabLogin.as_view(), name="gitlab_login"),
  85. path(
  86. "rest-auth/gitlab/connect/",
  87. social.GitlabConnect.as_view(),
  88. name="gitlab_connect",
  89. ),
  90. path("rest-auth/github/", social.GithubLogin.as_view(), name="github_login"),
  91. path(
  92. "rest-auth/github/connect/",
  93. social.GithubConnect.as_view(),
  94. name="github_connect",
  95. ),
  96. path("rest-auth/google/", social.GoogleLogin.as_view(), name="google_login"),
  97. path(
  98. "rest-auth/google/connect/",
  99. social.GoogleConnect.as_view(),
  100. name="google_connect",
  101. ),
  102. path(
  103. "rest-auth/microsoft/", social.MicrosoftLogin.as_view(), name="microsoft_login"
  104. ),
  105. path(
  106. "rest-auth/microsoft/connect/",
  107. social.MicrosoftConnect.as_view(),
  108. name="microsoft_connect",
  109. ),
  110. path("docs/", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc"),
  111. path("accounts/", include("allauth.urls")), # Required for allauth
  112. # These routes belong to the Angular single page app
  113. re_path(r"^$", TemplateView.as_view(template_name="index.html")),
  114. re_path(
  115. r"^(auth|login|register|issues|settings|organizations|profile|accept|reset-password).*$",
  116. TemplateView.as_view(template_name="index.html"),
  117. ),
  118. # Change the activate_url in the confirm emails
  119. re_path(
  120. r"^profile/confirm-email/(?P<key>[-:\w]+)/$",
  121. TemplateView.as_view(),
  122. name="account_confirm_email",
  123. ),
  124. # Change the password_reset_confirm in the reset password emails
  125. re_path(
  126. 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})/$",
  127. TemplateView.as_view(),
  128. name="password_reset_confirm",
  129. ),
  130. path("accept/", include(invitation_backend().get_urls())),
  131. ]
  132. if settings.BILLING_ENABLED:
  133. urlpatterns.append(path("stripe/", include("djstripe.urls", namespace="djstripe")))
  134. if settings.ENABLE_TEST_API:
  135. urlpatterns.append(path("api/test/", include("test_api.urls")))
  136. if settings.DEBUG:
  137. import debug_toolbar
  138. urlpatterns = [
  139. path("__debug__/", include(debug_toolbar.urls)),
  140. # For django versions before 2.0:
  141. # url(r'^__debug__/', include(debug_toolbar.urls)),
  142. ] + urlpatterns