diff --git a/posthog/batch_exports/http.py b/posthog/batch_exports/http.py index e39a01c9cbeec..eaca9da1218a3 100644 --- a/posthog/batch_exports/http.py +++ b/posthog/batch_exports/http.py @@ -95,35 +95,21 @@ class BatchExportRunViewSet(TeamAndOrgViewSetMixin, viewsets.ReadOnlyModelViewSe queryset = BatchExportRun.objects.all() serializer_class = BatchExportRunSerializer pagination_class = RunsCursorPagination + filter_rewrite_rules = {"team_id": "batch_export__team_id"} - def get_queryset(self, date_range: tuple[dt.datetime, dt.datetime] | None = None): - if not isinstance(self.request.user, User) or self.request.user.current_team is None: - raise NotAuthenticated() - - if date_range: - return self.queryset.filter( - batch_export_id=self.kwargs["parent_lookup_batch_export_id"], - created_at__range=date_range, - ).order_by("-created_at") - else: - return self.queryset.filter(batch_export_id=self.kwargs["parent_lookup_batch_export_id"]).order_by( - "-created_at" - ) - - def list(self, request: request.Request, *args, **kwargs) -> response.Response: - """Get all BatchExportRuns for a BatchExport.""" - if not isinstance(request.user, User) or request.user.team is None: - raise NotAuthenticated() + def get_queryset(self): + queryset = super().get_queryset() - after = self.request.query_params.get("after", "-7d") - before = self.request.query_params.get("before", None) - after_datetime = relative_date_parse(after, request.user.team.timezone_info) - before_datetime = relative_date_parse(before, request.user.team.timezone_info) if before else now() + after = self.request.GET.get("after", "-7d") + before = self.request.GET.get("before", None) + after_datetime = relative_date_parse(after, self.team.timezone_info) + before_datetime = relative_date_parse(before, self.team.timezone_info) if before else now() date_range = (after_datetime, before_datetime) - page = self.paginate_queryset(self.get_queryset(date_range=date_range)) - serializer = self.get_serializer(page, many=True) - return self.get_paginated_response(serializer.data) + queryset = queryset.filter(batch_export_id=self.kwargs["parent_lookup_batch_export_id"]) + queryset = queryset.filter(created_at__range=date_range) + + return queryset.order_by("-created_at") class BatchExportDestinationSerializer(serializers.ModelSerializer): @@ -342,9 +328,6 @@ class BatchExportViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet): serializer_class = BatchExportSerializer def get_queryset(self): - if not isinstance(self.request.user, User): - raise NotAuthenticated() - return super().get_queryset().exclude(deleted=True).order_by("-created_at").prefetch_related("destination") @action(methods=["POST"], detail=True)