Skip to content

Commit 81b0e17

Browse files
committed
fix(cohorts): plan-gate the Mixpanel webhook
1 parent e98fd87 commit 81b0e17

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

api/cohorts/sync_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class MixpanelCohortSyncView(APIView):
122122
"""
123123

124124
authentication_classes = [CohortSyncKeyAuthentication]
125-
permission_classes = [HasCohortSyncKey]
125+
permission_classes = [HasCohortSyncKey, CohortSyncPlanPermission]
126126

127127
@extend_schema(
128128
description=(

api/tests/unit/cohorts/test_sync_views.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,3 +1014,30 @@ def test_mixpanel_webhook__members_action_while_cohort_draining__returns_404_fai
10141014
"error": {"message": "Cohort is being deleted.", "code": 404},
10151015
}
10161016
assert Cohort.objects.filter(source_type=CohortSourceType.MIXPANEL).count() == 1
1017+
1018+
1019+
@pytest.mark.saas_mode
1020+
def test_mixpanel_webhook__saas_free_plan__returns_403(
1021+
postgres_cohort_sync_key: _KeyAndPlaintext,
1022+
) -> None:
1023+
# Given
1024+
_, plaintext = postgres_cohort_sync_key
1025+
client = _basic_auth_client(plaintext)
1026+
url = reverse("api-v1:cohort-sync:mixpanel")
1027+
1028+
# When
1029+
response = client.post(
1030+
url,
1031+
data={
1032+
"action": "members",
1033+
"parameters": {
1034+
"mixpanel_cohort_id": "mp-42",
1035+
"mixpanel_cohort_name": "Power users",
1036+
"members": [{"mixpanel_distinct_id": "user-1"}],
1037+
},
1038+
},
1039+
format="json",
1040+
)
1041+
1042+
# Then
1043+
assert response.status_code == status.HTTP_403_FORBIDDEN

0 commit comments

Comments
 (0)