From 1f3b5d35e5e2338526e974bda210fab306566106 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Mon, 9 Dec 2024 16:47:30 +0100 Subject: [PATCH] feat: adapt model to new spec --- .../0045_riskassessment_ebios_rm_study.py | 20 +++++++++++++++++++ backend/core/models.py | 8 ++++++++ backend/core/serializers.py | 9 +-------- backend/core/views.py | 2 +- ...02_remove_ebiosrmstudy_risk_assessments.py | 17 ++++++++++++++++ backend/ebios_rm/models.py | 8 -------- .../Forms/ModelForm/RiskAssessmentForm.svelte | 13 ++++++------ frontend/src/lib/utils/crud.ts | 2 +- frontend/src/lib/utils/schemas.ts | 2 +- .../ebios-rm/[id=uuid]/+page.server.ts | 2 +- .../risk-analyses/+page.server.ts | 6 +++--- 11 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 backend/core/migrations/0045_riskassessment_ebios_rm_study.py create mode 100644 backend/ebios_rm/migrations/0002_remove_ebiosrmstudy_risk_assessments.py diff --git a/backend/core/migrations/0045_riskassessment_ebios_rm_study.py b/backend/core/migrations/0045_riskassessment_ebios_rm_study.py new file mode 100644 index 0000000000..e47dd700e3 --- /dev/null +++ b/backend/core/migrations/0045_riskassessment_ebios_rm_study.py @@ -0,0 +1,20 @@ +# Generated by Django 5.1.1 on 2024-12-09 15:43 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0044_qualification'), + ('ebios_rm', '0002_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 5ab669cfd1..dcd25b8be1 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -1980,6 +1980,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 7ad0ee414e..701b00320b 100644 --- a/backend/core/serializers.py +++ b/backend/core/serializers.py @@ -191,13 +191,6 @@ class Meta: class RiskAssessmentWriteSerializer(BaseModelSerializer): - ebios_rm_studies = serializers.PrimaryKeyRelatedField( - many=True, - queryset=EbiosRMStudy.objects.all(), - required=False, - allow_null=True, - write_only=True, - ) class Meta: model = RiskAssessment @@ -220,7 +213,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 a1b14eb5e6..cabe0ceb5d 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -568,7 +568,7 @@ class RiskAssessmentViewSet(BaseModelViewSet): "authors", "risk_matrix", "status", - "ebios_rm_studies" + "ebios_rm_study" ] @action(detail=False, name="Risk assessments per status") diff --git a/backend/ebios_rm/migrations/0002_remove_ebiosrmstudy_risk_assessments.py b/backend/ebios_rm/migrations/0002_remove_ebiosrmstudy_risk_assessments.py new file mode 100644 index 0000000000..3db7ba7ce2 --- /dev/null +++ b/backend/ebios_rm/migrations/0002_remove_ebiosrmstudy_risk_assessments.py @@ -0,0 +1,17 @@ +# Generated by Django 5.1.1 on 2024-12-09 15:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('ebios_rm', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='ebiosrmstudy', + name='risk_assessments', + ), + ] diff --git a/backend/ebios_rm/models.py b/backend/ebios_rm/models.py index 1aad3324fe..063af95acd 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/frontend/src/lib/components/Forms/ModelForm/RiskAssessmentForm.svelte b/frontend/src/lib/components/Forms/ModelForm/RiskAssessmentForm.svelte index e1e4510a69..9c623be769 100644 --- a/frontend/src/lib/components/Forms/ModelForm/RiskAssessmentForm.svelte +++ b/frontend/src/lib/components/Forms/ModelForm/RiskAssessmentForm.svelte @@ -110,15 +110,14 @@ cacheLock={cacheLocks['observation']} bind:cachedValue={formDataCache['observation']} /> - {#if initialData.ebios_rm_studies} + {#if initialData.ebios_rm_study}