From b9a484046b87afbaf49ec15d41f28bf427f46000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Far=C3=ADas=20Santana?= Date: Mon, 9 Oct 2023 14:23:04 +0200 Subject: [PATCH] fix(batch-exports): Include properties in feature_enabled call (#17860) --- frontend/src/scenes/batch_exports/utils.ts | 1 + frontend/src/types.ts | 2 +- posthog/api/test/batch_exports/test_create.py | 20 +++++++++++++++++-- posthog/batch_exports/http.py | 18 ++++++++++++----- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/frontend/src/scenes/batch_exports/utils.ts b/frontend/src/scenes/batch_exports/utils.ts index 4302f2dc65298..16ebf9d3176ef 100644 --- a/frontend/src/scenes/batch_exports/utils.ts +++ b/frontend/src/scenes/batch_exports/utils.ts @@ -4,6 +4,7 @@ export function intervalToFrequency(interval: BatchExportConfiguration['interval return { day: 'daily', hour: 'hourly', + 'every 5 minutes': 'every 5 minutes', }[interval] } diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 0ca801012d6ec..60df3f8f1cf04 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -3211,7 +3211,7 @@ export type BatchExportConfiguration = { id: string name: string destination: BatchExportDestination - interval: 'hour' | 'day' + interval: 'hour' | 'day' | 'every 5 minutes' created_at: string start_at: string | null end_at: string | null diff --git a/posthog/api/test/batch_exports/test_create.py b/posthog/api/test/batch_exports/test_create.py index 3b63d3f3ceb7b..ca58d13a17347 100644 --- a/posthog/api/test/batch_exports/test_create.py +++ b/posthog/api/test/batch_exports/test_create.py @@ -65,7 +65,15 @@ def test_create_batch_export_with_interval_schedule(client: HttpClient, interval ) if interval == "every 5 minutes": - feature_enabled.assert_called_once_with("high-frequency-batch-exports", str(team.uuid)) + feature_enabled.assert_called_once_with( + "high-frequency-batch-exports", + str(team.uuid), + groups={"organization": str(team.organization.id)}, + group_properties={ + "organization": {"id": str(team.organization.id), "created_at": team.organization.created_at} + }, + send_feature_flag_events=False, + ) assert response.status_code == status.HTTP_201_CREATED, response.json() @@ -179,4 +187,12 @@ def test_cannot_create_a_batch_export_with_higher_frequencies_if_not_enabled(cli batch_export_data, ) assert response.status_code == status.HTTP_403_FORBIDDEN, response.json() - feature_enabled.assert_called_once_with("high-frequency-batch-exports", str(team.uuid)) + feature_enabled.assert_called_once_with( + "high-frequency-batch-exports", + str(team.uuid), + groups={"organization": str(team.organization.id)}, + group_properties={ + "organization": {"id": str(team.organization.id), "created_at": team.organization.created_at} + }, + send_feature_flag_events=False, + ) diff --git a/posthog/batch_exports/http.py b/posthog/batch_exports/http.py index f7084d65db89c..cd8e24aca5cd6 100644 --- a/posthog/batch_exports/http.py +++ b/posthog/batch_exports/http.py @@ -170,11 +170,19 @@ def create(self, validated_data: dict) -> BatchExport: destination_data = validated_data.pop("destination") team_id = self.context["team_id"] - if validated_data["interval"] not in ("hour", "day", "week") and not posthoganalytics.feature_enabled( - "high-frequency-batch-exports", - str(Team.objects.get(id=team_id).uuid), - ): - raise PermissionDenied("Higher frequency exports are not enabled for this team.") + if validated_data["interval"] not in ("hour", "day", "week"): + team = Team.objects.get(id=team_id) + + if not posthoganalytics.feature_enabled( + "high-frequency-batch-exports", + str(team.uuid), + groups={"organization": str(team.organization.id)}, + group_properties={ + "organization": {"id": str(team.organization.id), "created_at": team.organization.created_at} + }, + send_feature_flag_events=False, + ): + raise PermissionDenied("Higher frequency exports are not enabled for this team.") destination = BatchExportDestination(**destination_data) batch_export = BatchExport(team_id=team_id, destination=destination, **validated_data)