urls.py 4.8 KB

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