From 8ca4609f88e077f39768882c455396444e366e4a Mon Sep 17 00:00:00 2001 From: eric-intuitem <71850047+eric-intuitem@users.noreply.github.com> Date: Sun, 28 Apr 2024 22:39:55 +0200 Subject: [PATCH] custom migration for existing assessments, fix score --- ...on_framework_scores_definition_and_more.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/backend/core/migrations/0010_rename_score_definition_framework_scores_definition_and_more.py b/backend/core/migrations/0010_rename_score_definition_framework_scores_definition_and_more.py index 863884d29..27c9ea4c4 100644 --- a/backend/core/migrations/0010_rename_score_definition_framework_scores_definition_and_more.py +++ b/backend/core/migrations/0010_rename_score_definition_framework_scores_definition_and_more.py @@ -1,8 +1,28 @@ # Generated by Django 5.0.4 on 2024-04-28 15:34 +# well-known scores added manually from django.db import migrations, models +WELL_KNOWN_SCORES = { + "urn:intuitem:risk:framework:tisax-v6.0.2": (0, 5), + "urn:intuitem:risk:framework:cis-controls-v8": (0, 5), + "urn:intuitem:risk:framework:ccm-controls-v4": (0, 5), + "urn:intuitem:risk:framework:ccb-cff-2023-03-01": (1, 5), +} + +def fix_well_known_scores(apps, schema_editor): + Framework = apps.get_model('core', 'Framework') + ComplianceAssessment = apps.get_model('core', 'ComplianceAssessment') + for framework in Framework.objects.all(): + if framework.urn in WELL_KNOWN_SCORES: + (framework.min_score, framework.max_score) = WELL_KNOWN_SCORES[framework.urn] + framework.save() + for assessment in ComplianceAssessment.objects.all(): + if assessment.framework.urn in WELL_KNOWN_SCORES: + (assessment.min_score, assessment.max_score) = WELL_KNOWN_SCORES[assessment.framework.urn] + assessment.save() + class Migration(migrations.Migration): dependencies = [ ("core", "0009_framework_max_score_framework_min_score_and_more"), @@ -66,4 +86,5 @@ class Migration(migrations.Migration): migrations.DeleteModel( name="RequirementLevel", ), + migrations.RunPython(fix_well_known_scores), ]