Skip to content

Commit

Permalink
Fix non-working duplicate modal and remove 2 useless values from the …
Browse files Browse the repository at this point in the history
…AppliedControlReadSerializer
  • Loading branch information
monsieurswag committed Nov 27, 2024
1 parent 07d09e2 commit 1237413
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion backend/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
export let schema: any = {};
export let initialData: Record<string, any> = {};
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);
});
}
</script>

{#if !duplicate}
Expand Down
34 changes: 18 additions & 16 deletions frontend/src/lib/utils/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,24 @@ export const loadDetail = async ({ event, model, id }) => {
const selectOptions: Record<string, any> = {};

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

Expand Down

0 comments on commit 1237413

Please sign in to comment.