Repository navigation
Expand file tree
/
Copy pathurls.py
More file actions
277 lines (255 loc) · 11.4 KB
/
Copy pathurls.py
File metadata and controls
277 lines (255 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
from typing import Any
from django.conf import settings
from django.contrib import admin
from django.contrib.admin.exceptions import NotRegistered
from django.urls import include, path, re_path
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import RedirectView
from django_otp.plugins.otp_static.models import StaticDevice
from django_otp.plugins.otp_totp.models import TOTPDevice
from posthog.admin import register_all_admin
from posthog.middleware import impersonated_session_logout
from posthog.views import api_key_search_view, redis_edit_ttl_view, redis_values_view
from products.cdp.backend.api import hooks
from ee.admin.loginas_views import loginas_user, upgrade_impersonation
from ee.admin.oauth_views import admin_auth_check, admin_oauth_success
from ee.api import integration
from ee.api.vercel import vercel_connect, vercel_sso, vercel_webhooks
from ee.middleware import admin_oauth2_callback
from ee.support_sidebar_max.views import MaxChatViewSet
from .api import authentication, billing, conversation, core_memory, license, subscription
from .api.rbac import role
from .api.scim import views as scim_views
def extend_api_router() -> None:
from posthog.api import (
organizations_router,
projects_router,
router as root_router,
)
from ee.api import hands_free, max_tools
root_router.register(r"billing", billing.BillingViewset, "billing")
root_router.register(r"license", license.LicenseViewSet)
root_router.register(r"integrations", integration.PublicIntegrationViewSet)
organization_roles_router = organizations_router.register(
r"roles",
role.RoleViewSet,
"organization_roles",
["organization_id"],
)
organization_roles_router.register(
r"role_memberships",
role.RoleMembershipViewSet,
"organization_role_memberships",
["organization_id", "role_id"],
)
projects_router.register(r"hooks", hooks.HookViewSet, "project_hooks", ["team_id"])
project_subscriptions_router = projects_router.register(
r"subscriptions", subscription.SubscriptionViewSet, "project_subscriptions", ["team_id"]
)
project_subscriptions_router.register(
r"deliveries",
subscription.SubscriptionDeliveryViewSet,
"project_subscription_deliveries",
["team_id", "subscription_id"],
)
projects_router.register(r"conversations", conversation.ConversationViewSet, "project_conversations", ["team_id"])
projects_router.register(r"core_memory", core_memory.MaxCoreMemoryViewSet, "project_core_memory", ["team_id"])
projects_router.register(r"max_tools", max_tools.MaxToolsViewSet, "project_max_tools", ["team_id"])
projects_router.register(r"max_hands_free", hands_free.MaxHandsFreeViewSet, "project_max_hands_free", ["team_id"])
# The admin interface is disabled on self-hosted instances, as its misuse can be unsafe
if settings.ADMIN_PORTAL_ENABLED:
# `AdminSite.get_urls()` derives the `admin:app_list` URL pattern from the registry
# when `admin.site.urls` below is read, and never rebuilds it. `LazyAdminRegistry`
# fills the registry first, but `posthog/apps.py` skips it under `settings.TEST`.
register_all_admin()
# these models are auto-registered but we don't want to expose them to staff
for model in (StaticDevice, TOTPDevice):
try:
admin.site.unregister(model)
except NotRegistered:
pass
from posthog.admin.admins.code_based_verification_bypass_admin import (
CodeBasedVerificationBypassViewSet,
CodeBasedVerificationGlobalDisableViewSet,
code_based_verification_bypass_view,
)
from posthog.admin.admins.distinct_id_usage_admin import distinct_id_usage_view
from posthog.admin.admins.health_check_admin import (
health_check_list_view,
health_check_runs_fragment_view,
health_check_trigger_view,
)
from posthog.admin.admins.notebook_markdown_migration_admin import (
notebook_markdown_migration_run_view,
notebook_markdown_migration_stats_view,
notebook_markdown_migration_view,
)
from posthog.admin.admins.radar_bypass_admin import RadarBypassViewSet, radar_bypass_view
from posthog.admin.admins.resave_cohorts_admin import resave_cohorts_view
from posthog.admin.admins.tophog_admin import tophog_dashboard_view, tophog_restrictions_view
admin_urlpatterns = [
# APPEND_SLASH is disabled globally, so redirect /admin to /admin/ explicitly
path("admin", RedirectView.as_view(url="/admin/", permanent=False, query_string=True)),
path("admin/oauth2/callback", admin_oauth2_callback, name="admin_oauth2_callback"),
path("admin/oauth2/success", admin_oauth_success, name="admin_oauth_success"),
path("admin/auth_check", admin_auth_check, name="admin_auth_check"),
path("admin/redisvalues", redis_values_view, name="redis_values"),
path("admin/redis/edit-ttl", redis_edit_ttl_view, name="redis_edit_ttl"),
path("admin/apikeysearch", api_key_search_view, name="api_key_search"),
path(
"admin/radar-bypass/",
admin.site.admin_view(radar_bypass_view),
name="radar-bypass",
),
path(
"admin/api/radar-bypass/",
RadarBypassViewSet.as_view({"get": "list", "post": "create"}),
name="radar-bypass-api-list",
),
path(
"admin/api/radar-bypass/<str:email>/",
RadarBypassViewSet.as_view({"delete": "destroy"}),
name="radar-bypass-api-detail",
),
path(
"admin/code-based-verification-bypass/",
admin.site.admin_view(code_based_verification_bypass_view),
name="code-based-verification-bypass",
),
path(
"admin/api/code-based-verification-bypass/",
CodeBasedVerificationBypassViewSet.as_view({"get": "list", "post": "create"}),
name="code-based-verification-bypass-api-list",
),
path(
"admin/api/code-based-verification-bypass/<str:email>/",
CodeBasedVerificationBypassViewSet.as_view({"delete": "destroy"}),
name="code-based-verification-bypass-api-detail",
),
path(
"admin/api/code-based-verification-global-disable/",
CodeBasedVerificationGlobalDisableViewSet.as_view({"get": "list", "post": "create", "delete": "destroy"}),
name="code-based-verification-global-disable-api",
),
path(
"admin/resave-cohorts/",
admin.site.admin_view(resave_cohorts_view),
name="resave-cohorts",
),
path(
"admin/distinct-id-usage/",
admin.site.admin_view(distinct_id_usage_view),
name="distinct-id-usage",
),
path(
"admin/tophog/",
admin.site.admin_view(tophog_dashboard_view),
name="tophog-dashboard",
),
path(
"admin/tophog/restrictions/",
admin.site.admin_view(tophog_restrictions_view),
name="tophog-restrictions",
),
path(
"admin/health-checks/",
admin.site.admin_view(health_check_list_view),
name="health-checks",
),
path(
"admin/health-checks/<str:kind>/",
admin.site.admin_view(health_check_trigger_view),
name="health-check-trigger",
),
path(
"admin/health-checks/<str:kind>/runs/",
admin.site.admin_view(health_check_runs_fragment_view),
name="health-check-runs",
),
path(
"admin/notebook-markdown-migration/",
admin.site.admin_view(notebook_markdown_migration_view),
name="notebook-markdown-migration",
),
path(
"admin/notebook-markdown-migration/stats/",
admin.site.admin_view(notebook_markdown_migration_stats_view),
name="notebook-markdown-migration-stats",
),
path(
"admin/notebook-markdown-migration/run/",
admin.site.admin_view(notebook_markdown_migration_run_view),
name="notebook-markdown-migration-run",
),
path(
"admin/logout/",
impersonated_session_logout,
name="loginas-logout",
),
path("admin/login/user/<str:user_id>/", loginas_user, name="loginas-user-login"),
path("admin/impersonation/upgrade/", upgrade_impersonation, name="impersonation-upgrade"),
# Temporary compatibility aliases for stable DuckgresServer admin URLs.
path(
"admin/posthog/duckgresserver/",
RedirectView.as_view(url="/admin/managed_warehouse/duckgresserver/", permanent=False, query_string=True),
),
path(
"admin/posthog/duckgresserver/<path:url_suffix>",
RedirectView.as_view(
url="/admin/managed_warehouse/duckgresserver/%(url_suffix)s",
permanent=False,
query_string=True,
),
),
path("admin/", include("loginas.urls")),
path("admin/", admin.site.urls),
]
else:
admin_urlpatterns = []
urlpatterns: list[Any] = [
path("api/saml/metadata/", authentication.saml_metadata_view),
path("max/chat/", csrf_exempt(MaxChatViewSet.as_view({"post": "create"})), name="max_chat"),
re_path(r"^login/vercel/?$", vercel_sso.VercelSSOViewSet.as_view({"get": "sso_redirect"})),
re_path(r"^login/vercel/continue/?$", vercel_sso.VercelSSOViewSet.as_view({"get": "sso_continue"})),
re_path(
r"^connect/vercel/callback/?$",
vercel_connect.VercelConnectCallbackViewSet.as_view({"get": "callback"}),
),
re_path(
r"^api/vercel/connect/complete/?$",
vercel_connect.VercelConnectLinkViewSet.as_view({"post": "complete"}),
),
re_path(
r"^api/vercel/connect/session/?$",
vercel_connect.VercelConnectLinkViewSet.as_view({"get": "session_info"}),
),
path("webhooks/vercel", csrf_exempt(vercel_webhooks.vercel_webhook), name="vercel_webhooks"),
path("scim/v2/<str:scim_slug>/Users", csrf_exempt(scim_views.SCIMUsersView.as_view()), name="scim_users"),
path(
"scim/v2/<str:scim_slug>/Users/<int:user_id>",
csrf_exempt(scim_views.SCIMUserDetailView.as_view()),
name="scim_user_detail",
),
path("scim/v2/<str:scim_slug>/Groups", csrf_exempt(scim_views.SCIMGroupsView.as_view()), name="scim_groups"),
path(
"scim/v2/<str:scim_slug>/Groups/<uuid:group_id>",
csrf_exempt(scim_views.SCIMGroupDetailView.as_view()),
name="scim_group_detail",
),
path(
"scim/v2/<str:scim_slug>/ServiceProviderConfig",
csrf_exempt(scim_views.SCIMServiceProviderConfigView.as_view()),
name="scim_service_provider_config",
),
path(
"scim/v2/<str:scim_slug>/ResourceTypes",
csrf_exempt(scim_views.SCIMResourceTypesView.as_view()),
name="scim_resource_types",
),
path("scim/v2/<str:scim_slug>/Schemas", csrf_exempt(scim_views.SCIMSchemasView.as_view()), name="scim_schemas"),
# Stripe Projects provisioning (APP 0.1d)
path("api/partners/stripe/", include("ee.partners.stripe.api.provisioning.urls")),
# Agentic provisioning (partner account/resource provisioning + deep-link login)
path("", include("ee.api.agentic_provisioning.urls")),
*admin_urlpatterns,
]