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(tasks): Let any member filter to internal tasks (#67684)

Michael Matloka3558c64046d1
diff --git a/frontend/src/scenes/inbox/inboxSceneLogic.ts b/frontend/src/scenes/inbox/inboxSceneLogic.ts
index a78f12aabc6e..87ba86c5119f 100644
--- a/frontend/src/scenes/inbox/inboxSceneLogic.ts
+++ b/frontend/src/scenes/inbox/inboxSceneLogic.ts
@@ -181,8 +181,7 @@ interface InboxOpenTracking {
/**
* Inbox scene orchestrator. Owns the active tab, the selected report (loaded by id),
* the project-wide Runs list, and session-analysis. The per-tab report
- * lists + their counts live in the keyed `reportListLogic` (one instance per flat tab),
- * so this logic no longer holds a shared report list.
+ * lists + their counts live in the keyed `reportListLogic` (one instance per flat tab).
*/
export const inboxSceneLogic = kea<inboxSceneLogicType>([
path(['scenes', 'inbox', 'inboxSceneLogic']),
diff --git a/products/posthog_ai/frontend/types/taskTypes.ts b/products/posthog_ai/frontend/types/taskTypes.ts
index 1940bd477b2b..2e46b0896bf7 100644
--- a/products/posthog_ai/frontend/types/taskTypes.ts
+++ b/products/posthog_ai/frontend/types/taskTypes.ts
@@ -103,7 +103,7 @@ export interface TaskListParams {
organization?: string
stage?: string
origin_product?: string
- /** `all` includes internal tasks (shown-by-default flag, not an access gate); `true` is a staff-only internal-only view. */
+ /** `all` includes internal tasks (shown-by-default flag, not an access gate); `true` narrows to only-internal tasks. */
internal?: 'true' | 'false' | 'all'
search?: string
status?: TaskRunStatus
diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.py
index 30b8ac55af8a..677dce20b8d3 100644
--- a/products/tasks/backend/facade/api.py
+++ b/products/tasks/backend/facade/api.py
@@ -2592,9 +2592,7 @@ async def select_repository_for_message(team_id: int, user_id: int, message: str
)
-def _list_tasks_queryset(
- team_id: int, user_id: int | None, *, filters: dict, is_debug_or_staff: bool
-) -> QuerySet[Task]:
+def _list_tasks_queryset(team_id: int, user_id: int | None, *, filters: dict) -> QuerySet[Task]:
latest_run = TaskRun.objects.filter(task=OuterRef("pk"), team_id=team_id).order_by("-created_at", "-id")
qs = _visible_task_qs(team_id, user_id).order_by("-created_at", "-id")
@@ -2641,12 +2639,12 @@ def _list_tasks_queryset(
qs = qs.annotate(_latest_run_status=Subquery(latest_run_status)).filter(_latest_run_status=status_filter)
# `internal` controls default visibility, not access — task visibility (applied above) is the real
- # authorization boundary. `all` returns both and is open to any team member; `true` (only-internal)
- # stays a staff/debug view; the default excludes internal tasks so the main task list stays clean.
+ # authorization boundary, open to any team member. `all` returns both, `true` returns only-internal,
+ # and the default excludes internal tasks so the main task list stays clean.
internal_param = filters.get("internal")
if internal_param == "all":
pass
- elif internal_param == "true" and is_debug_or_staff:
+ elif internal_param == "true":
qs = qs.filter(internal=True)
else:
qs = qs.filter(internal=False)
@@ -2691,13 +2689,9 @@ def _tasks_to_dtos(tasks: Iterable[Task], team_id: int) -> list[contracts.TaskDe
return dtos
-def list_tasks(
- team_id: int, user_id: int | None, *, filters: dict, is_debug_or_staff: bool
-) -> list[contracts.TaskDetailDTO]:
+def list_tasks(team_id: int, user_id: int | None, *, filters: dict) -> list[contracts.TaskDetailDTO]:
"""All visible tasks for the team as DTOs, mirroring the task list view filters."""
- return _tasks_to_dtos(
- _list_tasks_queryset(team_id, user_id, filters=filters, is_debug_or_staff=is_debug_or_staff), team_id
- )
+ return _tasks_to_dtos(_list_tasks_queryset(team_id, user_id, filters=filters), team_id)
def list_task_repositories(team_id: int, user_id: int | None) -> list[str]:
diff --git a/products/tasks/backend/presentation/serializers.py b/products/tasks/backend/presentation/serializers.py
index 42e2da4b1919..e2228a245f45 100644
--- a/products/tasks/backend/presentation/serializers.py
+++ b/products/tasks/backend/presentation/serializers.py
@@ -976,8 +976,8 @@ class TaskListQuerySerializer(serializers.Serializer):
help_text=(
"Filter by the internal flag, which controls whether a task is shown by default, not whether "
"it is accessible. Defaults to excluding internal tasks. Use 'all' to include both internal "
- "and user-facing tasks (available to any team member; access stays governed by task "
- "visibility). 'true' lists only internal tasks and is a staff/debug view."
+ "and user-facing tasks, or 'true' to list only internal tasks. All values are available to any "
+ "team member; access stays governed by task visibility."
),
)
archived = serializers.ChoiceField(
diff --git a/products/tasks/backend/presentation/views/api.py b/products/tasks/backend/presentation/views/api.py
index be16f63009a9..b5a52a4ffc77 100644
--- a/products/tasks/backend/presentation/views/api.py
+++ b/products/tasks/backend/presentation/views/api.py
@@ -224,10 +224,7 @@ class TaskViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
filters = {key: request.query_params.get(key) for key in request.query_params}
filters["internal"] = getattr(request, "validated_query_data", {}).get("internal")
filters["archived"] = getattr(request, "validated_query_data", {}).get("archived")
- is_debug_or_staff = settings.DEBUG or request.user.is_staff
- tasks = tasks_facade._list_tasks_queryset(
- self.team_id, self._user_id(), filters=filters, is_debug_or_staff=is_debug_or_staff
- )
+ tasks = tasks_facade._list_tasks_queryset(self.team_id, self._user_id(), filters=filters)
page = self.paginate_queryset(tasks)
assert page is not None, "TaskViewSet list requires an active paginator"
return self.get_paginated_response(
diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.py
index 84481c92abe8..644a2f2099d8 100644
--- a/products/tasks/backend/tests/test_api.py
+++ b/products/tasks/backend/tests/test_api.py
@@ -262,7 +262,7 @@ class TestTaskCreatorScoping(BaseTaskAPITest):
def test_list_signal_report_tasks_hidden_by_default(self):
# Signal-report tasks are always created with internal=True, so the
# default list still hides them. The retrieve-by-ID path (and the
- # staff/DEBUG `?internal=true` path) is how they're surfaced.
+ # `?internal=true` / `?internal=all` filters) is how they're surfaced.
other_user = self.create_organization_user("signal-owner")
signal_task = Task.objects.create(
team=self.team,
@@ -914,7 +914,6 @@ class TestTaskAPI(BaseTaskAPITest):
self.team.id,
self.user.id,
filters={"stage": "building"},
- is_debug_or_staff=False,
).query
).upper()
self.assertIn("EXISTS", query_sql)
@@ -3038,40 +3037,14 @@ class TestTaskInternalFilterAPI(BaseTaskAPITest):
self.assertIn(str(self.external_task.id), task_ids)
self.assertNotIn(str(self.internal_task.id), task_ids)
- def test_list_internal_true_is_ignored_for_non_staff_in_production(self):
- # Non-staff user with DEBUG=False must not have internal tasks surfaced.
+ def test_list_internal_true_shows_only_internal_tasks(self):
+ # `internal=true` narrows to only-internal tasks for any team member — it's a visibility toggle,
+ # not a staff/DEBUG gate (task visibility is the real access boundary).
self.assertFalse(self.user.is_staff)
with self.settings(DEBUG=False):
response = self.client.get("/api/projects/@current/tasks/?internal=true")
self.assertEqual(response.status_code, status.HTTP_200_OK)
- data = response.json()
- task_ids = [t["id"] for t in data["results"]]
- self.assertIn(str(self.external_task.id), task_ids)
- self.assertNotIn(str(self.internal_task.id), task_ids)
-
- def test_list_internal_true_shows_only_internal_tasks_in_debug(self):
- with self.settings(DEBUG=True):
- response = self.client.get("/api/projects/@current/tasks/?internal=true")
- self.assertEqual(response.status_code, status.HTTP_200_OK)
-
- data = response.json()
- task_ids = [t["id"] for t in data["results"]]
- self.assertNotIn(str(self.external_task.id), task_ids)
- self.assertIn(str(self.internal_task.id), task_ids)
-
- def test_list_internal_true_shows_only_internal_tasks_for_staff(self):
- # Staff users can list internal tasks even with DEBUG=False.
- staff_user = User.objects.create_user(
- email="[email protected]", password="password", first_name="Staff", is_staff=True
- )
- self.organization.members.add(staff_user)
- staff_client = APIClient()
- staff_client.force_authenticate(staff_user)
- with self.settings(DEBUG=False):
- response = staff_client.get("/api/projects/@current/tasks/?internal=true")
- self.assertEqual(response.status_code, status.HTTP_200_OK)
-
data = response.json()
task_ids = [t["id"] for t in data["results"]]
self.assertNotIn(str(self.external_task.id), task_ids)
diff --git a/products/tasks/frontend/generated/api.schemas.ts b/products/tasks/frontend/generated/api.schemas.ts
index f96f94a6e099..515f2d9f9b53 100644
--- a/products/tasks/frontend/generated/api.schemas.ts
+++ b/products/tasks/frontend/generated/api.schemas.ts
@@ -2084,7 +2084,7 @@ export type TasksListParams = {
*/
created_by?: number
/**
- * Filter by the internal flag, which controls whether a task is shown by default, not whether it is accessible. Defaults to excluding internal tasks. Use 'all' to include both internal and user-facing tasks (available to any team member; access stays governed by task visibility). 'true' lists only internal tasks and is a staff/debug view.
+ * Filter by the internal flag, which controls whether a task is shown by default, not whether it is accessible. Defaults to excluding internal tasks. Use 'all' to include both internal and user-facing tasks, or 'true' to list only internal tasks. All values are available to any team member; access stays governed by task visibility.
*
* * `true` - true
* * `false` - false
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index f297e51bc7a5..30b2e71e713c 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -66469,7 +66469,7 @@ export namespace Schemas {
*/
created_by?: number;
/**
- * Filter by the internal flag, which controls whether a task is shown by default, not whether it is accessible. Defaults to excluding internal tasks. Use 'all' to include both internal and user-facing tasks (available to any team member; access stays governed by task visibility). 'true' lists only internal tasks and is a staff/debug view.
+ * Filter by the internal flag, which controls whether a task is shown by default, not whether it is accessible. Defaults to excluding internal tasks. Use 'all' to include both internal and user-facing tasks, or 'true' to list only internal tasks. All values are available to any team member; access stays governed by task visibility.
*
* * `true` - true
* * `false` - false
diff --git a/services/mcp/src/generated/tasks/api.ts b/services/mcp/src/generated/tasks/api.ts
index 8499eef36c19..d0f8c6eb3636 100644
--- a/services/mcp/src/generated/tasks/api.ts
+++ b/services/mcp/src/generated/tasks/api.ts
@@ -38,7 +38,7 @@ export const TasksListQueryParams = /* @__PURE__ */ zod.object({
.enum(['true', 'false', 'all'])
.optional()
.describe(
- "Filter by the internal flag, which controls whether a task is shown by default, not whether it is accessible. Defaults to excluding internal tasks. Use 'all' to include both internal and user-facing tasks (available to any team member; access stays governed by task visibility). 'true' lists only internal tasks and is a staff/debug view.\n\n* `true` - true\n* `false` - false\n* `all` - all"
+ "Filter by the internal flag, which controls whether a task is shown by default, not whether it is accessible. Defaults to excluding internal tasks. Use 'all' to include both internal and user-facing tasks, or 'true' to list only internal tasks. All values are available to any team member; access stays governed by task visibility.\n\n* `true` - true\n* `false` - false\n* `all` - all"
),
limit: zod
.number()
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/tasks-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/tasks-list.json
index 1ab125f00408..db94470ef9a3 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/tasks-list.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/tasks-list.json
@@ -11,7 +11,7 @@
"type": "number"
},
"internal": {
- "description": "Filter by the internal flag, which controls whether a task is shown by default, not whether it is accessible. Defaults to excluding internal tasks. Use 'all' to include both internal and user-facing tasks (available to any team member; access stays governed by task visibility). 'true' lists only internal tasks and is a staff/debug view.\n\n* `true` - true\n* `false` - false\n* `all` - all",
+ "description": "Filter by the internal flag, which controls whether a task is shown by default, not whether it is accessible. Defaults to excluding internal tasks. Use 'all' to include both internal and user-facing tasks, or 'true' to list only internal tasks. All values are available to any team member; access stays governed by task visibility.\n\n* `true` - true\n* `false` - false\n* `all` - all",
"enum": ["true", "false", "all"],
"type": "string"
},