-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ [#499] Refactor auditlog endpoint
- Loading branch information
1 parent
8e2983e
commit 5152d26
Showing
10 changed files
with
83 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.db.models import QuerySet | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from django_filters import FilterSet, UUIDFilter | ||
from timeline_logger.models import TimelineLog | ||
|
||
from openarchiefbeheer.destruction.models import DestructionList | ||
|
||
|
||
class LogsFilterset(FilterSet): | ||
destruction_list = UUIDFilter( | ||
field_name="destruction_list", | ||
method="filter_destruction_list", | ||
help_text=_("Retrieve the logs of a particular destruction list."), | ||
) | ||
|
||
class Meta: | ||
model = TimelineLog | ||
fields = ("destruction_list",) | ||
|
||
def filter_destruction_list( | ||
self, queryset: QuerySet[TimelineLog], name: str, value: str | ||
) -> QuerySet[TimelineLog]: | ||
destruction_list = DestructionList.objects.filter(uuid=value).first() | ||
if not destruction_list: | ||
return queryset.none() | ||
|
||
content_type = ContentType.objects.get_for_model(destruction_list) | ||
|
||
return queryset.filter( | ||
content_type=content_type, | ||
object_id=destruction_list.pk, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from rest_framework import serializers | ||
from timeline_logger.models import TimelineLog | ||
|
||
from openarchiefbeheer.accounts.api.serializers import UserSerializer | ||
|
||
|
||
class AuditTrailItemSerializer(serializers.ModelSerializer): | ||
message = serializers.CharField(source="get_message") | ||
user = UserSerializer() | ||
|
||
class Meta: | ||
model = TimelineLog | ||
fields = ( | ||
"pk", | ||
"timestamp", | ||
"user", | ||
"message", | ||
"extra_data", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from django_filters.rest_framework import DjangoFilterBackend | ||
from drf_spectacular.utils import extend_schema, extend_schema_view | ||
from rest_framework import mixins | ||
from rest_framework.viewsets import GenericViewSet | ||
from timeline_logger.models import TimelineLog | ||
|
||
from .filtersets import LogsFilterset | ||
from .serializers import AuditTrailItemSerializer | ||
|
||
|
||
@extend_schema_view( | ||
list=extend_schema( | ||
tags=["Logs"], | ||
summary=_("List logs"), | ||
), | ||
) | ||
class LogsViewset(mixins.ListModelMixin, GenericViewSet): | ||
queryset = TimelineLog.objects.all() | ||
serializer_class = AuditTrailItemSerializer | ||
filter_backends = (DjangoFilterBackend,) | ||
filterset_class = LogsFilterset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters