Skip to content

Commit

Permalink
feat(cdp): allow free users to update non-free templates (#26608)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ben White <[email protected]>
  • Loading branch information
3 people authored Dec 3, 2024
1 parent 8b60590 commit 8eea1c0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion posthog/api/hog_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def validate(self, attrs):
{"template_id": "The Data Pipelines addon is required to create custom functions."}
)

if template.status != "free":
if template.status != "free" and not instance:
raise serializers.ValidationError(
{"template_id": "The Data Pipelines addon is required for this template."}
)
Expand Down
8 changes: 4 additions & 4 deletions posthog/api/test/__snapshots__/test_insight.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -1380,12 +1380,12 @@
LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id")
WHERE (("ee_accesscontrol"."organization_member_id" IS NULL
AND "ee_accesscontrol"."resource" = 'project'
AND "ee_accesscontrol"."resource_id" = '446'
AND "ee_accesscontrol"."resource_id" = '447'
AND "ee_accesscontrol"."role_id" IS NULL
AND "ee_accesscontrol"."team_id" = 99999)
OR ("posthog_organizationmembership"."user_id" = 99999
AND "ee_accesscontrol"."resource" = 'project'
AND "ee_accesscontrol"."resource_id" = '446'
AND "ee_accesscontrol"."resource_id" = '447'
AND "ee_accesscontrol"."role_id" IS NULL
AND "ee_accesscontrol"."team_id" = 99999)
OR ("ee_accesscontrol"."organization_member_id" IS NULL
Expand Down Expand Up @@ -1493,12 +1493,12 @@
LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id")
WHERE (("ee_accesscontrol"."organization_member_id" IS NULL
AND "ee_accesscontrol"."resource" = 'project'
AND "ee_accesscontrol"."resource_id" = '446'
AND "ee_accesscontrol"."resource_id" = '447'
AND "ee_accesscontrol"."role_id" IS NULL
AND "ee_accesscontrol"."team_id" = 99999)
OR ("posthog_organizationmembership"."user_id" = 99999
AND "ee_accesscontrol"."resource" = 'project'
AND "ee_accesscontrol"."resource_id" = '446'
AND "ee_accesscontrol"."resource_id" = '447'
AND "ee_accesscontrol"."role_id" IS NULL
AND "ee_accesscontrol"."team_id" = 99999)
OR ("ee_accesscontrol"."organization_member_id" IS NULL
Expand Down
39 changes: 38 additions & 1 deletion posthog/api/test/test_hog_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_free_users_cannot_use_without_template(self):
assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()
assert response.json()["detail"] == "The Data Pipelines addon is required to create custom functions."

def test_free_users_cannot_use_non_free_templates(self):
def test_free_users_cannot_create_non_free_templates(self):
response = self._create_slack_function(
{
"template_id": template_webhook.id,
Expand All @@ -124,6 +124,43 @@ def test_free_users_cannot_use_non_free_templates(self):
assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()
assert response.json()["detail"] == "The Data Pipelines addon is required for this template."

def test_free_users_can_update_non_free_templates(self):
self.organization.available_product_features = [
{"key": AvailableFeature.DATA_PIPELINES, "name": AvailableFeature.DATA_PIPELINES}
]
self.organization.save()

response = self._create_slack_function(
{
"name": template_webhook.name,
"template_id": template_webhook.id,
"inputs": {
"url": {"value": "https://example.com"},
},
}
)

assert response.json()["template"]["status"] == template_webhook.status

self.organization.available_product_features = []
self.organization.save()

payload = {
"name": template_webhook.name,
"template_id": template_webhook.id,
"inputs": {
"url": {"value": "https://example.com/posthog-webhook-updated"},
},
}

update_response = self.client.patch(
f"/api/projects/{self.team.id}/hog_functions/{response.json()['id']}/",
data=payload,
)

assert update_response.status_code == status.HTTP_200_OK, update_response.json()
assert update_response.json()["inputs"]["url"]["value"] == "https://example.com/posthog-webhook-updated"


class TestHogFunctionAPI(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
def setUp(self):
Expand Down

0 comments on commit 8eea1c0

Please sign in to comment.