From 69fe3e153628e135bb7eb51b497dafa5b8445f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riku=20Kestila=CC=88?= Date: Wed, 10 Jan 2024 13:44:17 +0200 Subject: [PATCH] feat: audit log employee in applicant form --- .../api/v1/serializers/application.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/benefit/applications/api/v1/serializers/application.py b/backend/benefit/applications/api/v1/serializers/application.py index 5d23f1f643..76fbd83219 100755 --- a/backend/benefit/applications/api/v1/serializers/application.py +++ b/backend/benefit/applications/api/v1/serializers/application.py @@ -56,6 +56,8 @@ from companies.api.v1.serializers import CompanySerializer from companies.models import Company from messages.automatic_messages import send_application_reopened_message +from shared.audit_log import audit_logging +from shared.audit_log.enums import Operation from terms.api.v1.serializers import ( ApplicantTermsApprovalSerializer, ApproveTermsSerializer, @@ -1247,9 +1249,22 @@ def create(self, validated_data): return application def _update_or_create_employee(self, application, employee_data): - employee, _ = Employee.objects.update_or_create( + employee, was_created = Employee.objects.update_or_create( application=application, defaults=employee_data ) + user = self.get_logged_in_user() + + if was_created: + audit_log_operation = Operation.CREATE + else: + audit_log_operation = Operation.UPDATE + + audit_logging.log( + user, + "", + audit_log_operation, + employee, + ) return employee def get_company(self, validated_data):