Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impact graph #1231

Merged
merged 5 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,95 @@ def ids(self, request):

return Response(my_map)

@action(detail=False, name="Generate data for applied controls impact graph")
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):
model = Policy
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
Expand Up @@ -27,4 +27,10 @@
link="assets/graph"
tags={['analysis', 'assets']}
/>
<Article
title="Impact Analysis"
desc="Visualize the impact of your applied controls"
link="insights/controls-impact"
tags={['analysis', 'controls']}
/>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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>
Loading