: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
fix(workflows): grant the suggestion scope to a workflows scout a person set up (#118257)
Daniel Marchuk7aa3010cef15
diff --git a/products/signals/backend/facade/api.py b/products/signals/backend/facade/api.pyindex 2647d8b593da..321652a0a7ea 100644--- a/products/signals/backend/facade/api.py+++ b/products/signals/backend/facade/api.py@@ -1768,7 +1768,7 @@ def enable_scout_for_product(fit the project's enabled-scout limit, and only a project admin or the person the runs act asmay give a new scout more than the default scopes or widen an existing grant.Returns False without writing when a rule refuses, when the organization has not approved AI data processing, when the scout- is paused by a person or by the system, or when another product owns its config.+ is paused by a person or by the system."""from posthog.temporal.oauth import ( # noqa: PLC0415 — keeps the token module off the facade's import pathSCOUT_DEFAULT_WRITE_SCOPES,@@ -1830,10 +1830,11 @@ def enable_scout_for_product()if created:return True- # A config this product did not create is somebody's own scout, and its write access is theirs to grant.# A paused config stays paused, whether a person or a system breaker paused it.- if config.source_product != source_product or not config.enabled:+ if not config.enabled:return False+ # A scout a person set up keeps its other settings. It still gains this product's scopes when the person+ # may grant them, because without them its runs cannot do what the person just asked the product for.granted = sorted(set(config.write_scopes or []) | set(scopes))if granted != sorted(config.write_scopes or []):if not _may_grant_scout_scopes(team=team, skill_name=skill_name, config=config, acting_user=acting_user):diff --git a/products/workflows/backend/tests/api/test_workflow_proposals.py b/products/workflows/backend/tests/api/test_workflow_proposals.pyindex 842eb3a35ccf..38f2d77bf00c 100644--- a/products/workflows/backend/tests/api/test_workflow_proposals.py+++ b/products/workflows/backend/tests/api/test_workflow_proposals.py@@ -678,14 +678,36 @@ class TestWorkflowProposals(APIBaseTest):self._toggle(second, False)assert self._suggestions_scout() is None+ @parameterized.expand([("emitting", True, "running"), ("in dry run", False, "dry_run")])+ def test_a_scout_a_person_set_up_gains_the_suggestion_grant_and_outlives_the_opt_out(+ self, _name: str, emit: bool, scout_status: str+ ):+ flow_id = self._create_active_flow(optimize=False)+ SignalScoutConfig.objects.for_team(self.team.id).create(+ team=self.team,+ skill_name="signals-scout-workflows",+ enabled=True,+ emit=emit,+ write_scopes=["notebook:write"],+ created_by=self.user,+ enabled_by=self.user,+ )++ response = self._toggle(flow_id, True)+ scout = self._suggestions_scout()++ assert response["scout_status"] == scout_status+ assert scout is not None and scout.write_scopes == ["hog_flow_proposal:write", "notebook:write"]++ self._toggle(flow_id, False)+ assert self._suggestions_scout() is not None+@parameterized.expand([("paused by a person", "paused", "paused_by_user"),("paused by the system", "system_paused", "paused_by_system"),("a member widening another person's scout", "widen", "running"),("api key without the proposal scope turning one off", "key_off", "not_running"),- ("a scout a person set up", "own", "running"),- ("a scout a person set to dry run", "dry_run", "dry_run"),])def test_suggestions_scout_gains_no_grant(self, _name: str, case: str, scout_status: str):@@ -717,10 +739,6 @@ class TestWorkflowProposals(APIBaseTest):created_by=other,enabled_by=other,)- elif case in ("own", "dry_run"):- SignalScoutConfig.objects.for_team(self.team.id).create(- team=self.team, skill_name="signals-scout-workflows", enabled=True, emit=case != "dry_run"- )elif case == "key_off":key = generate_random_token_personal()PersonalAPIKey.objects.create(