Skip to content

Commit

Permalink
feat: adapt model to new spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene authored and nas-tabchiche committed Dec 10, 2024
1 parent c96f5a7 commit e9acb6f
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 30 deletions.
20 changes: 20 additions & 0 deletions backend/core/migrations/0045_riskassessment_ebios_rm_study.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
8 changes: 8 additions & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,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")
Expand Down
9 changes: 1 addition & 8 deletions backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -220,7 +213,7 @@ class RiskAssessmentReadSerializer(AssessmentReadSerializer):

class Meta:
model = RiskAssessment
fields = "__all__"
exclude = ["ebios_rm_study"]


class AssetWriteSerializer(BaseModelSerializer):
Expand Down
2 changes: 1 addition & 1 deletion backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ class RiskAssessmentViewSet(BaseModelViewSet):
"authors",
"risk_matrix",
"status",
"ebios_rm_studies"
"ebios_rm_study"
]

@action(detail=False, name="Risk assessments per status")
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
),
]
8 changes: 0 additions & 8 deletions backend/ebios_rm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Asset,
ComplianceAssessment,
Qualification,
RiskAssessment,
RiskMatrix,
Threat,
)
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,14 @@
cacheLock={cacheLocks['observation']}
bind:cachedValue={formDataCache['observation']}
/>
{#if initialData.ebios_rm_studies}
{#if initialData.ebios_rm_study}
<AutocompleteSelect
{form}
field="ebios_rm_studies"
multiple
cacheLock={cacheLocks['ebios_rm_studies']}
bind:cachedValue={formDataCache['ebios_rm_studies']}
label={m.ebiosRmStudies()}
options={getOptions({ objects: model.foreignKeys['ebios_rm_studies'] })}
field="ebios_rm_study"
cacheLock={cacheLocks['ebios_rm_study']}
bind:cachedValue={formDataCache['ebios_rm_study']}
label={m.ebiosRmStudy()}
options={getOptions({ objects: model.foreignKeys['ebios_rm_study'] })}
hidden
/>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/utils/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export const URL_MODEL_MAP: ModelMap = {
{ field: 'reviewers', urlModel: 'users', urlParams: 'is_third_party=false' },
{ field: 'risk_matrix', urlModel: 'risk-matrices' },
{ field: 'risk_scenarios', urlModel: 'risk-scenarios' },
{ field: 'ebios_rm_studies', urlModel: 'ebios-rm' }
{ field: 'ebios_rm_study', urlModel: 'ebios-rm' }
],
reverseForeignKeyFields: [{ field: 'risk_assessment', urlModel: 'risk-scenarios' }],
selectFields: [{ field: 'status' }],
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const RiskAssessmentSchema = z.object({
authors: z.array(z.string().optional()).optional(),
reviewers: z.array(z.string().optional()).optional(),
observation: z.string().optional().nullable(),
ebios_rm_studies: z.string().uuid().optional().array().optional()
ebios_rm_study: z.string().uuid().optional()
});

export const ThreatSchema = z.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {

const initialData = {
risk_matrix: data.risk_matrix.id,
ebios_rm_studies: [params.id]
ebios_rm_study: params.id
}

const createSchema = modelSchema('risk-assessments');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
const ebiosMatrixRes = await fetch(`${BASE_API_URL}/ebios-rm/studies/${params.id}/risk-matrix/`);
const risk_matrix_id = await ebiosMatrixRes.json().then((res) => res.id);
const initialData = {
ebios_rm_studies: [params.id],
ebios_rm_study: params.id,
risk_matrix: risk_matrix_id
};
const createForm = await superValidate(initialData, zod(createSchema), { errors: false });
Expand Down Expand Up @@ -73,8 +73,8 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
model['selectOptions'] = selectOptions;

const endpoint = model.endpointUrl
? `${BASE_API_URL}/${model.endpointUrl}?ebios_rm_studies=${params.id}`
: `${BASE_API_URL}/${model.urlModel}?ebios_rm_studies=${params.id}`;
? `${BASE_API_URL}/${model.endpointUrl}?ebios_rm_study=${params.id}`
: `${BASE_API_URL}/${model.urlModel}?ebios_rm_study=${params.id}`;
const res = await fetch(endpoint);
const data = await res.json().then((res) => res.results);

Expand Down

0 comments on commit e9acb6f

Please sign in to comment.