From 22696eca39be060a25094fb48886e78faf923ce7 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Tue, 17 Dec 2024 21:59:38 +0100 Subject: [PATCH] feat: add strategic scenario filters --- backend/ebios_rm/models.py | 15 +++++++++++++++ backend/ebios_rm/serializers.py | 1 + frontend/src/lib/utils/table.ts | 8 +++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/backend/ebios_rm/models.py b/backend/ebios_rm/models.py index 42dd525d1..6439ebdff 100644 --- a/backend/ebios_rm/models.py +++ b/backend/ebios_rm/models.py @@ -411,6 +411,21 @@ def get_scope(self): def save(self, *args, **kwargs): self.folder = self.ebios_rm_study.folder super().save(*args, **kwargs) + + def get_gravity_display(self): + if self.ro_to_couple.get_gravity() < 0: + return { + "abbreviation": "--", + "name": "--", + "description": "not rated", + "value": -1, + "hexcolor": "#f9fafb", + } + risk_matrix = self.parsed_matrix + return { + **risk_matrix["impact"][self.ro_to_couple.get_gravity()], + "value": self.ro_to_couple.get_gravity(), + } class AttackPath(NameDescriptionMixin, FolderMixin): diff --git a/backend/ebios_rm/serializers.py b/backend/ebios_rm/serializers.py index 9a56bd5d2..e5f0b8f7d 100644 --- a/backend/ebios_rm/serializers.py +++ b/backend/ebios_rm/serializers.py @@ -139,6 +139,7 @@ class StrategicScenarioReadSerializer(BaseModelSerializer): ebios_rm_study = FieldsRelatedField() folder = FieldsRelatedField() ro_to_couple = FieldsRelatedField() + gravity = serializers.JSONField(source="get_gravity_display") class Meta: model = StrategicScenario diff --git a/frontend/src/lib/utils/table.ts b/frontend/src/lib/utils/table.ts index dbfa0e24a..3a7e93bc9 100644 --- a/frontend/src/lib/utils/table.ts +++ b/frontend/src/lib/utils/table.ts @@ -4,7 +4,6 @@ import SelectFilter from '$lib/components/Filters/SelectFilter.svelte'; import type { ComponentType } from 'svelte'; import { LOCALE_DISPLAY_MAP } from './constants'; import type { Row } from '@vincjo/datatables'; -import { category, entity } from '$paraglide/messages'; interface ListViewFilterConfig { component: ComponentType; @@ -705,8 +704,11 @@ export const listViewFields: ListViewFieldsConfig = { } }, 'strategic-scenarios': { - head: ['ref_id', 'name', 'description', 'ro_to_couple', 'attackPaths'], - body: ['ref_id', 'name', 'description', 'ro_to_couple', 'attack_paths'] + head: ['ref_id', 'name', 'description', 'ro_to_couple', 'attackPaths', 'gravity'], + body: ['ref_id', 'name', 'description', 'ro_to_couple', 'attack_paths', 'gravity'], + filters: { + gravity: GRAVITY_FILTER + } }, 'attack-paths': { head: ['is_selected', 'name', 'stakeholders', 'description'],