From 01dffac15107c2ccc967238a861dc2fda49b4592 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Wed, 15 May 2024 15:30:37 +0200 Subject: [PATCH] feat: prepare action plan API --- backend/core/models.py | 3 +++ backend/core/views.py | 27 +++++++++++++++++++ frontend/src/lib/utils/locales.ts | 3 ++- .../[id=uuid]/+page.svelte | 2 +- .../[id=uuid]/plan/+page.svelte | 0 5 files changed, 33 insertions(+), 2 deletions(-) delete mode 100644 frontend/src/routes/(app)/compliance-assessments/[id=uuid]/plan/+page.svelte diff --git a/backend/core/models.py b/backend/core/models.py index 73ff08b8e..0ca553bdc 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -1319,6 +1319,9 @@ def get_selected_implementation_groups(self): if group.get("ref_id") in self.selected_implementation_groups ] + def get_requirement_assessments(self): + return RequirementAssessment.objects.filter(compliance_assessment=self) + def get_requirements_status_count(self): requirements_status_count = [] for st in RequirementAssessment.Status: diff --git a/backend/core/views.py b/backend/core/views.py index bc70c8562..05349415d 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -1188,6 +1188,33 @@ def selected_implementation_groups(self, request, pk): } return Response(implementation_group_choices) + @action(detail=True, methods=["get"], name="Get action plan data") + def action_plan(self, request, pk): + (viewable_objects, _, _) = RoleAssignment.get_accessible_object_ids( + folder=Folder.get_root_folder(), + user=request.user, + object_type=ComplianceAssessment, + ) + if UUID(pk) in viewable_objects: + response = {"planned": dict(), "active": dict(), "inactive": dict(), "none": dict()} + compliance_assessment_object = self.get_object() + requirement_assessments_objects = ( + compliance_assessment_object.get_requirement_assessments() + ) + applied_controls = AppliedControlReadSerializer( + AppliedControl.objects.filter( + requirement_assessments__in=requirement_assessments_objects + ), + many=True, + ).data + for applied_control in applied_controls: + response[applied_control["status"].lower()].update( + applied_control + ) if applied_control["status"] else response["none"].update( + applied_control + ) + return Response(response) + def perform_create(self, serializer): """ Create RequirementAssessment objects for the newly created ComplianceAssessment diff --git a/frontend/src/lib/utils/locales.ts b/frontend/src/lib/utils/locales.ts index 71ba70738..849354c78 100644 --- a/frontend/src/lib/utils/locales.ts +++ b/frontend/src/lib/utils/locales.ts @@ -334,7 +334,8 @@ export function localItems(languageTag: string): LocalItems { }), attemptToRemoveOnlyAdminUserGroup: m.attemptToRemoveOnlyAdminUserGroup({ languageTag: languageTag - }) + }), + actionPlan: m.actionPlan({ languageTag: languageTag }), }; return LOCAL_ITEMS; } diff --git a/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/+page.svelte b/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/+page.svelte index b3fb0f3a3..69bd1421f 100644 --- a/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/+page.svelte +++ b/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/+page.svelte @@ -194,7 +194,7 @@ > {/if} - {m.actionPlan()} diff --git a/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/plan/+page.svelte b/frontend/src/routes/(app)/compliance-assessments/[id=uuid]/plan/+page.svelte deleted file mode 100644 index e69de29bb..000000000