Skip to content

Commit

Permalink
feat: add filters and checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Dec 17, 2024
1 parent c8074ba commit 5ef6da4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions backend/ebios_rm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/lib/utils/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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' }
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down

0 comments on commit 5ef6da4

Please sign in to comment.