From 293070bdeeb681cf97375ca63204a1ccb3a7b479 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Mon, 16 Dec 2024 11:40:02 +0100 Subject: [PATCH] style: improve detailed view --- backend/ebios_rm/models.py | 43 ++++- backend/ebios_rm/serializers.py | 2 + frontend/messages/en.json | 3 +- .../[id=uuid]/+page.svelte | 181 +++++++++++------- 4 files changed, 151 insertions(+), 78 deletions(-) diff --git a/backend/ebios_rm/models.py b/backend/ebios_rm/models.py index 315f06a66c..abc2cdf4cc 100644 --- a/backend/ebios_rm/models.py +++ b/backend/ebios_rm/models.py @@ -12,6 +12,7 @@ ) from iam.models import FolderMixin, User from tprm.models import Entity +import json class EbiosRMStudy(NameDescriptionMixin, ETADueDateMixin, FolderMixin): @@ -453,6 +454,23 @@ def risk_matrix(self): def parsed_matrix(self): return self.risk_matrix.parse_json_translated() + @property + def ref_id(self): + sorted_operational_scenarios = list( + OperationalScenario.objects.filter( + ebios_rm_study=self.ebios_rm_study + ).order_by("created_at") + ) + return sorted_operational_scenarios.index(self) + 1 + + @property + def gravity(self): + gravity = -1 + for attack_path in self.attack_paths.all(): + if attack_path.gravity > gravity: + gravity = attack_path.gravity + return gravity + def get_likelihood_display(self): if self.likelihood < 0: return { @@ -468,11 +486,21 @@ def get_likelihood_display(self): } def get_gravity_display(self): - gravity = -1 - for attack_path in self.attack_paths.all(): - if attack_path.gravity > gravity: - gravity = attack_path.gravity - if gravity < 0: + if self.gravity < 0: + return { + "abbreviation": "--", + "name": "--", + "description": "not rated", + "value": -1, + } + risk_matrix = self.parsed_matrix + return { + **risk_matrix["impact"][self.gravity], + "value": self.gravity, + } + + def get_risk_level_display(self): + if self.likelihood < 0 or self.gravity < 0: return { "abbreviation": "--", "name": "--", @@ -480,7 +508,8 @@ def get_gravity_display(self): "value": -1, } risk_matrix = self.parsed_matrix + risk_index = risk_matrix["grid"][self.likelihood][self.gravity] return { - **risk_matrix["impact"][gravity], - "value": gravity, + **risk_matrix["risk"][risk_index], + "value": risk_index, } diff --git a/backend/ebios_rm/serializers.py b/backend/ebios_rm/serializers.py index 20256f96ca..3a052d016b 100644 --- a/backend/ebios_rm/serializers.py +++ b/backend/ebios_rm/serializers.py @@ -161,6 +161,8 @@ class OperationalScenarioReadSerializer(BaseModelSerializer): threats = FieldsRelatedField(many=True) likelihood = serializers.JSONField(source="get_likelihood_display") gravity = serializers.JSONField(source="get_gravity_display") + risk_level = serializers.JSONField(source="get_risk_level_display") + ref_id = serializers.CharField() class Meta: model = OperationalScenario diff --git a/frontend/messages/en.json b/frontend/messages/en.json index dcdeaefbce..1a9d9af3ec 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -993,7 +993,8 @@ "noAuthor": "No author assigned", "noReviewer": "No reviewer assigned", "selectAudit": "Select audit", - "operarionalScenario": "Operational scenario", + "operationalScenario": "Operational scenario", + "operationalScenarioRefId": "Operational scenario {refId}", "operationalScenarios": "Operational scenarios", "addOperationalScenario": "Add operational scenario", "workshopFour": "Workshop 4", diff --git a/frontend/src/routes/(app)/(internal)/operational-scenarios/[id=uuid]/+page.svelte b/frontend/src/routes/(app)/(internal)/operational-scenarios/[id=uuid]/+page.svelte index 4c24d40ee9..4a0fedf0ec 100644 --- a/frontend/src/routes/(app)/(internal)/operational-scenarios/[id=uuid]/+page.svelte +++ b/frontend/src/routes/(app)/(internal)/operational-scenarios/[id=uuid]/+page.svelte @@ -3,13 +3,15 @@ import * as m from '$paraglide/messages'; import { page } from '$app/stores'; import { pageTitle } from '$lib/utils/stores'; - import { safeTranslate } from '$lib/utils/i18n'; import ModelTable from '$lib/components/ModelTable/ModelTable.svelte'; + import { popup, type PopupSettings } from '@skeletonlabs/skeleton'; export let data: PageData; const operationalScenario = data.data; + pageTitle.set(m.operationalScenarioRefId({ refId: operationalScenario.ref_id })); + let activeActivity: string | null = null; $page.url.searchParams.forEach((value, key) => { if (key === 'activity' && value === 'one') { @@ -21,22 +23,42 @@ } }); - const likelihoodChoices = [ - { label: m.unlikely(), value: 0 }, - { label: m.likely(), value: 1 }, - { label: m.veryLikely(), value: 2 }, - { label: m.certain(), value: 3 } - ]; - const gravityChoices = [ - { label: m.minor(), value: 0 }, - { label: m.significant(), value: 1 }, - { label: m.important(), value: 2 }, - { label: m.critical(), value: 3 } - ]; + const popupLikelihood: PopupSettings = { + event: 'click', + target: 'popupLikelihood', + placement: 'bottom' + }; + const popupGravity: PopupSettings = { + event: 'click', + target: 'popupGravity', + placement: 'bottom' + }; + const popupRiskLevel: PopupSettings = { + event: 'click', + target: 'popupRiskLevel', + placement: 'bottom' + };
-
+
+

+ {operationalScenario.ebios_rm_study.str} + - {m.operationalScenarioRefId({ refId: operationalScenario.ref_id })} +

+ {#if operationalScenario.is_selected} + {m.selected()} + {:else} + {m.notSelected()} + {/if} +

+

{m.selected()} - {:else} - {m.notSelected()} - {/if} -

-
-

- - {m.likelihood()} -

-
- {#each likelihoodChoices as choice} - {#if operationalScenario.likelihood.value === choice.value} -
- {choice.label} - ({choice.value}) -
- {:else} -
- {choice.label} - ({choice.value}) -
- {/if} - {/each} +
+
+
+

+ {operationalScenario.likelihood.description} +

+
+
+

+ + {m.likelihood()} +

+ {operationalScenario.likelihood.name} +
-
-
-

- - {m.gravity()} -

-
- {#each gravityChoices as choice} - {#if operationalScenario.gravity.value === choice.value} -
- {choice.label} - ({choice.value}) -
- {:else} -
- {choice.label} - ({choice.value}) -
- {/if} - {/each} + +
+
+

+ {operationalScenario.gravity.description} +

+
+
+

+ + {m.gravity()} +

+ {operationalScenario.gravity.name} + +
+ +
+
+

+ {operationalScenario.risk_level.description} +

+
+
+

+ + {m.riskLevel()} +

+ {operationalScenario.risk_level.name} +