From 641c7e933f1f68e9a9d45b50f369e99a818aedc2 Mon Sep 17 00:00:00 2001 From: monsieurswag Date: Mon, 21 Oct 2024 18:06:49 +0200 Subject: [PATCH] Codefactor fix 3 --- backend/core/views.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/core/views.py b/backend/core/views.py index d25ff6dddd..9b62d1f29a 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -950,10 +950,8 @@ def duplicate(self, request, pk): {"results": "applied control duplicated"}, status=HTTP_404_NOT_FOUND ) - applied_control = self.get_object() - data = request.data - new_folder = Folder.objects.get(id=data["folder"]) - duplicate_applied_control = AppliedControl.objects.create( + def duplicate_into_folder(applied_control: AppliedControl, data: dict, folder: Folder) -> AppliedControl : + return duplicate_applied_control = AppliedControl.objects.create( reference_control=applied_control.reference_control, name=data["name"], description=data["description"], @@ -968,6 +966,12 @@ def duplicate(self, request, pk): effort=applied_control.effort, cost=applied_control.cost, ) + + applied_control = self.get_object() + data = request.data + new_folder = Folder.objects.get(id=data["folder"]) + duplicate_applied_control = duplicate_into_folder(applied_control, data, new_folder) + if data["duplicate_evidences"]: duplicate_related_objects( applied_control, duplicate_applied_control, new_folder, "evidences"