events: make notifications filterable

This commit is contained in:
Jens Langhammer 2021-01-16 19:08:07 +01:00
parent 2d2a404028
commit f959212692
3 changed files with 35 additions and 3 deletions

View File

@ -39,6 +39,13 @@ class NotificationViewSet(
queryset = Notification.objects.all()
serializer_class = NotificationSerializer
filterset_fields = [
"severity",
"body",
"created",
"event",
"seen",
]
def get_queryset(self):
if not self.request:

View File

@ -8,7 +8,7 @@ from django.db.models.signals import post_save, pre_delete
from django.http import HttpRequest, HttpResponse
from authentik.core.middleware import LOCAL
from authentik.events.models import Event, EventAction
from authentik.events.models import Event, EventAction, Notification
from authentik.events.signals import EventNewThread
from authentik.events.utils import model_to_dict
@ -63,7 +63,7 @@ class AuditMiddleware:
user: User, request: HttpRequest, sender, instance: Model, created: bool, **_
):
"""Signal handler for all object's post_save"""
if isinstance(instance, Event):
if isinstance(instance, (Event, Notification)):
return
action = EventAction.MODEL_CREATED if created else EventAction.MODEL_UPDATED
@ -75,7 +75,7 @@ class AuditMiddleware:
user: User, request: HttpRequest, sender, instance: Model, **_
):
"""Signal handler for all object's pre_delete"""
if isinstance(instance, Event):
if isinstance(instance, (Event, Notification)):
return
EventNewThread(

View File

@ -984,6 +984,31 @@ paths:
operationId: events_notifications_list
description: Notification Viewset
parameters:
- name: severity
in: query
description: ''
required: false
type: string
- name: body
in: query
description: ''
required: false
type: string
- name: created
in: query
description: ''
required: false
type: string
- name: event
in: query
description: ''
required: false
type: string
- name: seen
in: query
description: ''
required: false
type: string
- name: ordering
in: query
description: Which field to use when ordering the results.