From 65eb52ac431f059a60b1f46ad642f94c0d658b3c Mon Sep 17 00:00:00 2001 From: David Murphy Date: Thu, 7 Dec 2023 16:00:21 -0800 Subject: [PATCH] chore: Add denylist for elements_chain (#19193) Getting ready to flip from allowlist to denylist. Will run with both over the weekend, then will switch to denylist only. --- posthog/api/decide.py | 9 ++++++++- posthog/api/test/test_decide.py | 16 ++++++++++++++++ posthog/settings/ingestion.py | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/posthog/api/decide.py b/posthog/api/decide.py index ccb6670af4584..05f3a005e83dd 100644 --- a/posthog/api/decide.py +++ b/posthog/api/decide.py @@ -230,7 +230,14 @@ def get_decide(request: HttpRequest): if random() < settings.NEW_ANALYTICS_CAPTURE_SAMPLING_RATE: response["analytics"] = {"endpoint": settings.NEW_ANALYTICS_CAPTURE_ENDPOINT} - if settings.ELEMENT_CHAIN_AS_STRING_TEAMS and str(team.id) in settings.ELEMENT_CHAIN_AS_STRING_TEAMS: + if ( + settings.ELEMENT_CHAIN_AS_STRING_TEAMS + and str(team.id) in settings.ELEMENT_CHAIN_AS_STRING_TEAMS + and ( + settings.ELEMENT_CHAIN_AS_STRING_EXCLUDED_TEAMS is None + or str(team.id) not in settings.ELEMENT_CHAIN_AS_STRING_EXCLUDED_TEAMS + ) + ): response["elementsChainAsString"] = True if team.session_recording_opt_in and ( diff --git a/posthog/api/test/test_decide.py b/posthog/api/test/test_decide.py index 8c670c3243529..06ddabb0495da 100644 --- a/posthog/api/test/test_decide.py +++ b/posthog/api/test/test_decide.py @@ -3019,6 +3019,22 @@ def test_decide_element_chain_as_string(self, *args): self.assertEqual(response.status_code, 200) self.assertFalse("elementsChainAsString" in response.json()) + with self.settings( + ELEMENT_CHAIN_AS_STRING_TEAMS={str(self.team.id)}, ELEMENT_CHAIN_AS_STRING_EXCLUDED_TEAMS={"0"} + ): + response = self._post_decide(api_version=3) + self.assertEqual(response.status_code, 200) + self.assertTrue("elementsChainAsString" in response.json()) + self.assertTrue(response.json()["elementsChainAsString"]) + + with self.settings( + ELEMENT_CHAIN_AS_STRING_TEAMS={str(self.team.id)}, + ELEMENT_CHAIN_AS_STRING_EXCLUDED_TEAMS={str(self.team.id)}, + ): + response = self._post_decide(api_version=3) + self.assertEqual(response.status_code, 200) + self.assertFalse("elementsChainAsString" in response.json()) + class TestDatabaseCheckForDecide(BaseTest, QueryMatchingTest): """ diff --git a/posthog/settings/ingestion.py b/posthog/settings/ingestion.py index b559f5726ca29..59fa99ca59bb3 100644 --- a/posthog/settings/ingestion.py +++ b/posthog/settings/ingestion.py @@ -40,3 +40,4 @@ NEW_ANALYTICS_CAPTURE_SAMPLING_RATE = get_from_env("NEW_ANALYTICS_CAPTURE_SAMPLING_RATE", type_cast=float, default=1.0) ELEMENT_CHAIN_AS_STRING_TEAMS = get_set(os.getenv("ELEMENT_CHAIN_AS_STRING_TEAMS", "")) +ELEMENT_CHAIN_AS_STRING_EXCLUDED_TEAMS = get_set(os.getenv("ELEMENT_CHAIN_AS_STRING_EXCLUDED_TEAMS", ""))