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

Fix/requirement counts #98

Merged
merged 3 commits into from
Feb 29, 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
15 changes: 7 additions & 8 deletions backend/core/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import date, timedelta
from re import sub

from django.db.models import Count
from django.shortcuts import get_object_or_404
Expand All @@ -8,6 +7,7 @@
from core.serializers import SecurityFunctionReadSerializer, ThreatReadSerializer

from .models import *
from .utils import camel_case

STATUS_COLOR_MAP = { # TODO: Move these kinds of color maps to frontend
"--": "#fac858",
Expand All @@ -25,12 +25,6 @@
}


def camel_case(s):
s = sub(r"(_|-)+", " ", s).title().replace(" ", "")

return "".join([s[0].lower(), s[1:]])


def security_measure_priority(user: User):
def get_quadrant(security_measure):
if security_measure.effort in ["S", "M"]:
Expand Down Expand Up @@ -253,6 +247,7 @@ def get_sorted_requirement_nodes_rec(
"leaf_content": req.display_long(),
"status": req_as.status,
"status_display": req_as.get_status_display(),
"status_i18n": camel_case(req_as.status),
"style": "leaf",
"threats": ThreatReadSerializer(
req.threats.all(), many=True
Expand Down Expand Up @@ -844,6 +839,10 @@ def compile_risk_assessment_for_composer(user, risk_assessment_list: list):
"untreated_h_vh": untreated_h_vh,
"accepted": accepted,
},
"security_measure_status": {"localLables":local_lables, "labels": labels, "values": values},
"security_measure_status": {
"localLables": local_lables,
"labels": labels,
"values": values,
},
"colors": get_risk_color_ordered_list(user, risk_assessment_list),
}
9 changes: 6 additions & 3 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .base_models import *
from .validators import validate_file_size, validate_file_name
from .utils import camel_case
from iam.models import FolderMixin
from django.core import serializers

Expand Down Expand Up @@ -779,9 +780,9 @@ def quality_check(self) -> dict:
if not self.authors.all():
info_lst.append(
{
"msg": _(
"{}: No author assigned to this risk assessment"
).format(str(self)),
"msg": _("{}: No author assigned to this risk assessment").format(
str(self)
),
"obj_type": "risk_assessment",
"object": _object,
}
Expand Down Expand Up @@ -1281,13 +1282,15 @@ def donut_render(self) -> dict:
count = (
RequirementAssessment.objects.filter(status=st)
.filter(compliance_assessment=self)
.filter(requirement__assessable=True)
.count()
)
total = RequirementAssessment.objects.filter(
compliance_assessment=self
).count()
v = {
"name": st.label,
"localName": camel_case(st.value),
"value": count,
"itemStyle": {"color": color_map[st]},
}
Expand Down
7 changes: 7 additions & 0 deletions backend/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from django.utils.translation import gettext_lazy as _
from re import sub
from enum import Enum


def camel_case(s):
s = sub(r"(_|-)+", " ", s).title().replace(" ", "")

return "".join([s[0].lower(), s[1:]])


class RoleCodename(Enum):
ADMINISTRATOR = "BI-RL-ADM"
DOMAIN_MANAGER = "BI-RL-DMA"
Expand Down
14 changes: 9 additions & 5 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ def generate_html(
)

assessments = RequirementAssessment.objects.filter(
compliance_assessment=compliance_assessment
compliance_assessment=compliance_assessment,
).all()

node_per_urn = {r.urn: r for r in requirement_nodes}
Expand All @@ -1366,7 +1366,9 @@ def bar_graph(node: RequirementNode):
content = ""
compliance_assessments_status = []
candidates = [
c for c in assessments if not (node) or c == node or node in ancestors[c]
c
for c in assessments.filter(requirement__assessable=True)
if not (node) or c == node or node in ancestors[c]
]
total = len(candidates)
for st in RequirementAssessment.Status:
Expand All @@ -1388,9 +1390,11 @@ def bar_graph(node: RequirementNode):
content += "bg-green-500"
elif stat[0] == "not_applicable":
content += "bg-black text-white dark:bg-white dark:text-black"
content += (
'" style="width:' + str(stat[1]) + '%"> ' + str(stat[1]) + "%</div>"
)
content += '" style="width:' + str(stat[1]) + '%"> '
if stat[0] != "to_do":
content += str(stat[1]) + "%"

content += "</div>"
content += "</div></div>"
return content

Expand Down
8 changes: 7 additions & 1 deletion frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,5 +370,11 @@
"current": "Current",
"residual": "Residual",
"jumpToRiskAssessment": "Jump to risk assessment",
"additionalMeasures": "Additional measures"
"additionalMeasures": "Additional measures",
"toDo": "To do",
"inProgress": "In progress",
"nonCompliant": "Non compliant",
"partiallyCompliant": "Partially compliant",
"compliant": "Compliant",
"notApplicable": "Not applicable"
}
8 changes: 7 additions & 1 deletion frontend/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,5 +372,11 @@
"current": "Courrant",
"residual": "Résiduel",
"jumpToRiskAssessment": "Passer à l'évaluation des risques",
"additionalMeasures": "Mesures supplémentaires"
"additionalMeasures": "Mesures supplémentaires",
"toDo": "À faire",
"inProgress": "En cours",
"nonCompliant": "Non conforme",
"partiallyCompliant": "Partiellement conforme",
"compliant": "Conforme",
"notApplicable": "Non applicable"
}
3 changes: 2 additions & 1 deletion frontend/src/lib/components/Chart/DonutChart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@
});
</script>

<div class="bg-white w-auto h-full" bind:this={chart_element} />
<div class="bg-white w-auto h-full" bind:this={chart_element} />

6 changes: 6 additions & 0 deletions frontend/src/lib/utils/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ export function localItems(languageTag: string): LocalItems {
lossOfAccountabilityChoice3: m.lossOfAccountabilityChoice3({ languageTag: languageTag }),
composer: m.composer({ languageTag: languageTag }),
plan: m.plan({ languageTag: languageTag }),
toDo: m.toDo({ languageTag: languageTag }),
inProgress: m.inProgress({ languageTag: languageTag }),
nonCompliant: m.nonCompliant({ languageTag: languageTag }),
partiallyCompliant: m.partiallyCompliant({ languageTag: languageTag }),
compliant: m.compliant({ languageTag: languageTag }),
notApplicable: m.notApplicable({ languageTag: languageTag })
};
return LOCAL_ITEMS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
lead: node.status ? TreeViewItemLead : '',
leadProps: {
status: node.status,
statusI18n: node.status_i18n,
assessable: node.assessable,
statusDisplay: node.status_display,
statusColor: complianceColorMap[node.status]
Expand Down Expand Up @@ -141,7 +142,7 @@
name="compliance_assessments"
s_label="compliance_assessments"
values={compliance_assessment_donut_values.values}
colors={compliance_assessment_donut_values.values.map(object => object.itemStyle.color)}
colors={compliance_assessment_donut_values.values.map((object) => object.itemStyle.color)}
/>
</div>
<div class="flex flex-row space-x-2 ml-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<script lang="ts">
import { localItems } from '$lib/utils/locales';
import { languageTag } from '$paraglide/runtime';

export let statusI18n: string;
export let statusDisplay: string;
export let statusColor: string;
export let assessable: boolean;

const lead = statusDisplay ?? '';
const lead = localItems(languageTag())[statusI18n] ?? statusDisplay ?? '';

$: classesText = statusColor === '#000000' ? 'text-white' : '';
</script>
Expand Down
Loading