Skip to content

Commit

Permalink
Merge pull request #75 from intuitem/feat/manage-strength-of-knowledge
Browse files Browse the repository at this point in the history
Feat/manage strength of knowledge
  • Loading branch information
eric-intuitem authored Feb 28, 2024
2 parents c1d8247 + 58fe726 commit f9dfeef
Show file tree
Hide file tree
Showing 22 changed files with 523 additions and 361 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.2 on 2024-02-26 14:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0002_initial'),
]

operations = [
migrations.AlterField(
model_name='riskscenario',
name='strength_of_knowledge',
field=models.IntegerField(default=-1, help_text='The strength of the knowledge supporting the assessment', verbose_name='Strength of Knowledge'),
),
]
47 changes: 37 additions & 10 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,12 +998,35 @@ class RiskScenario(NameDescriptionMixin):
("transfer", _("Transfer")),
]

SOK_OPTIONS = [
("--", _("--")),
("0", _("Low")),
("1", _("Medium")),
("2", _("High")),
]
DEFAULT_SOK_OPTIONS = {
-1: {
"name": _("--"),
"description": _(
"The strength of the knowledge supporting the assessment is undefined"
),
},
0: {
"name": _("Low"),
"description": _(
"The strength of the knowledge supporting the assessment is low"
),
"symbol": "◇",
},
1: {
"name": _("Medium"),
"description": _(
"The strength of the knowledge supporting the assessment is medium"
),
"symbol": "⬙",
},
2: {
"name": _("High"),
"description": _(
"The strength of the knowledge supporting the assessment is high"
),
"symbol": "◆",
},
}

risk_assessment = models.ForeignKey(
RiskAssessment,
Expand Down Expand Up @@ -1076,11 +1099,10 @@ class RiskScenario(NameDescriptionMixin):
verbose_name=_("Treatment status"),
)

