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.

fix(tasks): show shared Slack tasks on the task-detail endpoint (#88912)

posthog[bot]5ab6b6ea72bb
diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.py
index 4d61265a6235..c5d866e0c3b4 100644
--- a/products/tasks/backend/facade/api.py
+++ b/products/tasks/backend/facade/api.py
@@ -5087,10 +5087,17 @@ def _task_detail_queryset():
def _visible_task_qs(team_id: int, user_id: int | None, *, bypass_visibility: bool = False, for_control: bool = False):
"""Team-scoped live tasks, gated by read visibility — or by the narrower
- control predicate when ``for_control`` (mutations, runs, agent commands)."""
+ control predicate when ``for_control`` (mutations, runs, agent commands).
+
+ The read branch ORs in ``_shared_slack_thread_q()`` so a task shared in a Slack channel
+ is readable team-wide, matching ``task_accessible_for_run_view``. Without it the run
+ endpoint admits a channel collaborator while task detail returns 404 for the same task.
+ """
qs = Task.objects.filter(team_id=team_id, deleted=False)
if not bypass_visibility:
- qs = qs.filter(task_control_q(user_id) if for_control else task_visibility_q(user_id))
+ qs = qs.filter(
+ task_control_q(user_id) if for_control else task_visibility_q(user_id) | _shared_slack_thread_q()
+ )
return qs
diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.py
index b84ff019dc5c..73da0d6e3240 100644
--- a/products/tasks/backend/tests/test_api.py
+++ b/products/tasks/backend/tests/test_api.py
@@ -13594,6 +13594,34 @@ class TestTaskRunSlackTaskApiAccess(BaseTaskAPITest):
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
+ # The task-detail endpoint must widen the same way the run endpoint does. Before this,
+ # a channel collaborator could open the run but got 404 on the task, so the shared task
+ # looked deleted. Same conversation-type matrix as the run gate.
+ @parameterized.expand(
+ [
+ ("dm_thread_hidden", "im", status.HTTP_404_NOT_FOUND),
+ ("public_channel_thread_readable", "public_channel", status.HTTP_200_OK),
+ ("unclassified_thread_readable", None, status.HTTP_200_OK),
+ ]
+ )
+ @patch("products.tasks.backend.models.TaskRun.publish_stream_state_event")
+ def test_non_creator_task_detail_access_by_conversation_type(
+ self,
+ _case_name: str,
+ conversation_type: str | None,
+ expected_status: int,
+ _mock_publish_stream_state_event: MagicMock,
+ ) -> None:
+ task, _run = self._create_run(
+ origin_product=Task.OriginProduct.SLACK,
+ conversation_type=conversation_type,
+ with_mapping=True,
+ )
+
+ response = self.client.get(f"/api/projects/@current/tasks/{task.id}/")
+
+ self.assertEqual(response.status_code, expected_status)
+
class TestModelCatalogueAPI(BaseTaskAPITest):
GATEWAY_MODELS = (