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.

chore(tasks): allow staff to view internal tasks in all envs (#57157)

Joshua Snyder25e7fe860874
diff --git a/products/tasks/backend/api.py b/products/tasks/backend/api.py
index 49a5a888808e..38c0c41dd2df 100644
--- a/products/tasks/backend/api.py
+++ b/products/tasks/backend/api.py
@@ -426,7 +426,7 @@ class TaskViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
)
internal_param = getattr(self.request, "validated_query_data", {}).get("internal")
- if internal_param is True and settings.DEBUG:
+ if internal_param is True and (settings.DEBUG or self.request.user.is_staff):
qs = qs.filter(internal=True)
else:
qs = qs.filter(internal=False)
diff --git a/products/tasks/backend/serializers.py b/products/tasks/backend/serializers.py
index bc09c6af3165..e852ca848d92 100644
--- a/products/tasks/backend/serializers.py
+++ b/products/tasks/backend/serializers.py
@@ -845,7 +845,7 @@ class TaskListQuerySerializer(serializers.Serializer):
)
internal = serializers.BooleanField(
required=False,
- help_text="When true, list internal tasks instead of user-facing ones. Honored only in debug environments; ignored in production. Defaults to excluding internal tasks.",
+ help_text="When true, list internal tasks instead of user-facing ones. Honored in debug environments or for staff users; ignored for non-staff users in production. Defaults to excluding internal tasks.",
)
diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.py
index 9f321f9dcd92..30e0657c7af7 100644
--- a/products/tasks/backend/tests/test_api.py
+++ b/products/tasks/backend/tests/test_api.py
@@ -1990,9 +1990,11 @@ 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_in_production(self):
- # DEBUG is False in tests by default, so ?internal=true must not surface internal tasks.
- response = self.client.get("/api/projects/@current/tasks/?internal=true")
+ 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.
+ 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()
@@ -2010,6 +2012,23 @@ class TestTaskInternalFilterAPI(BaseTaskAPITest):
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)
+ self.assertIn(str(self.internal_task.id), task_ids)
+
def test_list_internal_false_excludes_internal_tasks(self):
response = self.client.get("/api/projects/@current/tasks/?internal=false")
self.assertEqual(response.status_code, status.HTTP_200_OK)
diff --git a/products/tasks/frontend/components/TasksList.tsx b/products/tasks/frontend/components/TasksList.tsx
index 3ac3c12f43dd..5035c7ec4d37 100644
--- a/products/tasks/frontend/components/TasksList.tsx
+++ b/products/tasks/frontend/components/TasksList.tsx
@@ -28,7 +28,8 @@ import { TaskStatusBadge } from './TaskStatusBadge'
import { UserFilter } from './UserFilter'
export function TasksList(): JSX.Element {
- const { searchQuery, repository, status, showInternal, isDev, isCreateModalOpen } = useValues(taskTrackerSceneLogic)
+ const { searchQuery, repository, status, showInternal, isStaff, isCreateModalOpen } =
+ useValues(taskTrackerSceneLogic)
const { tasks, tasksLoading, repositories } = useValues(tasksLogic)
const { setSearchQuery, setRepository, setStatus, setShowInternal, openCreateModal, closeCreateModal } =
useActions(taskTrackerSceneLogic)
@@ -139,7 +140,7 @@ export function TasksList(): JSX.Element {
)}
<LemonSelect value={status} onChange={setStatus} options={statusOptions} className="min-w-32" />
<UserFilter />
- {isDev && (
+ {isStaff && (
<LemonSwitch
label="Show internal"
checked={showInternal}
diff --git a/products/tasks/frontend/generated/api.schemas.ts b/products/tasks/frontend/generated/api.schemas.ts
index ea647e22ebb6..5542d5aa4b8c 100644
--- a/products/tasks/frontend/generated/api.schemas.ts
+++ b/products/tasks/frontend/generated/api.schemas.ts
@@ -1488,7 +1488,7 @@ export type TasksListParams = {
*/
created_by?: number
/**
- * When true, list internal tasks instead of user-facing ones. Honored only in debug environments; ignored in production. Defaults to excluding internal tasks.
+ * When true, list internal tasks instead of user-facing ones. Honored in debug environments or for staff users; ignored for non-staff users in production. Defaults to excluding internal tasks.
*/
internal?: boolean
/**
diff --git a/products/tasks/frontend/logics/taskTrackerSceneLogic.ts b/products/tasks/frontend/logics/taskTrackerSceneLogic.ts
index 1909b1f66ec5..34e80fd7b9e8 100644
--- a/products/tasks/frontend/logics/taskTrackerSceneLogic.ts
+++ b/products/tasks/frontend/logics/taskTrackerSceneLogic.ts
@@ -6,7 +6,6 @@ import { subscriptions } from 'kea-subscriptions'
import { lemonToast } from '@posthog/lemon-ui'
import api from 'lib/api'
-import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
import { Params } from 'scenes/sceneTypes'
import { userLogic } from 'scenes/userLogic'
@@ -29,16 +28,7 @@ export const taskTrackerSceneLogic = kea<taskTrackerSceneLogicType>([
path(['products', 'tasks', 'frontend', 'taskTrackerSceneLogic']),
connect(() => ({
- values: [
- router,
- ['location'],
- userLogic,
- ['user'],
- tasksLogic,
- ['tasks', 'repositories'],
- preflightLogic,
- ['isDev'],
- ],
+ values: [router, ['location'], userLogic, ['user'], tasksLogic, ['tasks', 'repositories']],
actions: [tasksLogic, ['loadTasks', 'loadRepositories', 'deleteTask']],
})),
@@ -132,11 +122,12 @@ export const taskTrackerSceneLogic = kea<taskTrackerSceneLogicType>([
}),
selectors({
+ isStaff: [(s) => [s.user], (user): boolean => user?.is_staff ?? false],
// All filters are pushed down to the backend via `loadTasks(listParams)` so results are
// not limited by list pagination. The scene renders `tasks` (the loader output) directly.
listParams: [
- (s) => [s.searchQuery, s.repository, s.status, s.createdBy, s.showInternal, s.isDev],
- (searchQuery, repository, status, createdBy, showInternal, isDev): TaskListParams => {
+ (s) => [s.searchQuery, s.repository, s.status, s.createdBy, s.showInternal, s.isStaff],
+ (searchQuery, repository, status, createdBy, showInternal, isStaff): TaskListParams => {
const params: TaskListParams = {}
if (searchQuery.trim()) {
params.search = searchQuery.trim()
@@ -150,7 +141,7 @@ export const taskTrackerSceneLogic = kea<taskTrackerSceneLogicType>([
if (createdBy !== null) {
params.created_by = createdBy
}
- if (showInternal && isDev) {
+ if (showInternal && isStaff) {
params.internal = true
}
return params
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 66f7cc730f1b..71ae1bfc4e16 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -45542,7 +45542,7 @@ export namespace Schemas {
*/
created_by?: number;
/**
- * When true, list internal tasks instead of user-facing ones. Honored only in debug environments; ignored in production. Defaults to excluding internal tasks.
+ * When true, list internal tasks instead of user-facing ones. Honored in debug environments or for staff users; ignored for non-staff users in production. Defaults to excluding internal tasks.
*/
internal?: boolean;
/**