Skip to content

: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.

feat(growth): list audit notebooks after first view (#110013)

Oliver Browne90359a820862
diff --git a/products/account_audits/backend/logic/service.py b/products/account_audits/backend/logic/service.py
index 504153890e40..5fd6f036bcef 100644
--- a/products/account_audits/backend/logic/service.py
+++ b/products/account_audits/backend/logic/service.py
@@ -108,7 +108,7 @@ class AccountAuditService:
text_content="",
created_by_id=actor_id,
last_modified_by_id=actor_id,
- visibility="internal",
+ visibility="unlisted",
creation_source="server",
)
run_id = create_audit_task(
diff --git a/products/account_audits/backend/tests/test_account_audits.py b/products/account_audits/backend/tests/test_account_audits.py
index b532fd4403c0..59670ee6d4f0 100644
--- a/products/account_audits/backend/tests/test_account_audits.py
+++ b/products/account_audits/backend/tests/test_account_audits.py
@@ -144,10 +144,12 @@ class TestAccountAuditStartAPI(APIBaseTest):
self.assertEqual(env.network_access_level, "custom")
self.assertEqual(env.allowed_domains, [])
self.assertFalse(env.include_default_domains)
+ listed = self.client.get(f"/api/projects/{self.team.id}/notebooks/")
+ self.assertNotIn(admission.notebook_short_id, [item["short_id"] for item in listed.json()["results"]])
notebook = self.client.get(f"/api/projects/{self.team.id}/notebooks/{admission.notebook_short_id}/")
self.assertEqual(notebook.status_code, 200)
listed = self.client.get(f"/api/projects/{self.team.id}/notebooks/")
- self.assertNotIn(admission.notebook_short_id, [item["short_id"] for item in listed.json()["results"]])
+ self.assertIn(admission.notebook_short_id, [item["short_id"] for item in listed.json()["results"]])
fresh = self._post({**payload, "team_id": self.team.id}, webhook_id="delivery-2")
self.assertEqual(fresh.status_code, 202)
self.assertNotEqual(fresh.json()["task_run_id"], first.json()["task_run_id"])
diff --git a/products/notebooks/backend/migrations/0027_notebook_unlisted_visibility.py b/products/notebooks/backend/migrations/0027_notebook_unlisted_visibility.py
new file mode 100644
index 000000000000..af0336d6b750
--- /dev/null
+++ b/products/notebooks/backend/migrations/0027_notebook_unlisted_visibility.py
@@ -0,0 +1,25 @@
+# Generated by Django 5.2.18 on 2026-10-22 14:06
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("notebooks", "0026_widget_snapshot"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="notebook",
+ name="visibility",
+ field=models.CharField(
+ choices=[
+ ("internal", "internal"),
+ ("default", "default"),
+ ("unlisted", "unlisted"),
+ ],
+ default="default",
+ max_length=20,
+ ),
+ ),
+ ]
diff --git a/products/notebooks/backend/migrations/max_migration.txt b/products/notebooks/backend/migrations/max_migration.txt
index 0b7b137820b3..89de1c0ff0ab 100644
--- a/products/notebooks/backend/migrations/max_migration.txt
+++ b/products/notebooks/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0026_widget_snapshot
+0027_notebook_unlisted_visibility
diff --git a/products/notebooks/backend/models.py b/products/notebooks/backend/models.py
index 9121ca2e0b05..5e2717b30be4 100644
--- a/products/notebooks/backend/models.py
+++ b/products/notebooks/backend/models.py
@@ -23,6 +23,8 @@ class Notebook(FileSystemSyncMixin, RootTeamMixin, UUIDTModel):
class Visibility(models.TextChoices):
INTERNAL = "internal", "internal"
DEFAULT = "default", "default"
+ # Hidden like INTERNAL until someone opens it in the app, then DEFAULT.
+ UNLISTED = "unlisted", "unlisted"
short_id = models.CharField(max_length=12, blank=True, default=generate_short_id)
team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE, related_name="+")
@@ -67,7 +69,7 @@ class Notebook(FileSystemSyncMixin, RootTeamMixin, UUIDTModel):
name=self.title or "Untitled",
href=f"/notebooks/{self.short_id}",
meta={"created_at": str(self.created_at), "created_by": self.created_by_id},
- should_delete=self.deleted or self.visibility == self.Visibility.INTERNAL,
+ should_delete=self.deleted or self.visibility != self.Visibility.DEFAULT,
)
diff --git a/products/notebooks/backend/presentation/views/notebook.py b/products/notebooks/backend/presentation/views/notebook.py
index 325725eceac5..1977b63f11b7 100644
--- a/products/notebooks/backend/presentation/views/notebook.py
+++ b/products/notebooks/backend/presentation/views/notebook.py
@@ -1513,6 +1513,9 @@ class NotebookViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, ForbidD
return Response(None, 304)
read_source, source_props = classify_request_source(request)
+ if read_source == NotebookCreationSource.UI and instance.visibility == Notebook.Visibility.UNLISTED:
+ instance.visibility = Notebook.Visibility.DEFAULT
+ instance.save(update_fields=["visibility"])
if read_source != NotebookCreationSource.UI:
# Browser opens are the client-side `notebook opened` event; only count programmatic
# (MCP / API) reads here so agent traffic doesn't inflate the human revisit numbers.
diff --git a/products/notebooks/backend/test/test_notebook_read_event.py b/products/notebooks/backend/test/test_notebook_read_event.py
index 213a967cdaf2..c20f36c063c7 100644
--- a/products/notebooks/backend/test/test_notebook_read_event.py
+++ b/products/notebooks/backend/test/test_notebook_read_event.py
@@ -1,11 +1,15 @@
from posthog.test.base import APIBaseTest
from unittest.mock import patch
+from parameterized import parameterized
from rest_framework import status
+from posthog.models import FileSystem
from posthog.models.personal_api_key import PersonalAPIKey
from posthog.models.utils import generate_random_token_personal, hash_key_value
+from products.notebooks.backend.models import Notebook
+
CAPTURE_PATH = "products.notebooks.backend.presentation.views.notebook.capture_notebook_read"
@@ -46,3 +50,33 @@ class TestNotebookReadEvent(APIBaseTest):
self.assertEqual(kwargs["short_id"], short_id)
self.assertEqual(kwargs["read_source"], "mcp")
self.assertEqual(kwargs["api_key_type"], "PersonalAPIKeyAuthentication")
+
+ @parameterized.expand(
+ [
+ ("unlisted_browser", Notebook.Visibility.UNLISTED, False, Notebook.Visibility.DEFAULT),
+ ("unlisted_api_key", Notebook.Visibility.UNLISTED, True, Notebook.Visibility.UNLISTED),
+ ("internal_browser", Notebook.Visibility.INTERNAL, False, Notebook.Visibility.INTERNAL),
+ ]
+ )
+ def test_browser_read_lists_an_unlisted_notebook(
+ self, _name: str, visibility: str, via_api_key: bool, expected: str
+ ) -> None:
+ notebook = Notebook.objects.create(team=self.team, visibility=visibility)
+ headers: dict[str, str] = {}
+ if via_api_key:
+ key_value = generate_random_token_personal()
+ PersonalAPIKey.objects.create(
+ user=self.user, label="read-key", secure_value=hash_key_value(key_value), scopes=["notebook:read"]
+ )
+ self.client.logout()
+ headers["Authorization"] = f"Bearer {key_value}"
+
+ response = self.client.get(self._url(notebook.short_id), headers=headers)
+
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ notebook.refresh_from_db()
+ self.assertEqual(notebook.visibility, expected)
+ self.assertEqual(
+ FileSystem.objects.filter(team=self.team, type="notebook", ref=notebook.short_id).exists(),
+ expected == Notebook.Visibility.DEFAULT,
+ )