From a4c030e2b670834b911bc3cd3283650d2260f9b0 Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Tue, 26 Nov 2024 16:23:22 +0100 Subject: [PATCH] :sparkles: [#499] Add logging for when the record manager processes the review --- .../destruction/api/serializers.py | 4 +++ .../openarchiefbeheer/destruction/tasks.py | 8 ++++-- .../src/openarchiefbeheer/logging/logevent.py | 25 +++++++++++++++++++ ...struction_list_review_response_created.txt | 3 +++ ...ruction_list_review_response_processed.txt | 6 +++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 backend/src/openarchiefbeheer/logging/templates/logging/destruction_list_review_response_created.txt create mode 100644 backend/src/openarchiefbeheer/logging/templates/logging/destruction_list_review_response_processed.txt diff --git a/backend/src/openarchiefbeheer/destruction/api/serializers.py b/backend/src/openarchiefbeheer/destruction/api/serializers.py index 357dca2c..c2ff0889 100644 --- a/backend/src/openarchiefbeheer/destruction/api/serializers.py +++ b/backend/src/openarchiefbeheer/destruction/api/serializers.py @@ -852,6 +852,10 @@ def create(self, validated_data: dict) -> ReviewResponse: review_response = ReviewResponse.objects.create(**validated_data) ReviewItemResponse.objects.bulk_create(items_responses) + logevent.destruction_list_review_response_created( + validated_data["review"].destruction_list, self.context["request"].user + ) + process_review_response.delay(review_response.pk) return review_response diff --git a/backend/src/openarchiefbeheer/destruction/tasks.py b/backend/src/openarchiefbeheer/destruction/tasks.py index f79225f9..a6fdb361 100644 --- a/backend/src/openarchiefbeheer/destruction/tasks.py +++ b/backend/src/openarchiefbeheer/destruction/tasks.py @@ -6,6 +6,7 @@ from celery import chain from openarchiefbeheer.celery import app +from openarchiefbeheer.logging import logevent from .constants import InternalStatus, ListItemStatus, ListStatus from .exceptions import DeletionProcessingError @@ -43,10 +44,13 @@ def process_review_response(pk: int) -> None: item_response.save() return + destruction_list = review_response.review.destruction_list prepopulate_selection_after_review_response( - review_response.review.destruction_list, items_review_responses + destruction_list, items_review_responses ) - review_response.review.destruction_list.assign_next() + destruction_list.assign_next() + + logevent.destruction_list_review_response_processed(destruction_list) def delete_destruction_list(destruction_list: DestructionList) -> None: diff --git a/backend/src/openarchiefbeheer/logging/logevent.py b/backend/src/openarchiefbeheer/logging/logevent.py index 2e4feae6..fc713b84 100644 --- a/backend/src/openarchiefbeheer/logging/logevent.py +++ b/backend/src/openarchiefbeheer/logging/logevent.py @@ -6,6 +6,7 @@ from openarchiefbeheer.accounts.api.serializers import UserSerializer from openarchiefbeheer.accounts.models import User +from openarchiefbeheer.destruction.constants import ListItemStatus from openarchiefbeheer.destruction.models import ( DestructionList, DestructionListAssignee, @@ -99,6 +100,30 @@ def destruction_list_ready_for_first_review( ) +def destruction_list_review_response_created( + destruction_list: DestructionList, user: User +) -> None: + _create_log( + model=destruction_list, + event="destruction_list_review_response_created", + user=user, + ) + + +def destruction_list_review_response_processed( + destruction_list: DestructionList, +) -> None: + _create_log( + model=destruction_list, + event="destruction_list_review_response_processed", + extra_data={ + "number_of_zaken": destruction_list.items.filter( + status=ListItemStatus.suggested + ).count(), + }, + ) + + def destruction_list_updated(destruction_list: DestructionList, user: User) -> None: _create_log(model=destruction_list, event="destruction_list_updated", user=user) diff --git a/backend/src/openarchiefbeheer/logging/templates/logging/destruction_list_review_response_created.txt b/backend/src/openarchiefbeheer/logging/templates/logging/destruction_list_review_response_created.txt new file mode 100644 index 00000000..ab5e196a --- /dev/null +++ b/backend/src/openarchiefbeheer/logging/templates/logging/destruction_list_review_response_created.txt @@ -0,0 +1,3 @@ +{% load i18n %}{% with groups=log.extra_data.user_groups|join:", " %}{% blocktranslate trimmed with list_name=log.content_object.name groups=groups group_pluralized=group_pluralized author=log.user count counter=log.extra_data.user_groups|length %} +User {{ author }} (member of group {{ groups }}) has processed the feedback on destruction list "{{ list_name }}".{% plural %}User {{ author }} (member of groups {{ groups }}) has processed the feedback on destruction list "{{ list_name }}". +{% endblocktranslate %}{% endwith %} \ No newline at end of file diff --git a/backend/src/openarchiefbeheer/logging/templates/logging/destruction_list_review_response_processed.txt b/backend/src/openarchiefbeheer/logging/templates/logging/destruction_list_review_response_processed.txt new file mode 100644 index 00000000..feacda03 --- /dev/null +++ b/backend/src/openarchiefbeheer/logging/templates/logging/destruction_list_review_response_processed.txt @@ -0,0 +1,6 @@ +{% load i18n %}{% blocktranslate trimmed with list_name=log.content_object.name %} +The review response of destruction list "{{ list_name }}" has been processed. +{% endblocktranslate %} +{% blocktranslate trimmed with number_of_zaken=log.extra_data.number_of_zaken count counter=log.extra_data.number_of_zaken %} +There is now one zaak on the list.{% plural %}There are now {{ number_of_zaken }} zaken on the list. +{% endblocktranslate %}