Skip to content

Commit

Permalink
fix: Zapier hook template (#27036)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
benjackwhite and github-actions[bot] authored Dec 19, 2024
1 parent fba447a commit 4621c51
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 40 deletions.
6 changes: 5 additions & 1 deletion posthog/api/hog_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,18 @@ def get_serializer_class(self) -> type[BaseSerializer]:
return HogFunctionMinimalSerializer if self.action == "list" else HogFunctionSerializer

def safely_get_queryset(self, queryset: QuerySet) -> QuerySet:
if not (self.action == "partial_update" and self.request.data.get("deleted") is False):
# We only want to include deleted functions if we are un-deleting them
queryset = queryset.filter(deleted=False)

if self.action == "list":
if "type" in self.request.GET:
types = [self.request.GET.get("type", "destination")]
elif "types" in self.request.GET:
types = self.request.GET.get("types", "destination").split(",")
else:
types = ["destination"]
queryset = queryset.filter(deleted=False, type__in=types)
queryset = queryset.filter(type__in=types)

if self.request.GET.get("filters"):
try:
Expand Down
54 changes: 36 additions & 18 deletions posthog/api/test/__snapshots__/test_decide.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -1672,7 +1673,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -2080,7 +2082,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -2708,7 +2711,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -3104,7 +3108,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -3402,7 +3407,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -3766,7 +3772,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -4903,7 +4910,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -5401,7 +5409,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -5759,7 +5768,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -6518,7 +6528,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -6815,7 +6826,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -7211,7 +7223,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -7557,7 +7570,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -8185,7 +8199,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -8482,7 +8497,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -8874,7 +8890,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -9212,7 +9229,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down
12 changes: 8 additions & 4 deletions posthog/api/test/__snapshots__/test_early_access_feature.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -1004,7 +1005,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -1627,7 +1629,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -2132,7 +2135,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -1726,7 +1727,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down
15 changes: 10 additions & 5 deletions posthog/api/test/__snapshots__/test_survey.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -873,7 +874,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -1339,7 +1341,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -1733,7 +1736,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down Expand Up @@ -2156,7 +2160,8 @@
"posthog_team"."external_data_workspace_last_synced_at"
FROM "posthog_hogfunction"
INNER JOIN "posthog_team" ON ("posthog_hogfunction"."team_id" = "posthog_team"."id")
WHERE ("posthog_hogfunction"."enabled"
WHERE (NOT "posthog_hogfunction"."deleted"
AND "posthog_hogfunction"."enabled"
AND "posthog_hogfunction"."team_id" = 99999
AND "posthog_hogfunction"."type" IN ('site_destination',
'site_app'))
Expand Down
23 changes: 23 additions & 0 deletions posthog/api/test/test_hog_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,29 @@ def test_deletes_via_update(self, *args):
]
assert filtered_actual_activities == expected_activities

def test_can_undelete_hog_function(self, *args):
response = self.client.post(
f"/api/projects/{self.team.id}/hog_functions/",
data={**EXAMPLE_FULL},
)
id = response.json()["id"]

response = self.client.patch(
f"/api/projects/{self.team.id}/hog_functions/{id}/",
data={"deleted": True},
)
assert response.status_code == status.HTTP_200_OK, response.json()
assert (
self.client.get(f"/api/projects/{self.team.id}/hog_functions/{id}").status_code == status.HTTP_404_NOT_FOUND
)

response = self.client.patch(
f"/api/projects/{self.team.id}/hog_functions/{id}/",
data={"deleted": False},
)
assert response.status_code == status.HTTP_200_OK, response.json()
assert self.client.get(f"/api/projects/{self.team.id}/hog_functions/{id}").status_code == status.HTTP_200_OK

def test_inputs_required(self, *args):
payload = {
"name": "Fetch URL",
Expand Down
2 changes: 1 addition & 1 deletion posthog/cdp/templates/zapier/template_zapier.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"hook": {
"id": "{source.url}",
"event": "{event}",
"target": "https://hooks.zapier.com/{inputs.hook}",
"target": "https://hooks.zapier.com",
},
"data": {
"eventUuid": "{event.uuid}",
Expand Down
2 changes: 1 addition & 1 deletion posthog/models/remote_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def _build_site_apps_js(self):
)
site_functions = (
HogFunction.objects.select_related("team")
.filter(team=self.team, enabled=True, type__in=("site_destination", "site_app"))
.filter(team=self.team, enabled=True, deleted=False, type__in=("site_destination", "site_app"))
.all()
)

Expand Down
22 changes: 22 additions & 0 deletions posthog/models/test/test_remote_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,3 +813,25 @@ def test_renders_js_including_site_functions(self):
})();\
""" # noqa: W291, W293
)

def test_removes_deleted_site_functions(self):
site_destination = HogFunction.objects.create(
name="Site destination",
type=HogFunctionType.SITE_DESTINATION,
team=self.team,
enabled=True,
filters={
"events": [{"id": "$pageview", "name": "$pageview", "type": "events", "order": 0}],
"filter_test_accounts": True,
},
)

js = self.remote_config.get_config_js_via_token(self.team.api_token)

assert str(site_destination.id) in js

site_destination.deleted = True
site_destination.save()

js = self.remote_config.get_config_js_via_token(self.team.api_token)
assert str(site_destination.id) not in js
Loading

0 comments on commit 4621c51

Please sign in to comment.