Skip to content
Snippets Groups Projects
Commit 020fbe39 authored by Jonathan Foucher's avatar Jonathan Foucher
Browse files

Add residual risks to PDF

parent 92d6a45c
No related branches found
No related tags found
No related merge requests found
Pipeline #30200 failed
......@@ -25,14 +25,20 @@ public function ActionPlanPdf()
->first();
$evaluation = Evaluation::where('organization_id', $organization_id)
->where('status',2)
->where('status', Evaluation::STATUS_DONE)
->where('reference', env('REFERENTIEL_VERSION'))
->with('dangerLevels')
->with('measureLevels')
->with('measureLevels.measure')
->with('organization')
->latest()
->orderBy('updated_at', 'DESC')
->first();
if (!$evaluation) {
abort(404);
}
$collectionAction = collect($evaluation->measureLevels)->filter(function (MeasureLevel $ml) {
return null !== $ml->expected_level && $ml->actual_level < 3 && $ml->actual_level !== $ml->expected_level;
});
......@@ -46,7 +52,7 @@ public function ActionPlanPdf()
'actions' => $actionSorted,
'elu' => 'test elu',
'agent' => 'test agent',
'referentiel' => 'v1.0',
'referentiel' => $evaluation->reference,
'date' => $organization->updated_at->format('d/m/Y'),
];
......@@ -106,21 +112,26 @@ public function PolitiqueSecuritePdf()
->first();
$evaluation = Evaluation::where('organization_id', $organization_id)
->where('status',2)
->where('status', Evaluation::STATUS_DONE)
->where('reference', env('REFERENTIEL_VERSION'))
->with('dangerLevels')
->with('measureLevels')
->with('measureLevels.measure')
->with('organization')
->latest()
->orderBy('updated_at', 'DESC')
->first();
if (!$evaluation) {
abort(404);
}
$data = [
'plan_name' => 'Test plan',
'organization' => $organization,
'evaluation' => $evaluation,
'elu' => 'test elu',
'agent' => 'test agent',
'referentiel' => 'v1.0',
'referentiel' => $evaluation->reference,
'date' => $organization->updated_at->format('d/m/Y'),
];
......@@ -159,14 +170,19 @@ public function DossierCyberSecuritePdf(GraphDataRepository $repository)
->first();
$evaluation = Evaluation::where('organization_id', $organization_id)
->where('status',2)
->where('status', Evaluation::STATUS_DONE)
->where('reference', env('REFERENTIEL_VERSION'))
->with('dangerLevels')
->with('measureLevels')
->with('measureLevels.measure')
->with('organization')
->latest()
->orderBy('updated_at', 'DESC')
->first();
if (!$evaluation) {
abort(404);
}
$collectionAction = collect($evaluation->measureLevels)->filter(function (MeasureLevel $ml) {
return null !== $ml->expected_level && $ml->actual_level < 3 && $ml->actual_level !== $ml->expected_level;
});
......@@ -183,15 +199,16 @@ public function DossierCyberSecuritePdf(GraphDataRepository $repository)
'actions' => $actionSorted,
'elu' => 'test elu',
'agent' => 'test agent',
'referentiel' => 'v1.0',
'referentiel' => $evaluation->reference,
'legendLevels' => $dangerLevels,
'residualRisks' => $evaluation->getResidualDangers(),
'measuresData' => $repository->getMeasuresDataForEvaluation($evaluation),
'attackData' => $repository->getAttackDataForEvaluation($evaluation),
'expositionData' => $repository->getExpositionDataForEvaluation($evaluation),
'date' => $organization->updated_at->format('d/m/Y'),
];
// return view('pdf.dossierCyberSecurite.dossier', $data);
return view('pdf.dossierCyberSecurite.dossier', $data);
$pdf = App::make('snappy.pdf.wrapper');
$pdf->loadView('pdf.dossierCyberSecurite.dossier', $data);
......
......@@ -8,6 +8,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;
/**
* Class Evaluation.
......@@ -15,10 +16,10 @@
* @property int $id
* @property DateTime $createdAt
* @property DateTime $updatedAt
* @property DangerLevelEvaluation[]|iterable $dangerLevels
* @property DangerLevelEvaluation[]|iterable $danger_levels
* @property MeasureLevel[]|iterable $measureLevels
* @property MeasureLevel[]|iterable $measure_levels
* @property DangerLevelEvaluation[]|iterable|Collection $dangerLevels
* @property DangerLevelEvaluation[]|iterable|Collection $danger_levels
* @property MeasureLevel[]|iterable|Collection $measureLevels
* @property MeasureLevel[]|iterable|Collection $measure_levels
* @property int $status
* @property Organization $organization
* @property int $organization_id
......@@ -66,4 +67,33 @@ public function maturityLevels(): HasMany
{
return $this->hasMany(EvaluationMaturityAnswer::class);
}
public function getResidualDangers()
{
// Get all scenarios
// For each scenario
// For each measure
// check if level is zero
// if all measures are 0 for this scenario then it is a residual risk
$scenarios = Scenario::with(['dangers', 'measures'])->get();
$residual_scenarios = $scenarios;
foreach ($scenarios as $scenario) {
foreach ($scenario->measures as $measure) {
// Get the level of this measure for this evaluation
$level = $this->measureLevels->first(function(MeasureLevel $ml) use ($measure) {
return $ml->measure_id === $measure->id;
});
if ($level->actual_level > 0) {
$residual_scenarios = $residual_scenarios->reject($scenario);
}
}
}
return $residual_scenarios->map(function(Scenario $scenario) {
return $scenario->dangers;
})->flatten(1)->unique('id');
}
}
......@@ -281,7 +281,12 @@
<h5 style="margin-left: 25px">3.2 - Liste des risques cyber résiduels.</h5>
<br>
<p>Les risques cyber résiduels sont les risques pour lesquels vous n’avez pas mis en place de mesure de protection :</p>
<p style="margin-left: 25px"></p>
@foreach($residualRisks as $residual)
<p style="margin-left: 25px">• {{$residual->name}}</p>
@endforeach
@if (count($residualRisks) === 0)
<p>Vous n'avez aucun risque résiduel</p>
@endif
<div class="page-break"></div>
......@@ -513,6 +518,8 @@
backdropColor: 'rgba(255,255,255, 0.8)',
fontSize: 25,
z: 10,
min:0,
beginAtZero: true,
},
grid: {
z: 9,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment