Skip to content

Commit

Permalink
Impact graph for applied controls
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-smith committed Dec 23, 2024
1 parent 10c2d37 commit 02ce510
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
83 changes: 83 additions & 0 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,89 @@ def impact_graph(self, request):
(viewable_controls_ids, _, _) = RoleAssignment.get_accessible_object_ids(
Folder.get_root_folder(), request.user, AppliedControl
)
csf_functions_map = dict()
categories = [{"name": "--"}]
for i, option in enumerate(ReferenceControl.CSF_FUNCTION, 1):
csf_functions_map[option[0]] = i
categories.append({"name": option[1]})
categories.append({"name": "requirements"}) # 7
categories.append({"name": "scenarios"}) # 9
categories.append({"name": "audits"}) # 8
categories.append({"name": "risk assessments"})

nodes = list()
links = list()
indexes = dict()
idx_cnt = 0
for ac in AppliedControl.objects.filter(id__in=viewable_controls_ids):
nodes.append(
{
"name": ac.name,
"value": ac.name,
"category": csf_functions_map.get(ac.csf_function, 0),
}
)
indexes[ac.id] = idx_cnt
idx_cnt += 1
# attached requirement_assessments
for req in RequirementAssessment.objects.filter(applied_controls__id=ac.id):
nodes.append(
{
"name": req.requirement.ref_id,
"value": req.requirement.description,
"category": 7,
"symbol": "triangle",
}
)
indexes[req.id] = (
idx_cnt # not good - even if the probability of collision is low
)
idx_cnt += 1

audit = req.compliance_assessment
if indexes.get(audit.id) is None:
nodes.append(
{
"name": audit.name,
"value": audit.framework.name,
"category": 9,
"symbol": "rect",
}
)
indexes[audit.id] = idx_cnt
idx_cnt += 1
links.append({"source": indexes[audit.id], "target": indexes[req.id]})

links.append({"source": indexes[ac.id], "target": indexes[req.id]})
for sc in RiskScenario.objects.filter(applied_controls__id=ac.id):
nodes.append(
{
"name": sc.ref_id,
"value": sc.name,
"category": 8,
"symbol": "diamond",
}
)
indexes[sc.id] = idx_cnt
idx_cnt += 1

ra = sc.risk_assessment
if indexes.get(ra.id) is None:
nodes.append(
{
"name": ra.name,
"value": ra.name,
"category": 10,
"symbol": "rect",
}
)
indexes[ra.id] = idx_cnt
idx_cnt += 1
links.append({"source": indexes[ra.id], "target": indexes[sc.id]})

links.append({"source": indexes[ac.id], "target": indexes[sc.id]})

return Response({"nodes": nodes, "categories": categories, "links": links})


class PolicyViewSet(AppliedControlViewSet):
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/components/DataViz/GraphExplorer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export let classesContainer = '';
export let title = '';
export let layout = 'force';
export let initLayout = 'circular';
export let edgeLength = 50;
export let name = 'graph';
Expand Down Expand Up @@ -81,7 +82,7 @@
gravity: 0.05,
layoutAnimation: true,
friction: 0.1,
initLayout: 'circular'
initLayout: initLayout
},
labelLayout: {
hideOverlap: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import { BASE_API_URL } from '$lib/utils/constants';

import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ params, fetch }) => {
const endpoint = `${BASE_API_URL}/applied-controls/impact_graph/`;

const res = await fetch(endpoint);
const data = await res.json();

return { data };
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script lang="ts">
import type { PageData } from './$types';
export let data: PageData;
import GraphExplorer from '$lib/components/DataViz/GraphExplorer.svelte';
import { pageTitle } from '$lib/utils/stores';
</script>

<div class="bg-white shadow flex overflow-x-auto">
<div class="w-full h-screen">
<GraphExplorer title="Mapping Explorer" initLayout="circular" data={data.data} />
</div>
</div>

0 comments on commit 02ce510

Please sign in to comment.