:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(hogbox-preview): enable Django admin on preview boxes (#96628)
Julian Bez1a3b00285567
diff --git a/tools/hogbox-preview/hogbox_preview/stack.py b/tools/hogbox-preview/hogbox_preview/stack.pyindex dbbdefd7f698..d142267cf62b 100644--- a/tools/hogbox-preview/hogbox_preview/stack.py+++ b/tools/hogbox-preview/hogbox_preview/stack.py@@ -333,6 +333,15 @@ class PostHogPreviewStack:# companion settings change that reads this from the env; it's an# inert no-op on an image that predates it." - USE_LOCAL_SETUP=1",+ # ee/urls.py registers /admin/* only when ADMIN_PORTAL_ENABLED is true,+ # and ee/settings.py defaults it to DEMO or DEBUG — both false here. So+ # without this, Django has no /admin route at all: the request falls+ # through to the SPA, which prefixes any path it doesn't know with the+ # project id, and /admin lands on /project/1/admin. A box reaches admin+ # only over the tailnet (hogland's box-front is an internal NLB behind+ # split-DNS), and the seeded demo user is staff, so /admin is as exposed+ # as the rest of the preview and no more.+ " - ADMIN_PORTAL_ENABLED=1",]lines += [" plugins:",diff --git a/tools/hogbox-preview/tests/test_stack_admin_portal.py b/tools/hogbox-preview/tests/test_stack_admin_portal.pynew file mode 100644index 000000000000..1519e1d9f98a--- /dev/null+++ b/tools/hogbox-preview/tests/test_stack_admin_portal.py@@ -0,0 +1,48 @@+"""Unit tests for the Django admin flag in the preview stack env.++Self-contained: no network, no live box. ``write_override`` only touches+``backend.write_file``, so a recording fake backend is enough to assert the+generated compose override turns the admin portal on — without it, ee/urls.py+registers no /admin route and the SPA rewrites /admin to /project/1/admin.++ cd tools/hogbox-preview && python -m unittest discover tests+"""++from __future__ import annotations++import unittest++# Importing the package pulls hogland_backend, which needs the posthog-hogland+# SDK (installed per-run via `uv run --with`, not a repo dependency). Guard the+# import so the monorepo's Django pytest collection can't hard-fail here.+try:+ from hogbox_preview.stack import PostHogPreviewStack++ HAVE_SDK = True+except ImportError:+ HAVE_SDK = False+++class _RecordingBackend:+ """Duck-typed stand-in for a PreviewBackend: write_override only calls+ write_file, so that's all the stack needs from us here."""++ def __init__(self):+ self.files: dict[str, str] = {}++ def write_file(self, remote_path, content) -> None:+ self.files[remote_path] = content if isinstance(content, str) else content.decode()++[email protected](HAVE_SDK, "posthog-hogland SDK not installed")+class PreviewAdminPortalTest(unittest.TestCase):+ def test_override_enables_the_admin_portal(self):+ backend = _RecordingBackend()+ stack = PostHogPreviewStack(backend)+ stack.write_override()+ override = backend.files[f"{stack.repo_dir}/{stack.OVERRIDE}"]+ self.assertIn("- ADMIN_PORTAL_ENABLED=1", override)+++if __name__ == "__main__":+ unittest.main()