-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #347 from intuitem/hotfix/score_nist_csf_1.1
add score migration for NIST CSF 1.1
- Loading branch information
Showing
7 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Generated by Django 5.0.4 on 2024-05-01 13:42 | ||
# well-known scores added manually | ||
|
||
from django.db import migrations | ||
|
||
|
||
WELL_KNOWN_SCORES = { | ||
"urn:intuitem:risk:framework:tisax-v6.0.2": (0, 5), | ||
"urn:intuitem:risk:framework:ccb-cff-2023-03-01": (1, 5), | ||
"urn:intuitem:risk:framework:nist-csf-2.0": (1, 4), | ||
"urn:intuitem:risk:framework:nist-csf-1.1": (1, 4), | ||
} | ||
|
||
|
||
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() | ||
print("custom migration for", framework.urn) | ||
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 | ||
] | ||
print("custom migration for", assessment.framework.urn) | ||
else: | ||
# no default value, so fix it now | ||
(assessment.min_score, assessment.max_score) = (0, 100) | ||
assessment.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("core", "0010_rename_score_definition_framework_scores_definition_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(fix_well_known_scores), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.