From 4a1fc34881cad5d6ccdedc2c9e9ae560b1fe842d Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Tue, 16 Apr 2024 21:19:14 +0200 Subject: [PATCH] Display risk scenarios count instead of list in risk assessment ModelTable --- backend/core/serializers.py | 12 +++++------- frontend/src/lib/utils/table.ts | 11 ++--------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/backend/core/serializers.py b/backend/core/serializers.py index 805eab409..4a2b27f59 100644 --- a/backend/core/serializers.py +++ b/backend/core/serializers.py @@ -21,9 +21,7 @@ class BaseModelSerializer(serializers.ModelSerializer): def update(self, instance: models.Model, validated_data: Any) -> models.Model: if hasattr(instance, "urn") and getattr(instance, "urn"): - raise PermissionDenied( - {"urn": "Imported objects cannot be modified"} - ) + raise PermissionDenied({"urn": "Imported objects cannot be modified"}) try: object_updated = super().update(instance, validated_data) return object_updated @@ -134,6 +132,7 @@ class Meta: class RiskAssessmentReadSerializer(AssessmentReadSerializer): risk_scenarios = FieldsRelatedField(many=True) + risk_scenarios_count = serializers.IntegerField(source="risk_scenarios.count") risk_matrix = FieldsRelatedField() class Meta: @@ -162,7 +161,7 @@ class Meta: class ReferenceControlReadSerializer(ReferenceControlWriteSerializer): folder = FieldsRelatedField() - library = FieldsRelatedField(["name","urn"]) + library = FieldsRelatedField(["name", "urn"]) class LibraryReadSerializer(BaseModelSerializer): @@ -187,7 +186,7 @@ class Meta: class ThreatReadSerializer(BaseModelSerializer): folder = FieldsRelatedField() - library = FieldsRelatedField(["name","urn"]) + library = FieldsRelatedField(["name", "urn"]) class Meta: model = Threat @@ -407,7 +406,7 @@ class Meta: class FrameworkReadSerializer(BaseModelSerializer): folder = FieldsRelatedField() - library = FieldsRelatedField(["name","urn"]) + library = FieldsRelatedField(["name", "urn"]) class Meta: model = Framework @@ -503,4 +502,3 @@ class RequirementAssessmentWriteSerializer(BaseModelSerializer): class Meta: model = RequirementAssessment fields = "__all__" - diff --git a/frontend/src/lib/utils/table.ts b/frontend/src/lib/utils/table.ts index 2ec95d5d1..a5ea58187 100644 --- a/frontend/src/lib/utils/table.ts +++ b/frontend/src/lib/utils/table.ts @@ -14,7 +14,7 @@ export const listViewFields = { }, 'risk-assessments': { head: ['name', 'riskMatrix', 'description', 'riskScenarios', 'project'], - body: ['name', 'risk_matrix', 'description', 'risk_scenarios', 'project'] + body: ['name', 'risk_matrix', 'description', 'risk_scenarios_count', 'project'] }, threats: { head: ['ref', 'name', 'description', 'provider', 'domain'], @@ -22,14 +22,7 @@ export const listViewFields = { meta: ['id', 'urn'] }, 'risk-scenarios': { - head: [ - 'name', - 'threats', - 'riskAssessment', - 'appliedControls', - 'currentLevel', - 'residualLevel' - ], + head: ['name', 'threats', 'riskAssessment', 'appliedControls', 'currentLevel', 'residualLevel'], body: [ 'name', 'threats',