From c2579d55ae0e5210409dfe81ff50a53bf0400cc2 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Fri, 20 Dec 2024 14:39:52 +0100 Subject: [PATCH] fix: risk assessment generation --- backend/core/models.py | 2 +- backend/core/serializers.py | 3 ++- .../migrations/0009_alter_roto_activity.py | 20 ++++++++++++++----- backend/ebios_rm/models.py | 2 +- backend/ebios_rm/views.py | 2 +- .../risk-assessments/[id=uuid]/+page.svelte | 11 ++++++++++ 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/backend/core/models.py b/backend/core/models.py index 7407d4853..3b0860c8a 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -1501,7 +1501,7 @@ def get_descendants(self) -> set[Self]: children = self.get_children() sub_children = set() for child in children: - sub_children.append(child) + sub_children.add(child) sub_children.update(child.get_descendants()) return sub_children diff --git a/backend/core/serializers.py b/backend/core/serializers.py index 6595dd66a..75547b1ff 100644 --- a/backend/core/serializers.py +++ b/backend/core/serializers.py @@ -210,10 +210,11 @@ class RiskAssessmentReadSerializer(AssessmentReadSerializer): risk_scenarios = FieldsRelatedField(many=True) risk_scenarios_count = serializers.IntegerField(source="risk_scenarios.count") risk_matrix = FieldsRelatedField() + ebios_rm_study = FieldsRelatedField(["id", "name"]) class Meta: model = RiskAssessment - exclude = ["ebios_rm_study"] + exclude = [] class AssetWriteSerializer(BaseModelSerializer): diff --git a/backend/ebios_rm/migrations/0009_alter_roto_activity.py b/backend/ebios_rm/migrations/0009_alter_roto_activity.py index 3705c2d84..86b3f5d53 100644 --- a/backend/ebios_rm/migrations/0009_alter_roto_activity.py +++ b/backend/ebios_rm/migrations/0009_alter_roto_activity.py @@ -5,15 +5,25 @@ class Migration(migrations.Migration): - dependencies = [ - ('ebios_rm', '0008_remove_attackpath_ro_to_couple_strategicscenario_and_more'), + ("ebios_rm", "0008_remove_attackpath_ro_to_couple_strategicscenario_and_more"), ] operations = [ migrations.AlterField( - model_name='roto', - name='activity', - field=models.PositiveSmallIntegerField(choices=[(0, 'undefined'), (1, 'very_low'), (2, 'low'), (3, 'moderate'), (4, 'important')], default=0, validators=[django.core.validators.MaxValueValidator(4)], verbose_name='Activity'), + model_name="roto", + name="activity", + field=models.PositiveSmallIntegerField( + choices=[ + (0, "undefined"), + (1, "very_low"), + (2, "low"), + (3, "moderate"), + (4, "important"), + ], + default=0, + validators=[django.core.validators.MaxValueValidator(4)], + verbose_name="Activity", + ), ), ] diff --git a/backend/ebios_rm/models.py b/backend/ebios_rm/models.py index 584b70dff..5b35766fc 100644 --- a/backend/ebios_rm/models.py +++ b/backend/ebios_rm/models.py @@ -655,7 +655,7 @@ def ro_to(self): def get_assets(self): initial_assets = Asset.objects.filter( - feared_events__in=self.ro_to.feared_events.all(), is_selected=True + feared_events__in=self.ro_to.feared_events.filter(is_selected=True) ) assets = set() for asset in initial_assets: diff --git a/backend/ebios_rm/views.py b/backend/ebios_rm/views.py index 59535e697..92f8c7ca2 100644 --- a/backend/ebios_rm/views.py +++ b/backend/ebios_rm/views.py @@ -139,7 +139,7 @@ def motivation(self, request): @action(detail=False, name="Get resources choices") def resources(self, request): return Response(dict(RoTo.Resources.choices)) - + @action(detail=False, name="Get activity choices") def activity(self, request): return Response(dict(RoTo.Activity.choices)) diff --git a/frontend/src/routes/(app)/(internal)/risk-assessments/[id=uuid]/+page.svelte b/frontend/src/routes/(app)/(internal)/risk-assessments/[id=uuid]/+page.svelte index 8286307d0..8910121e3 100644 --- a/frontend/src/routes/(app)/(internal)/risk-assessments/[id=uuid]/+page.svelte +++ b/frontend/src/routes/(app)/(internal)/risk-assessments/[id=uuid]/+page.svelte @@ -199,6 +199,17 @@ >
+
+ {m.ebiosRmStudy()}: + {risk_assessment.ebios_rm_study.name} +
+
{m.description()}: