From 2fb62028ab7884d11681c664e8edc026ab971f48 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Mon, 16 Dec 2024 12:48:58 +0100 Subject: [PATCH] feat: change operational scenario/attack path relationship --- backend/ebios_rm/migrations/0001_initial.py | 9 ++++---- backend/ebios_rm/models.py | 14 ++++++------- backend/ebios_rm/serializers.py | 2 +- .../ModelForm/OperationalScenarioForm.svelte | 21 ++++++++++--------- frontend/src/lib/utils/crud.ts | 2 +- frontend/src/lib/utils/schemas.ts | 2 +- .../[id=uuid]/+page.svelte | 2 +- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/backend/ebios_rm/migrations/0001_initial.py b/backend/ebios_rm/migrations/0001_initial.py index 8980b23f0f..9e8778c5f9 100644 --- a/backend/ebios_rm/migrations/0001_initial.py +++ b/backend/ebios_rm/migrations/0001_initial.py @@ -354,12 +354,13 @@ class Migration(migrations.Migration): models.TextField(blank=True, verbose_name="Justification"), ), ( - "attack_paths", - models.ManyToManyField( - help_text="Attack paths that are pertinent to the operational scenario", - related_name="operational_scenarios", + "attack_path", + models.OneToOneField( + help_text="Attack path that is pertinent to the operational scenario", + related_name="operational_scenario", to="ebios_rm.attackpath", verbose_name="Attack paths", + on_delete=django.db.models.deletion.CASCADE, ), ), ( diff --git a/backend/ebios_rm/models.py b/backend/ebios_rm/models.py index abc2cdf4cc..0459a2d357 100644 --- a/backend/ebios_rm/models.py +++ b/backend/ebios_rm/models.py @@ -418,11 +418,12 @@ class OperationalScenario(AbstractBaseModel, FolderMixin): related_name="operational_scenarios", on_delete=models.CASCADE, ) - attack_paths = models.ManyToManyField( + attack_path = models.OneToOneField( AttackPath, verbose_name=_("Attack paths"), - related_name="operational_scenarios", - help_text=_("Attack paths that are pertinent to the operational scenario"), + related_name="operational_scenario", + help_text=_("Attack path that is pertinent to the operational scenario"), + on_delete=models.CASCADE, ) threats = models.ManyToManyField( Threat, @@ -465,11 +466,7 @@ def ref_id(self): @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 + return self.attack_path.gravity def get_likelihood_display(self): if self.likelihood < 0: @@ -478,6 +475,7 @@ def get_likelihood_display(self): "name": "--", "description": "not rated", "value": -1, + "hexcolor": "#f9fafb", } risk_matrix = self.parsed_matrix return { diff --git a/backend/ebios_rm/serializers.py b/backend/ebios_rm/serializers.py index 3a052d016b..dad2156958 100644 --- a/backend/ebios_rm/serializers.py +++ b/backend/ebios_rm/serializers.py @@ -157,7 +157,7 @@ class OperationalScenarioReadSerializer(BaseModelSerializer): str = serializers.CharField(source="__str__") ebios_rm_study = FieldsRelatedField() folder = FieldsRelatedField() - attack_paths = FieldsRelatedField(many=True) + attack_path = FieldsRelatedField() threats = FieldsRelatedField(many=True) likelihood = serializers.JSONField(source="get_likelihood_display") gravity = serializers.JSONField(source="get_gravity_display") diff --git a/frontend/src/lib/components/Forms/ModelForm/OperationalScenarioForm.svelte b/frontend/src/lib/components/Forms/ModelForm/OperationalScenarioForm.svelte index fc57071272..8dd9c15b50 100644 --- a/frontend/src/lib/components/Forms/ModelForm/OperationalScenarioForm.svelte +++ b/frontend/src/lib/components/Forms/ModelForm/OperationalScenarioForm.svelte @@ -72,16 +72,17 @@ bind:cachedValue={formDataCache['threats']} label={m.threats()} /> - + {#if context !== 'edit'} + + {/if}

- {m.attackPaths()} + {m.attackPath()}