diff --git a/backend/core/migrations/0046_riskassessment_ebios_rm_study.py b/backend/core/migrations/0046_riskassessment_ebios_rm_study.py new file mode 100644 index 000000000..36cc5a92c --- /dev/null +++ b/backend/core/migrations/0046_riskassessment_ebios_rm_study.py @@ -0,0 +1,26 @@ +# Generated by Django 5.1.4 on 2024-12-11 11:07 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("core", "0045_alter_appliedcontrol_category_and_more"), + ("ebios_rm", "0003_remove_ebiosrmstudy_risk_assessments"), + ] + + operations = [ + migrations.AddField( + model_name="riskassessment", + name="ebios_rm_study", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="risk_assessments", + to="ebios_rm.ebiosrmstudy", + verbose_name="EBIOS RM study", + ), + ), + ] diff --git a/backend/core/models.py b/backend/core/models.py index d201af8b3..cc08c0d35 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -1997,6 +1997,14 @@ class RiskAssessment(Assessment): ref_id = models.CharField( max_length=100, null=True, blank=True, verbose_name=_("reference id") ) + ebios_rm_study = models.ForeignKey( + "ebios_rm.EbiosRMStudy", + verbose_name=_("EBIOS RM study"), + on_delete=models.CASCADE, + null=True, + blank=True, + related_name="risk_assessments", + ) class Meta: verbose_name = _("Risk assessment") diff --git a/backend/core/serializers.py b/backend/core/serializers.py index e55df2c53..0e3c95ae7 100644 --- a/backend/core/serializers.py +++ b/backend/core/serializers.py @@ -212,7 +212,7 @@ class RiskAssessmentReadSerializer(AssessmentReadSerializer): class Meta: model = RiskAssessment - fields = "__all__" + exclude = ["ebios_rm_study"] class AssetWriteSerializer(BaseModelSerializer): diff --git a/backend/core/views.py b/backend/core/views.py index ad510618f..562e5f3ba 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -575,6 +575,7 @@ class RiskAssessmentViewSet(BaseModelViewSet): "authors", "risk_matrix", "status", + "ebios_rm_study", ] @action(detail=False, name="Risk assessments per status") diff --git a/backend/ebios_rm/migrations/0003_remove_ebiosrmstudy_risk_assessments.py b/backend/ebios_rm/migrations/0003_remove_ebiosrmstudy_risk_assessments.py new file mode 100644 index 000000000..d02c92ad2 --- /dev/null +++ b/backend/ebios_rm/migrations/0003_remove_ebiosrmstudy_risk_assessments.py @@ -0,0 +1,16 @@ +# Generated by Django 5.1.4 on 2024-12-11 11:07 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("ebios_rm", "0002_alter_roto_target_objective"), + ] + + operations = [ + migrations.RemoveField( + model_name="ebiosrmstudy", + name="risk_assessments", + ), + ] diff --git a/backend/ebios_rm/models.py b/backend/ebios_rm/models.py index 7b8853494..83ad19ea1 100644 --- a/backend/ebios_rm/models.py +++ b/backend/ebios_rm/models.py @@ -7,7 +7,6 @@ Asset, ComplianceAssessment, Qualification, - RiskAssessment, RiskMatrix, Threat, ) @@ -49,13 +48,6 @@ class Status(models.TextChoices): "Compliance assessments established as security baseline during workshop 1.4" ), ) - risk_assessments = models.ManyToManyField( - RiskAssessment, - blank=True, - verbose_name=_("Risk assessments"), - related_name="ebios_rm_studies", - help_text=_("Risk assessments generated at the end of workshop 4"), - ) reference_entity = models.ForeignKey( Entity, on_delete=models.PROTECT, diff --git a/backend/ebios_rm/views.py b/backend/ebios_rm/views.py index bf5ec10b4..71ddb5d7d 100644 --- a/backend/ebios_rm/views.py +++ b/backend/ebios_rm/views.py @@ -33,6 +33,11 @@ class EbiosRMStudyViewSet(BaseModelViewSet): def status(self, request): return Response(dict(EbiosRMStudy.Status.choices)) + @action(detail=True, name="Get risk matrix", url_path="risk-matrix") + def risk_matrix(self, request, pk=None): + ebios_rm_study = self.get_object() + return Response(RiskMatrixReadSerializer(ebios_rm_study.risk_matrix).data) + @method_decorator(cache_page(60 * LONG_CACHE_TTL)) @action(detail=True, name="Get gravity choices") def gravity(self, request, pk): diff --git a/frontend/src/lib/components/Forms/ModelForm/RiskAssessmentForm.svelte b/frontend/src/lib/components/Forms/ModelForm/RiskAssessmentForm.svelte index 1a5f2d850..9c623be76 100644 --- a/frontend/src/lib/components/Forms/ModelForm/RiskAssessmentForm.svelte +++ b/frontend/src/lib/components/Forms/ModelForm/RiskAssessmentForm.svelte @@ -65,6 +65,7 @@ bind:cachedValue={formDataCache['risk_matrix']} label={m.riskMatrix()} helpText={m.riskAssessmentMatrixHelpText()} + hidden={initialData.risk_matrix} /> + {#if initialData.ebios_rm_study} +