Skip to content

Commit

Permalink
Added the threat validation to manage the evaluation and treands upda…
Browse files Browse the repository at this point in the history
…te fields, fixed the local risk threat modification, fixed reports generation.
  • Loading branch information
ruslanbaidan committed Aug 21, 2024
1 parent 80f64f3 commit 9744558
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 248 deletions.
15 changes: 7 additions & 8 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1651,22 +1651,21 @@
ReflectionBasedAbstractFactory::class,
InputValidator\InstanceRiskOp\UpdateInstanceRiskOpDataInputValidator::class =>
ReflectionBasedAbstractFactory::class,
CoreInputValidator\Asset\PostAssetDataInputValidator::class => static function (
Containerinterface $container
) {
return new CoreInputValidator\Asset\PostAssetDataInputValidator(
InputValidator\Threat\PostThreatDataInputValidator::class => static function (Containerinterface $container)
{

Check failure on line 1655 in config/module.config.php

View workflow job for this annotation

GitHub Actions / build

Opening brace should be on the same line as the declaration
return new InputValidator\Threat\PostThreatDataInputValidator(
$container->get('config'),
$container->get(CoreInputValidator\InputValidationTranslator::class),
$container->get(Table\AssetTable::class)
$container->get(Table\ThreatTable::class)
);
},
CoreInputValidator\Threat\PostThreatDataInputValidator::class => static function (
CoreInputValidator\Asset\PostAssetDataInputValidator::class => static function (
Containerinterface $container
) {
return new CoreInputValidator\Threat\PostThreatDataInputValidator(
return new CoreInputValidator\Asset\PostAssetDataInputValidator(
$container->get('config'),
$container->get(CoreInputValidator\InputValidationTranslator::class),
$container->get(Table\ThreatTable::class)
$container->get(Table\AssetTable::class)
);
},
CoreInputValidator\Vulnerability\PostVulnerabilityDataInputValidator::class => static function (
Expand Down
20 changes: 11 additions & 9 deletions src/Controller/ApiAnrDeliverableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

namespace Monarc\FrontOffice\Controller;

use Laminas\Diactoros\Response;
use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\Core\Exception\Exception;
use Monarc\FrontOffice\Entity\Anr;
use Monarc\FrontOffice\Service\DeliverableGenerationService;
use function strlen;

class ApiAnrDeliverableController extends AbstractRestfulControllerRequestHandler
{
Expand All @@ -36,17 +38,17 @@ public function create($data)
throw new Exception('Generated file is not found: ' . $filePath);
}

$response = $this->getResponse();
$response->setContent(file_get_contents($filePath));

$reportContent = file_get_contents($filePath);
$stream = fopen('php://memory', 'rb+');
fwrite($stream, $reportContent);
rewind($stream);
unlink($filePath);

$headers = $response->getHeaders();
$headers->clearHeaders()
->addHeaderLine('Content-Type', 'text/plain; charset=utf-8')
->addHeaderLine('Content-Disposition', 'attachment; filename="deliverable.docx"');

return $this->response;
return new Response($stream, 200, [
'Content-Type' => 'text/plain; charset=utf-8',
'Content-Length' => strlen($reportContent),
'Content-Disposition' => 'attachment; filename="deliverable.docx"',
]);
}

public function get($id)
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ApiAnrThreatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\Core\Validator\InputValidator\Threat\PostThreatDataInputValidator;
use Monarc\FrontOffice\InputFormatter\Threat\GetThreatsInputFormatter;
use Monarc\FrontOffice\Entity\Anr;
use Monarc\FrontOffice\Service\AnrThreatService;
use Monarc\FrontOffice\Validator\InputValidator\Threat\PostThreatDataInputValidator;

class ApiAnrThreatsController extends AbstractRestfulControllerRequestHandler
{
Expand Down
5 changes: 3 additions & 2 deletions src/Service/AnrInstanceRiskService.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,9 @@ private function updateInstanceRiskData(Entity\InstanceRisk $instanceRisk, array
if (isset($data['reductionAmount'])) {
$instanceRisk->setReductionAmount((int)$data['reductionAmount']);
}
if (isset($data['threatRate'])) {
$instanceRisk->setThreatRate((int)$data['threatRate']);
if (isset($data['threatRate']) && $instanceRisk->getThreatRate() !== $data['threatRate']) {
$instanceRisk->setThreatRate((int)$data['threatRate'])
->setIsThreatRateNotSetOrModifiedExternally(false);
}
if (isset($data['vulnerabilityRate'])) {
$instanceRisk->setVulnerabilityRate((int)$data['vulnerabilityRate']);
Expand Down
8 changes: 5 additions & 3 deletions src/Service/AnrThreatService.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ public function deleteList(Anr $anr, array $data): void
private function manageQualification(Threat $threat, array $data): void
{
if (isset($data['qualification'])) {
$instancesRisks = $this->instanceRiskTable->findByAnrThreatExcludeLocallySetThreatRatesOrNot(
$threat->setQualification($data['qualification']);

$instancesRisks = $this->instanceRiskTable->findByAnrAndThreatExcludeLocallySet(
$threat->getAnr(),
$threat,
empty($data['forceQualification'])
Expand All @@ -202,9 +204,9 @@ private function manageQualification(Threat $threat, array $data): void
$instanceRisk->setIsThreatRateNotSetOrModifiedExternally(true);
}

$this->instanceRiskTable->save($instanceRisk, false);

$this->anrInstanceRiskService->recalculateRiskRatesAndUpdateRecommendationsPositions($instanceRisk);

$this->instanceRiskTable->save($instanceRisk, false);
}
}
}
Expand Down
Loading

0 comments on commit 9744558

Please sign in to comment.