diff --git a/backend/ebios_rm/models.py b/backend/ebios_rm/models.py index a16407ebb..8477fab8b 100644 --- a/backend/ebios_rm/models.py +++ b/backend/ebios_rm/models.py @@ -10,6 +10,7 @@ Qualification, RiskMatrix, Threat, + RiskAssessment, ) from core.validators import ( JSONSchemaInstanceValidator, @@ -192,6 +193,19 @@ def operational_scenario_count(self): def applied_control_count(self): return AppliedControl.objects.filter(stakeholders__ebios_rm_study=self).count() + @property + def last_risk_assessment(self): + """Get the latest risk assessment for the study + Returns: + RiskAssessment: The latest risk assessment for the study + """ + try: + return RiskAssessment.objects.filter(ebios_rm_study=self).latest( + "created_at" + ) + except RiskAssessment.DoesNotExist: + return None + def update_workshop_step_status(self, workshop: int, step: int, new_status: str): if workshop < 1 or workshop > 5: raise ValueError("Workshop must be between 1 and 5") diff --git a/backend/ebios_rm/serializers.py b/backend/ebios_rm/serializers.py index dabc081b3..65d9d3610 100644 --- a/backend/ebios_rm/serializers.py +++ b/backend/ebios_rm/serializers.py @@ -2,7 +2,7 @@ BaseModelSerializer, FieldsRelatedField, ) -from core.models import StoredLibrary, RiskMatrix +from core.models import RiskMatrix from .models import ( EbiosRMStudy, FearedEvent, @@ -13,7 +13,6 @@ OperationalScenario, ) from rest_framework import serializers -import logging class EbiosRMStudyWriteSerializer(BaseModelSerializer): @@ -43,6 +42,7 @@ class EbiosRMStudyReadSerializer(BaseModelSerializer): selected_attack_path_count = serializers.IntegerField() operational_scenario_count = serializers.IntegerField() applied_control_count = serializers.IntegerField() + last_risk_assessment = FieldsRelatedField() class Meta: model = EbiosRMStudy diff --git a/frontend/messages/en.json b/frontend/messages/en.json index bfa9410dc..a94439d61 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -1033,6 +1033,7 @@ "ebiosWs3_3_tooltip": "You need at least one Stakeholder to define associated security measures", "ebiosWs4_1_tooltip": "You need at least one selected Attack Path from a Strategic Scenario to elaborate an operational scenario", "ebiosWs4_2_tooltip": "You need at least one Operational Scenario to evaluate its likelihood", + "ebiosWs5_tooltip": "No risk assessment has been conducted yet", "govern": "Govern", "identify": "Identify", "protect": "Protect", diff --git a/frontend/messages/fr.json b/frontend/messages/fr.json index 19b129a02..164389a7a 100644 --- a/frontend/messages/fr.json +++ b/frontend/messages/fr.json @@ -1032,14 +1032,14 @@ "ebiosWs3_2_tooltip": "Vous avez besoin d'au moins un couple SR/OV sélectionné pour élaborer un scénario stratégique", "ebiosWs3_3_tooltip": "Vous avez besoin d'au moins une Partie Prenante pour définir les mesures de sécurité associées", "ebiosWs4_1_tooltip": "Vous avez besoin d'au moins un Chemin d'Attaque sélectionné à partir d'un Scénario Stratégique pour élaborer un scénario opérationnel", - "ebiosWs4_2_tooltip": "Vous avez besoin d'au moins un Scénario Opérationnel pour évaluer sa probabilité", + "ebiosWs4_2_tooltip": "Vous avez besoin d'au moins un Scénario Opérationnel pour évaluer sa vraisemblance", + "ebiosWs5_tooltip": "Aucune analyse de risque n'a encore été réalisée", "govern": "Gouverner", "identify": "Identifier", "protect": "Protéger", "detect": "Détecter", "respond": "Répondre", "recover": "Récupérer", - "ebiosWs4_2_tooltip": "Vous avez besoin d'au moins un Scénario Opérationnel pour évaluer sa vraisemblance", "gravityHelpText": "Estimation du niveau et de l’intensité des effets d’un risque", "likelihoodHelpText": "Estimation de la faisabilité ou de la probabilité qu’un risque se réalise", "studyAssetHelpText": "Biens primaires (valeur métier) et supports relatifs à l'objet étudié", diff --git a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.server.ts b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.server.ts index 6d37a78e8..a874d82d4 100644 --- a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.server.ts +++ b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.server.ts @@ -81,6 +81,23 @@ export const load: PageServerLoad = async ({ params, fetch }) => { export const actions: Actions = { create: async (event) => { + const requestInitOptions: RequestInit = { + method: 'PATCH', + body: JSON.stringify({ + status: 'done', + step: 1, + workshop: 5 + }) + }; + + const endpoint = `${BASE_API_URL}/ebios-rm/studies/${event.params.id}/workshop/5/step/1/`; + const res = await event.fetch(endpoint, requestInitOptions); + + if (!res.ok) { + const response = await res.text(); + console.error(response); + } + return defaultWriteFormAction({ event, urlModel: 'risk-assessments', diff --git a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.svelte b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.svelte index da2b1be13..bec059cbe 100644 --- a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.svelte +++ b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.svelte @@ -106,22 +106,30 @@ { title: safeTranslate(m.ebiosWs5_2()), status: data.data.meta.workshops[4].steps[1].status, - href: `${$page.url.pathname}/workshop-5/risk-analyses?next=${$page.url.pathname}` + href: `/risk-assessments/${data.data.last_risk_assessment?.id}?activity=two&next=${$page.url.pathname}`, + disabled: data.data.last_risk_assessment == null, + tooltip: safeTranslate(m.ebiosWs5_tooltip()) }, { title: safeTranslate(m.ebiosWs5_3()), status: data.data.meta.workshops[4].steps[2].status, - href: `${$page.url.pathname}/workshop-5/risk-analyses?next=${$page.url.pathname}` + href: `/risk-assessments/${data.data.last_risk_assessment?.id}?activity=three&next=${$page.url.pathname}`, + disabled: data.data.last_risk_assessment == null, + tooltip: safeTranslate(m.ebiosWs5_tooltip()) }, { title: safeTranslate(m.ebiosWs5_4()), status: data.data.meta.workshops[4].steps[3].status, - href: `${$page.url.pathname}/workshop-5/risk-analyses?next=${$page.url.pathname}` + href: `/risk-assessments/${data.data.last_risk_assessment?.id}?activity=four&next=${$page.url.pathname}`, + disabled: data.data.last_risk_assessment == null, + tooltip: safeTranslate(m.ebiosWs5_tooltip()) }, { title: safeTranslate(m.ebiosWs5_5()), status: data.data.meta.workshops[4].steps[4].status, - href: `${$page.url.pathname}/workshop-5/risk-analyses?next=${$page.url.pathname}` + href: `/risk-assessments/${data.data.last_risk_assessment?.id}/remediation-plan?next=${$page.url.pathname}`, + disabled: data.data.last_risk_assessment == null, + tooltip: safeTranslate(m.ebiosWs5_tooltip()) } ] };