diff --git a/authentik/events/api/event.py b/authentik/events/api/event.py index f2bd1e437..ab7b13f05 100644 --- a/authentik/events/api/event.py +++ b/authentik/events/api/event.py @@ -29,6 +29,18 @@ class EventSerializer(ModelSerializer): ] +class EventTopPerUserParams(Serializer): + """Query params for top_per_user""" + + top_n = IntegerField(default=15) + + def create(self, request: Request) -> Response: + raise NotImplementedError + + def update(self, request: Request) -> Response: + raise NotImplementedError + + class EventTopPerUserSerializer(Serializer): """Response object of Event's top_per_user""" @@ -60,12 +72,14 @@ class EventViewSet(ReadOnlyModelViewSet): filterset_fields = ["action"] @swagger_auto_schema( - method="GET", responses={200: EventTopPerUserSerializer(many=True)} + method="GET", + responses={200: EventTopPerUserSerializer(many=True)}, + query_serializer=EventTopPerUserParams, ) @action(detail=False, methods=["GET"]) def top_per_user(self, request: Request): """Get the top_n events grouped by user count""" - filtered_action = request.query_params.get("filter_action", EventAction.LOGIN) + filtered_action = request.query_params.get("action", EventAction.LOGIN) top_n = request.query_params.get("top_n", 15) return Response( Event.objects.filter(action=filtered_action) diff --git a/swagger.yaml b/swagger.yaml index 321234d20..3580e81ef 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -1854,6 +1854,11 @@ paths: description: Page Size required: false type: integer + - name: top_n + in: query + required: false + type: integer + default: 15 responses: '200': description: Response object of Event's top_per_user