Skip to content

Commit

Permalink
chore: Add denylist for elements_chain (#19193)
Browse files Browse the repository at this point in the history
Getting ready to flip from allowlist to denylist.  Will run with both over the weekend, then will switch to denylist only.
  • Loading branch information
davemurphysf authored Dec 8, 2023
1 parent d229aa6 commit 65eb52a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion posthog/api/decide.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
16 changes: 16 additions & 0 deletions posthog/api/test/test_decide.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
1 change: 1 addition & 0 deletions posthog/settings/ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""))

0 comments on commit 65eb52a

Please sign in to comment.