Skip to content

Commit

Permalink
Merge branch 'main' into put_is_published_in_abstractbasemodel
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Feb 29, 2024
2 parents 117f02b + d184346 commit 7682850
Show file tree
Hide file tree
Showing 45 changed files with 947 additions and 608 deletions.
3 changes: 2 additions & 1 deletion backend/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ def compile_risk_assessment_for_composer(user, risk_assessment_list: list):
v = {"value": count, "itemStyle": {"color": STATUS_COLOR_MAP[st[0]]}}
values.append(v)
labels.append(st[1])
local_lables = [camel_case(str(l)) for l in labels]

risk_assessment_objects = list()

Expand Down Expand Up @@ -843,6 +844,6 @@ def compile_risk_assessment_for_composer(user, risk_assessment_list: list):
"untreated_h_vh": untreated_h_vh,
"accepted": accepted,
},
"security_measure_status": {"labels": labels, "values": values},
"security_measure_status": {"localLables":local_lables, "labels": labels, "values": values},
"colors": get_risk_color_ordered_list(user, risk_assessment_list),
}
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'),
),
]
65 changes: 53 additions & 12 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@ def get_linked_requirements_count(self):


class PolicyManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(category="policy")

def create(self, *args, **kwargs):
kwargs["category"] = "policy" # Ensure category is always "policy"
return super().create(*args, **kwargs)
Expand Down Expand Up @@ -771,11 +774,11 @@ def quality_check(self) -> dict:
"object": _object,
}
)
if not self.authors:
if not self.authors.all():
info_lst.append(
{
"msg": _(
"{}: No author assigned to this risk risk assessment"
"{}: No author assigned to this risk assessment"
).format(str(self)),
"obj_type": "risk_assessment",
"object": _object,
Expand Down Expand Up @@ -993,12 +996,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 @@ -1071,11 +1097,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 @@ -1143,6 +1168,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 Expand Up @@ -1282,6 +1312,17 @@ def quality_check(self) -> dict:
"object": _object,
}
)

if not self.authors.all():
info_lst.append(
{
"msg": _(
"{}: No author assigned to this compliance assessment"
).format(str(self)),
"obj_type": "complianceassessment",
"object": _object,
}
)
# ---

# --- check on requirement assessments:
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
Loading

0 comments on commit 7682850

Please sign in to comment.