From 13c51467b022b4b5f142c3489fb23d536fc36909 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Fri, 13 Dec 2024 16:47:32 +0100 Subject: [PATCH] feat: add gravity to operational scenario view --- backend/ebios_rm/models.py | 29 ++++++ backend/ebios_rm/serializers.py | 1 + frontend/messages/en.json | 3 +- .../src/lib/components/Forms/ModelForm.svelte | 2 +- frontend/src/lib/utils/crud.ts | 8 +- .../[id=uuid]/edit/+layout.server.ts | 5 +- .../[id=uuid]/edit/+page.svelte | 2 +- .../operational-scenario/+page.server.ts | 4 +- .../operational-scenario/+page.svelte | 10 +- .../[id=uuid]/+page.server.ts | 2 +- .../[id=uuid]/+page.svelte | 99 +++++++++++++------ 11 files changed, 124 insertions(+), 41 deletions(-) diff --git a/backend/ebios_rm/models.py b/backend/ebios_rm/models.py index dbe56bfb8..8affb08d6 100644 --- a/backend/ebios_rm/models.py +++ b/backend/ebios_rm/models.py @@ -246,6 +246,14 @@ def get_pertinence(self): PERTINENCE_MATRIX[self.motivation - 1][self.resources - 1] ).label + @property + def gravity(self): + gravity = -1 + for feared_event in self.feared_events.all(): + if feared_event.gravity > gravity: + gravity = feared_event.gravity + return gravity + class Stakeholder(AbstractBaseModel, FolderMixin): class Category(models.TextChoices): @@ -398,6 +406,9 @@ def save(self, *args, **kwargs): self.folder = self.ebios_rm_study.folder super().save(*args, **kwargs) + def get_gravity(self): + return self.ro_to_couple.gravity + class OperationalScenario(AbstractBaseModel, FolderMixin): ebios_rm_study = models.ForeignKey( @@ -455,3 +466,21 @@ def get_likelihood_display(self): **risk_matrix["probability"][self.likelihood], "value": self.likelihood, } + + def get_gravity_display(self): + gravity = -1 + for attack_path in self.attack_paths.all(): + if attack_path.get_gravity() > gravity: + gravity = attack_path.get_gravity() + if gravity < 0: + return { + "abbreviation": "--", + "name": "--", + "description": "not rated", + "value": -1, + } + risk_matrix = self.parsed_matrix + return { + **risk_matrix["impact"][gravity], + "value": gravity, + } diff --git a/backend/ebios_rm/serializers.py b/backend/ebios_rm/serializers.py index 3eed45bf0..20256f96c 100644 --- a/backend/ebios_rm/serializers.py +++ b/backend/ebios_rm/serializers.py @@ -160,6 +160,7 @@ class OperationalScenarioReadSerializer(BaseModelSerializer): attack_paths = FieldsRelatedField(many=True) threats = FieldsRelatedField(many=True) likelihood = serializers.JSONField(source="get_likelihood_display") + gravity = serializers.JSONField(source="get_gravity_display") class Meta: model = OperationalScenario diff --git a/frontend/messages/en.json b/frontend/messages/en.json index 1ff8e9333..601d30e06 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -1000,5 +1000,6 @@ "likely": "Likely", "unlikely": "Unlikely", "veryLikely": "Very likely", - "certain": "Certain" + "certain": "Certain", + "minor": "Minor" } diff --git a/frontend/src/lib/components/Forms/ModelForm.svelte b/frontend/src/lib/components/Forms/ModelForm.svelte index afc9eb231..939955bce 100644 --- a/frontend/src/lib/components/Forms/ModelForm.svelte +++ b/frontend/src/lib/components/Forms/ModelForm.svelte @@ -273,7 +273,7 @@ {:else if URLModel === 'attack-paths'} {:else if URLModel === 'operational-scenarios'} - + {/if}
{#if closeModal} diff --git a/frontend/src/lib/utils/crud.ts b/frontend/src/lib/utils/crud.ts index a6ed45334..b413e40f2 100644 --- a/frontend/src/lib/utils/crud.ts +++ b/frontend/src/lib/utils/crud.ts @@ -692,7 +692,13 @@ export const URL_MODEL_MAP: ModelMap = { foreignKeyFields: [ { field: 'ebios_rm_study', urlModel: 'ebios-rm' }, { field: 'threats', urlModel: 'threats' }, - { field: 'attack_paths', urlModel: 'attack-paths', endpointUrl: 'ebios-rm/attack-paths', urlParams: 'ebios_rm_study=', detail: true }, + { + field: 'attack_paths', + urlModel: 'attack-paths', + endpointUrl: 'ebios-rm/attack-paths', + urlParams: 'ebios_rm_study=', + detail: true + } ], selectFields: [{ field: 'likelihood', valueType: 'number', detail: true }] } diff --git a/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/edit/+layout.server.ts b/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/edit/+layout.server.ts index 1b0c7b45a..dadfb90bb 100644 --- a/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/edit/+layout.server.ts +++ b/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/edit/+layout.server.ts @@ -52,7 +52,10 @@ export const load: LayoutServerLoad = async (event) => { let url = keyModel.endpointUrl ? `${BASE_API_URL}/${keyModel.endpointUrl}/${queryParams}` : `${BASE_API_URL}/${keyModel.urlModel}/${queryParams}`; - if (['assets', 'attack-paths'].includes(keyModel.urlModel) && ['feared-events', 'operational-scenarios'].includes(event.params.model)) { + if ( + ['assets', 'attack-paths'].includes(keyModel.urlModel) && + ['feared-events', 'operational-scenarios'].includes(event.params.model) + ) { url = `${BASE_API_URL}/${keyModel.endpointUrl || keyModel.urlModel}/${queryParams}${object.ebios_rm_study}`; } const response = await event.fetch(url); diff --git a/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/edit/+page.svelte b/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/edit/+page.svelte index 3f8b8b4d0..5551caac7 100644 --- a/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/edit/+page.svelte +++ b/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/edit/+page.svelte @@ -16,6 +16,6 @@ selectOptions={data.selectOptions} foreignKeys={data.foreignKeys} model={data.model} - customNameDescription={customNameDescription} + {customNameDescription} context="edit" /> diff --git a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-four/operational-scenario/+page.server.ts b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-four/operational-scenario/+page.server.ts index f5d61cb84..dc296d006 100644 --- a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-four/operational-scenario/+page.server.ts +++ b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-four/operational-scenario/+page.server.ts @@ -36,7 +36,9 @@ export const load: PageServerLoad = async ({ params, fetch }) => { for (const keyField of foreignKeyFields) { const keyModel = getModelInfo(keyField.urlModel); - const queryParams = keyField.urlParams ? `?${keyField.urlParams}${keyField.detail ? params.id : ''}` : ''; + const queryParams = keyField.urlParams + ? `?${keyField.urlParams}${keyField.detail ? params.id : ''}` + : ''; const url = keyModel.endpointUrl ? `${BASE_API_URL}/${keyModel.endpointUrl}/${queryParams}` : `${BASE_API_URL}/${keyModel.urlModel}/${queryParams}`; diff --git a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-four/operational-scenario/+page.svelte b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-four/operational-scenario/+page.svelte index 733f7ca25..feeb89c3f 100644 --- a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-four/operational-scenario/+page.svelte +++ b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-four/operational-scenario/+page.svelte @@ -21,7 +21,8 @@ ref: CreateModal, props: { form: data.createForm, - model: data.model + model: data.model, + customNameDescription: true } }; let modal: ModalSettings = { @@ -64,7 +65,12 @@ }); - +