From 5ef6da442d3ec5e00cb61dbbb40f89049bbe95fd Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Tue, 17 Dec 2024 12:56:01 +0100 Subject: [PATCH] feat: add filters and checks --- backend/ebios_rm/models.py | 2 ++ frontend/src/lib/utils/crud.ts | 4 +++- .../[model=urlmodel]/[id=uuid]/edit/+layout.server.ts | 10 +++++++++- .../workshop-three/strategic-scenarios/+page.server.ts | 4 +++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/backend/ebios_rm/models.py b/backend/ebios_rm/models.py index 0a76b8800..bac7e8b3e 100644 --- a/backend/ebios_rm/models.py +++ b/backend/ebios_rm/models.py @@ -88,6 +88,8 @@ class Status(models.TextChoices): related_name="reviewers", ) observation = models.TextField(null=True, blank=True, verbose_name=_("Observation")) + + fields_to_check = ["name", "version"] class Meta: verbose_name = _("Ebios RM Study") diff --git a/frontend/src/lib/utils/crud.ts b/frontend/src/lib/utils/crud.ts index a076556f0..d91bc18ed 100644 --- a/frontend/src/lib/utils/crud.ts +++ b/frontend/src/lib/utils/crud.ts @@ -106,6 +106,7 @@ interface ForeignKeyField { endpointUrl?: string; urlParams?: string; detail?: boolean; + detailUrlParams?: string[]; // To prepare possible fetch for foreign keys with detail in generic views } interface Field { @@ -677,7 +678,8 @@ export const URL_MODEL_MAP: ModelMap = { verboseNamePlural: 'Attack paths', foreignKeyFields: [ { field: 'stakeholders', urlModel: 'stakeholders', endpointUrl: 'ebios-rm/stakeholders' }, - { field: 'ro_to_couple', urlModel: 'ro-to', endpointUrl: 'ebios-rm/ro-to' }, + { field: 'ro_to_couple', urlModel: 'ro-to', endpointUrl: 'ebios-rm/ro-to', urlParams: 'ebios_rm_study=', + detail: true }, { field: 'ebios_rm_study', urlModel: 'ebios-rm', endpointUrl: 'ebios-rm/studies' }, { field: 'folder', urlModel: 'folders', urlParams: 'content_type=DO' } ] diff --git a/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/edit/+layout.server.ts b/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/edit/+layout.server.ts index dadfb90bb..22c34b450 100644 --- a/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/edit/+layout.server.ts +++ b/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/edit/+layout.server.ts @@ -47,7 +47,15 @@ export const load: LayoutServerLoad = async (event) => { if (foreignKeyFields) { for (const keyField of foreignKeyFields) { - const queryParams = keyField.urlParams ? `?${keyField.urlParams}` : ''; + let queryParams = keyField.urlParams ? `?${keyField.urlParams}` : ''; + if (keyField.detailUrlParams && Array.isArray(keyField.detailUrlParams)) { + keyField.detailUrlParams.forEach(detailParam => { + const paramValue = object[detailParam]?.id; + if (paramValue) { + queryParams += queryParams ? `&${detailParam}=${paramValue}` : `?${detailParam}=${paramValue}`; + } + }); + } // To prepare possible fetch for foreign keys with detail in generic views const keyModel = getModelInfo(keyField.urlModel); let url = keyModel.endpointUrl ? `${BASE_API_URL}/${keyModel.endpointUrl}/${queryParams}` diff --git a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-three/strategic-scenarios/+page.server.ts b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-three/strategic-scenarios/+page.server.ts index 2b31addc0..94c75806d 100644 --- a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-three/strategic-scenarios/+page.server.ts +++ b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-three/strategic-scenarios/+page.server.ts @@ -51,7 +51,9 @@ export const load: PageServerLoad = async ({ params, fetch }) => { for (const keyField of foreignKeyFields) { const model = getModelInfo(keyField.urlModel); - const queryParams = keyField.urlParams ? `?${keyField.urlParams}` : ''; + const queryParams = keyField.urlParams + ? `?${keyField.urlParams}${keyField.detail ? params.id : ''}` + : ''; const url = model.endpointUrl ? `${BASE_API_URL}/${model.endpointUrl}/${queryParams}` : `${BASE_API_URL}/${model.urlModel}/${queryParams}`;