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

Round displayed stakeholder criticality #1201

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions backend/ebios_rm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,20 @@ def residual_criticality(self):
self.residual_trust,
)

def get_current_criticality_display(self) -> str:
return (
f"{self.current_criticality:.2f}".rstrip("0").rstrip(".")
if "." in f"{self.current_criticality:.2f}"
else f"{self.current_criticality:.2f}"
)

def get_residual_criticality_display(self) -> str:
return (
f"{self.residual_criticality:.2f}".rstrip("0").rstrip(".")
if "." in f"{self.residual_criticality:.2f}"
else f"{self.residual_criticality:.2f}"
)


class AttackPath(NameDescriptionMixin, FolderMixin):
ebios_rm_study = models.ForeignKey(
Expand Down
16 changes: 12 additions & 4 deletions backend/ebios_rm/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ class Meta:


class StakeholderWriteSerializer(BaseModelSerializer):
current_criticality = serializers.IntegerField(read_only=True)
residual_criticality = serializers.IntegerField(read_only=True)
current_criticality = serializers.CharField(
source="get_current_criticality_display"
)
residual_criticality = serializers.CharField(
source="get_residual_criticality_display"
)

class Meta:
model = Stakeholder
Expand All @@ -120,8 +124,12 @@ class StakeholderReadSerializer(BaseModelSerializer):
applied_controls = FieldsRelatedField(many=True)

category = serializers.CharField(source="get_category_display")
current_criticality = serializers.IntegerField()
residual_criticality = serializers.IntegerField()
current_criticality = serializers.CharField(
source="get_current_criticality_display"
)
residual_criticality = serializers.CharField(
source="get_residual_criticality_display"
)

class Meta:
model = Stakeholder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
trust: number
) => {
if (maturity === 0 || trust === 0) return 0;
return (dependency * penetration) / (maturity * trust);
return ((dependency * penetration) / (maturity * trust)).toFixed(2).replace(/\.?0+$/, '');
};

$: currentCriticality = getCriticality(
Expand Down
Loading