Skip to content

Commit

Permalink
feat: redirect to last risk analysis in ebios workshop 5 (#1256)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene authored Dec 26, 2024
1 parent 2603ab7 commit 590eb51
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 deletions.
14 changes: 14 additions & 0 deletions backend/ebios_rm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Qualification,
RiskMatrix,
Threat,
RiskAssessment,
)
from core.validators import (
JSONSchemaInstanceValidator,
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions backend/ebios_rm/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BaseModelSerializer,
FieldsRelatedField,
)
from core.models import StoredLibrary, RiskMatrix
from core.models import RiskMatrix
from .models import (
EbiosRMStudy,
FearedEvent,
Expand All @@ -13,7 +13,6 @@
OperationalScenario,
)
from rest_framework import serializers
import logging


class EbiosRMStudyWriteSerializer(BaseModelSerializer):
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions frontend/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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é",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
]
};
Expand Down

0 comments on commit 590eb51

Please sign in to comment.