Skip to content

Commit 0c0ce56

Browse files
committed
Fix domain import/export
for objectives and for qualifications
1 parent 2f5bec4 commit 0c0ce56

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

backend/core/serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ class RiskScenarioImportExportSerializer(BaseModelSerializer):
602602
slug_field="pk", read_only=True, many=True
603603
)
604604
applied_controls = HashSlugRelatedField(slug_field="pk", read_only=True, many=True)
605+
qualifications = HashSlugRelatedField(slug_field="urn", read_only=True, many=True)
605606

606607
class Meta:
607608
model = RiskScenario

backend/core/views.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3268,7 +3268,7 @@ def _validate_batch(self, model, batch, validation_errors, required_libraries):
32683268
)
32693269

32703270
def _create_model_objects(self, model, objects, link_dump_database_ids):
3271-
"""Create all objects for a model after validation."""
3271+
"""Create all objects for a model after validation during domain import."""
32723272
logger.debug("Creating objects for model", model=model)
32733273

32743274
model_name = f"{model._meta.app_label}.{model._meta.model_name}"
@@ -3302,7 +3302,7 @@ def _create_model_objects(self, model, objects, link_dump_database_ids):
33023302
)
33033303

33043304
def _create_batch(self, model, batch, link_dump_database_ids):
3305-
"""Create a batch of objects with proper relationship handling."""
3305+
"""Create a batch of objects with proper relationship handling during domain import."""
33063306
# Create all objects in the batch within a single transaction
33073307
with transaction.atomic():
33083308
for obj in batch:
@@ -3363,7 +3363,7 @@ def _process_model_relationships(
33633363
link_dump_database_ids,
33643364
many_to_many_map_ids,
33653365
):
3366-
"""Process model-specific relationships."""
3366+
"""Process model-specific relationships during domain import."""
33673367

33683368
def get_mapped_ids(
33693369
ids: List[str], link_dump_database_ids: Dict[str, str]
@@ -3410,6 +3410,9 @@ def get_mapped_ids(
34103410
many_to_many_map_ids["evidence_ids"] = get_mapped_ids(
34113411
_fields.pop("evidences", []), link_dump_database_ids
34123412
)
3413+
many_to_many_map_ids["objective_ids"] = get_mapped_ids(
3414+
_fields.pop("objectives", []), link_dump_database_ids
3415+
)
34133416
ref_control_id = link_dump_database_ids.get(
34143417
_fields["reference_control"]
34153418
)
@@ -3466,6 +3469,9 @@ def get_mapped_ids(
34663469
many_to_many_map_ids[map_key] = get_mapped_ids(
34673470
_fields.pop(field, []), link_dump_database_ids
34683471
)
3472+
many_to_many_map_ids["qualification_ids"] = get_mapped_ids(
3473+
_fields.pop("qualifications", []), link_dump_database_ids
3474+
)
34693475

34703476
case "entity":
34713477
_fields.pop("owned_folders", None)
@@ -3576,7 +3582,7 @@ def get_mapped_ids(
35763582
return _fields
35773583

35783584
def _set_many_to_many_relations(self, model, obj, many_to_many_map_ids):
3579-
"""Set many-to-many relationships after object creation."""
3585+
"""Set many-to-many relationships after object creation during domain import."""
35803586
model_name = model._meta.model_name
35813587

35823588
match model_name:
@@ -3590,7 +3596,8 @@ def _set_many_to_many_relations(self, model, obj, many_to_many_map_ids):
35903596
case "appliedcontrol":
35913597
if evidence_ids := many_to_many_map_ids.get("evidence_ids"):
35923598
obj.evidences.set(Evidence.objects.filter(id__in=evidence_ids))
3593-
3599+
if "objective_ids" in many_to_many_map_ids:
3600+
obj.objectives.set(many_to_many_map_ids["objective_ids"])
35943601
case "requirementassessment":
35953602
if applied_control_ids := many_to_many_map_ids.get("applied_controls"):
35963603
obj.applied_controls.set(
@@ -3620,6 +3627,7 @@ def _set_many_to_many_relations(self, model, obj, many_to_many_map_ids):
36203627
AppliedControl,
36213628
"existing_applied_controls",
36223629
),
3630+
"qualification_ids": (Qualification, "qualifications"),
36233631
}.items():
36243632
if ids := many_to_many_map_ids.get(field):
36253633
getattr(obj, model_class[1]).set(

0 commit comments

Comments
 (0)