Skip to content

Commit

Permalink
feat: prepare action plan API
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed May 15, 2024
1 parent 0c3fa4b commit 01dffac
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 27 additions & 0 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/utils/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ export function localItems(languageTag: string): LocalItems {
}),
attemptToRemoveOnlyAdminUserGroup: m.attemptToRemoveOnlyAdminUserGroup({
languageTag: languageTag
})
}),
actionPlan: m.actionPlan({ languageTag: languageTag }),
};
return LOCAL_ITEMS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
>
{/if}
</div>
<a href="#" class="btn variant-filled-primary h-fit"
<a href={`${$page.url.pathname}/action-plan`} class="btn variant-filled-primary h-fit"
><i class="fa-solid fa-heart-pulse mr-2" />{m.actionPlan()}</a
>
</div>
Expand Down
Empty file.

0 comments on commit 01dffac

Please sign in to comment.