diff --git a/backend/core/helpers.py b/backend/core/helpers.py index 08d8dfdf2..cb7ebc0c9 100644 --- a/backend/core/helpers.py +++ b/backend/core/helpers.py @@ -1264,7 +1264,7 @@ def duplicate_and_link_object(new_obj, duplicate_object, target_folder, field_na # Get parent and sub-folders of the target folder target_parent_folders = target_folder.get_parent_folders() - sub_folders = target_folder.sub_folders() + sub_folders = target_folder.get_sub_folders() # Get all related objects for the specified field related_objects = getattr(source_object, field_name).all() diff --git a/backend/core/serializers.py b/backend/core/serializers.py index b1440294e..17f3b92f6 100644 --- a/backend/core/serializers.py +++ b/backend/core/serializers.py @@ -338,9 +338,9 @@ class AppliedControlReadSerializer(AppliedControlWriteSerializer): ranking_score = serializers.IntegerField(source="get_ranking_score") owner = FieldsRelatedField(many=True) - has_evidences = serializers.BooleanField() - eta_missed = serializers.BooleanField() - + # These properties shouldn't be displayed in the frontend detail view as they are simple derivations from fields already displayed in the detail view. + # has_evidences = serializers.BooleanField() + # eta_missed = serializers.BooleanField() class AppliedControlDuplicateSerializer(BaseModelSerializer): class Meta: diff --git a/backend/core/views.py b/backend/core/views.py index 5ed4dee20..8259c845c 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -1101,6 +1101,7 @@ def duplicate(self, request, pk): folder=new_folder, category=applied_control.category, csf_function=applied_control.csf_function, + priority=applied_control.priority, status=applied_control.status, start_date=applied_control.start_date, eta=applied_control.eta, @@ -1115,7 +1116,9 @@ def duplicate(self, request, pk): ) duplicate_applied_control.save() - return Response({"results": "applied control duplicated"}) + return Response({ + "results": AppliedControlReadSerializer(duplicate_applied_control).data + }) class PolicyViewSet(AppliedControlViewSet): diff --git a/frontend/src/lib/components/Forms/ModelForm/AppliedControlPolicyForm.svelte b/frontend/src/lib/components/Forms/ModelForm/AppliedControlPolicyForm.svelte index 273dc20a9..cc9c18064 100644 --- a/frontend/src/lib/components/Forms/ModelForm/AppliedControlPolicyForm.svelte +++ b/frontend/src/lib/components/Forms/ModelForm/AppliedControlPolicyForm.svelte @@ -17,9 +17,11 @@ export let schema: any = {}; export let initialData: Record = {}; - model.selectOptions['priority'].forEach((element) => { - element.value = parseInt(element.value); - }); + if (model.selectOptions && 'priority' in model.selectOptions) { + model.selectOptions['priority'].forEach((element) => { + element.value = parseInt(element.value); + }); + } {#if !duplicate} diff --git a/frontend/src/lib/utils/load.ts b/frontend/src/lib/utils/load.ts index 8abf28742..08a762273 100644 --- a/frontend/src/lib/utils/load.ts +++ b/frontend/src/lib/utils/load.ts @@ -99,22 +99,24 @@ export const loadDetail = async ({ event, model, id }) => { const selectOptions: Record = {}; if (info.selectFields) { - await Promise.all(info.selectFields.map(async (selectField) => { - const url = `${BASE_API_URL}/${urlModel}/${selectField.field}/`; - const response = await event.fetch(url); - if (response.ok) { - selectOptions[selectField.field] = await response.json().then((data) => - Object.entries(data).map(([key, value]) => ({ - label: value, - value: key - })) - ); - } else { - console.error( - `Failed to fetch data for ${selectField.field}: ${response.statusText}` - ); - } - })); + await Promise.all( + info.selectFields.map(async (selectField) => { + const url = `${BASE_API_URL}/${urlModel}/${selectField.field}/`; + const response = await event.fetch(url); + if (response.ok) { + selectOptions[selectField.field] = await response.json().then((data) => + Object.entries(data).map(([key, value]) => ({ + label: value, + value: key + })) + ); + } else { + console.error( + `Failed to fetch data for ${selectField.field}: ${response.statusText}` + ); + } + }) + ); } relatedModels[e.urlModel] = { urlModel, diff --git a/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/+page.server.ts b/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/+page.server.ts index 771b4be6f..699a98520 100644 --- a/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/+page.server.ts +++ b/frontend/src/routes/(app)/(internal)/[model=urlmodel]/[id=uuid]/+page.server.ts @@ -88,7 +88,7 @@ export const actions: Actions = { const endpoint = `${BASE_API_URL}/${event.params.model}/${event.params.id}/duplicate/`; if (!form.valid) { - console.log(form.errors); + console.error(form.errors); return fail(400, { form: form }); }