strength_of_knowledge = models.CharField(
max_length=20,
choices=SOK_OPTIONS,
default="--",
strength_of_knowledge = models.IntegerField(
default=-1,
verbose_name=_("Strength of Knowledge"),
help_text=_("The strength of the knowledge supporting the assessment"),
)
justification = models.CharField(
max_length=500, blank=True, null=True, verbose_name=_("Justification")
Expand Down Expand Up @@ -1148,6 +1170,11 @@ def get_residual_proba(self):
risk_matrix = self.get_matrix()
return risk_matrix["probability"][self.residual_proba]

def get_strength_of_knowledge(self):
if self.strength_of_knowledge < 0:
return self.DEFAULT_SOK_OPTIONS[-1]
return self.DEFAULT_SOK_OPTIONS[self.strength_of_knowledge]

def __str__(self):
return (
str(self.parent_project().folder)
Expand Down
3 changes: 3 additions & 0 deletions backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ class RiskScenarioReadSerializer(RiskScenarioWriteSerializer):
residual_impact = serializers.CharField(source="get_residual_impact.name")
residual_level = serializers.JSONField(source="get_residual_risk")

strength_of_knowledge = serializers.JSONField(source="get_strength_of_knowledge")

security_measures = FieldsRelatedField(many=True)
rid = serializers.CharField()


class SecurityMeasureWriteSerializer(BaseModelSerializer):
Expand Down
23 changes: 23 additions & 0 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,29 @@ def impact(self, request, pk):
choices = undefined | _choices
return Response(choices)

@action(detail=True, name="Get strength of knowledge choices")
def strength_of_knowledge(self, request, pk):
undefined = {-1: RiskScenario.DEFAULT_SOK_OPTIONS[-1]}
_sok_choices = self.get_object().get_matrix().get("strength_of_knowledge")
if _sok_choices is not None:
sok_choices = dict(
zip(
list(range(0, 64)),
[
{
"name": x["name"],
"description": x.get("description"),
"symbol": x.get("symbol"),
}
for x in _sok_choices
],
)
)
else:
sok_choices = RiskScenario.DEFAULT_SOK_OPTIONS
choices = undefined | sok_choices
return Response(choices)

@action(detail=False, name="Get risk count per level")
def count_per_level(self, request):
return Response({"results": risks_count_per_level(request.user)})
Expand Down
94 changes: 47 additions & 47 deletions backend/library/libraries/critical_matrix_3x3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,50 @@ provider: intuitem
packager: intuitem
objects:
risk_matrix:
- urn: urn:intuitem:risk:matrix:critical_risk_matrix_3x3
ref_id: critical_3x3
name: critical 3x3
description: critical risk matrix 3x3
probability:
- abbreviation: L
name: Low
description: Unfrequent event
- abbreviation: M
name: Medium
description: Occasional event
- abbreviation: H
name: High
description: Frequent event
impact:
- abbreviation: L
name: Low
description: Low impact
- abbreviation: M
name: Medium
description: Medium impact
- abbreviation: H
name: High
description: High impact
risk:
- abbreviation: L
name: Low
description: acceptable risk
hexcolor: "#00FF00"
- abbreviation: M
name: Medium
description: risk requiring mitigation within 2 years
hexcolor: "#FFFF00"
- abbreviation: H
name: High
description: unacceptable risk
hexcolor: "#FF0000"
grid:
- - 0
- 1
- 1
- - 1
- 1
- 2
- - 1
- 2
- 2
- urn: urn:intuitem:risk:matrix:critical_risk_matrix_3x3
ref_id: critical_3x3
name: critical 3x3
description: critical risk matrix 3x3
probability:
- abbreviation: L
name: Low
description: Unfrequent event
- abbreviation: M
name: Medium
description: Occasional event
- abbreviation: H
name: High
description: Frequent event
impact:
- abbreviation: L
name: Low
description: Low impact
- abbreviation: M
name: Medium
description: Medium impact
- abbreviation: H
name: High
description: High impact
risk:
- abbreviation: L
name: Low
description: acceptable risk
hexcolor: "#00FF00"
- abbreviation: M
name: Medium
description: risk requiring mitigation within 2 years
hexcolor: "#FFFF00"
- abbreviation: H
name: High
description: unacceptable risk
hexcolor: "#FF0000"
grid:
- - 0
- 1
- 1
- - 1
- 1
- 2
- - 1
- 2
- 2
166 changes: 83 additions & 83 deletions backend/library/libraries/critical_matrix_5x5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,86 +8,86 @@ provider: intuitem
packager: intuitem
objects:
risk_matrix:
- urn: urn:intuitem:risk:matrix:critical_risk_matrix_5x5
ref_id: critical_5x5
name: critical 5x5
description: critical risk matrix 5x5
probability:
- abbreviation: VL
name: Very Low
description: Very unfrequent event
- abbreviation: L
name: Low
description: Unfrequent event
- abbreviation: M
name: Medium
description: Occasional event
- abbreviation: H
name: High
description: Frequent event
- abbreviation: VH
name: Very High
description: Very frequent event
impact:
- abbreviation: VL
name: Very Low
description: Very low impact
- abbreviation: L
name: Low
description: Low impact
- abbreviation: M
name: Medium
description: Medium impact
- abbreviation: H
name: High
description: High impact
- abbreviation: VH
name: Very High
description: Very high impact
risk:
- abbreviation: VL
name: Very Low
description: negligible risk
hexcolor: "#BBF7D0"
- abbreviation: L
name: Low
description: acceptable risk
hexcolor: "#BEF264"
- abbreviation: M
name: Medium
description: risk requiring mitigation within 2 years
hexcolor: "#FEF08A"
- abbreviation: H
name: High
description: risk requiring mitigation within 6 months
hexcolor: "#FBBF24"
- abbreviation: VH
name: Very High
description: unacceptable risk
hexcolor: "#F87171"
grid:
- - 0
- 0
- 1
- 1
- 2
- - 0
- 1
- 1
- 2
- 2
- - 1
- 1
- 2
- 2
- 3
- - 1
- 2
- 2
- 3
- 4
- - 2
- 2
- 3
- 4
- 4
- urn: urn:intuitem:risk:matrix:critical_risk_matrix_5x5
ref_id: critical_5x5
name: critical 5x5
description: critical risk matrix 5x5
probability:
- abbreviation: VL
name: Very Low
description: Very unfrequent event
- abbreviation: L
name: Low
description: Unfrequent event
- abbreviation: M
name: Medium
description: Occasional event
- abbreviation: H
name: High
description: Frequent event
- abbreviation: VH
name: Very High
description: Very frequent event
impact:
- abbreviation: VL
name: Very Low
description: Very low impact
- abbreviation: L
name: Low
description: Low impact
- abbreviation: M
name: Medium
description: Medium impact
- abbreviation: H
name: High
description: High impact
- abbreviation: VH
name: Very High
description: Very high impact
risk:
- abbreviation: VL
name: Very Low
description: negligible risk
hexcolor: "#BBF7D0"
- abbreviation: L
name: Low
description: acceptable risk
hexcolor: "#BEF264"
- abbreviation: M
name: Medium
description: risk requiring mitigation within 2 years
hexcolor: "#FEF08A"
- abbreviation: H
name: High
description: risk requiring mitigation within 6 months
hexcolor: "#FBBF24"
- abbreviation: VH
name: Very High
description: unacceptable risk
hexcolor: "#F87171"
grid:
- - 0
- 0
- 1
- 1
- 2
- - 0
- 1
- 1
- 2
- 2
- - 1
- 1
- 2
- 2
- 3
- - 1
- 2
- 2
- 3
- 4
- - 2
- 2
- 3
- 4
- 4
Loading

0 comments on commit f9dfeef

Please sign in to comment.