Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/manage strength of knowledge #75

Merged
merged 37 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9bd368b
Make risk scenario strength of knowledge optional
nas-tabchiche Feb 21, 2024
68f12a7
Create /risk-scenarios/strength_of_knowledge endpoint
nas-tabchiche Feb 21, 2024
408e416
Update Select component default value
nas-tabchiche Feb 21, 2024
6085a1f
Add strength_of_knowledge field to risk scenario update form
nas-tabchiche Feb 21, 2024
33c500e
Merge branch 'main' into feat/manage-strength-of-knowledge
nas-tabchiche Feb 26, 2024
75effe9
Fix regression in risk scenario nested model table
nas-tabchiche Feb 26, 2024
16a0acc
Make RiskScenario.strength_of_knowledge an IntegerField
nas-tabchiche Feb 26, 2024
402b589
Include description and symbol in default SoK options
nas-tabchiche Feb 26, 2024
3447029
Internationalize library objects model table
nas-tabchiche Feb 26, 2024
ed8966a
Add endpoint to get risk scenario strength of knowledge choices
nas-tabchiche Feb 26, 2024
acc25f9
Include strength_of_knowledge in RiskMatrixImporter
nas-tabchiche Feb 26, 2024
bbc53d7
Include strength of knowledge in risk matrix libraries
nas-tabchiche Feb 26, 2024
fd90227
Make strength_of_knowledge a number in risk scenario schema
nas-tabchiche Feb 26, 2024
e63fbe5
Correctly type strength of knowledge entries
nas-tabchiche Feb 26, 2024
b996255
Merge branch 'main' into feat/manage-strength-of-knowledge
nas-tabchiche Feb 26, 2024
3da087d
Internationalize risk scenario update page
nas-tabchiche Feb 26, 2024
c31c07e
Serialize strength of knowledge
nas-tabchiche Feb 26, 2024
8a94e54
chore: Make migrations
nas-tabchiche Feb 26, 2024
1fc3692
Write RiskScenarioItem component
nas-tabchiche Feb 26, 2024
da251ac
Integrate RiskScenarioItem into RiskMatrix component
nas-tabchiche Feb 26, 2024
e2cb2c2
Update "Risk matrix view" french translation
nas-tabchiche Feb 26, 2024
511b934
Improve display of cells with hexcolor attribute
nas-tabchiche Feb 26, 2024
9b9f30d
Allow scrolling within risk matrix cells
nas-tabchiche Feb 26, 2024
e63475e
Manage strength of knowledge display in RiskScenarioItem component
nas-tabchiche Feb 26, 2024
dfa630c
Improve risk matrices layout
nas-tabchiche Feb 26, 2024
b6a6dbf
Remove unused translation
nas-tabchiche Feb 26, 2024
8a4fa23
Fix related model create modal title
nas-tabchiche Feb 26, 2024
8ba3f6c
Show risk legend below both matrices
nas-tabchiche Feb 27, 2024
18ee6b9
Use relative path for paraglide import
nas-tabchiche Feb 27, 2024
56fa469
Merge branch 'main' into feat/manage-strength-of-knowledge
nas-tabchiche Feb 27, 2024
8b52b80
Fix translation files
nas-tabchiche Feb 27, 2024
2c26988
Simplify risk assessments detail view
nas-tabchiche Feb 27, 2024
d6abea3
Fix scenario create form
nas-tabchiche Feb 27, 2024
bb5b1ab
Update default SoK symbols
nas-tabchiche Feb 28, 2024
644aec3
Merge branch 'main' into feat/manage-strength-of-knowledge
nas-tabchiche Feb 28, 2024
d35a4ad
Fix typo
nas-tabchiche Feb 28, 2024
58fe726
Merge branch 'main' into feat/manage-strength-of-knowledge
nas-tabchiche Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading