Skip to content

Commit

Permalink
Removed useless anr validation across the controllers, fixed some ser…
Browse files Browse the repository at this point in the history
…vices responses.
  • Loading branch information
ruslanbaidan committed Mar 18, 2024
1 parent 908b574 commit f668837
Show file tree
Hide file tree
Showing 34 changed files with 206 additions and 172 deletions.
28 changes: 28 additions & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Monarc\Core\Service\Helper\ScalesCacheHelper;
use Monarc\Core\Storage\Authentication as StorageAuthentication;
use Monarc\Core\Table\Factory\ClientEntityManagerFactory;
use Monarc\Core\Validator\InputValidator as CoreInputValidator;
use Monarc\FrontOffice\Controller;
use Monarc\FrontOffice\CronTask;
use Monarc\FrontOffice\Export;
Expand Down Expand Up @@ -1648,6 +1649,33 @@
ReflectionBasedAbstractFactory::class,
InputValidator\InstanceRiskOp\UpdateInstanceRiskOpDataInputValidator::class =>
ReflectionBasedAbstractFactory::class,
CoreInputValidator\Asset\PostAssetDataInputValidator::class => static function (
Containerinterface $container
) {
return new CoreInputValidator\Asset\PostAssetDataInputValidator(
$container->get('config'),
$container->get(CoreInputValidator\InputValidationTranslator::class),
$container->get(Table\AssetTable::class)
);
},
CoreInputValidator\Threat\PostThreatDataInputValidator::class => static function (
Containerinterface $container
) {
return new CoreInputValidator\Threat\PostThreatDataInputValidator(
$container->get('config'),
$container->get(CoreInputValidator\InputValidationTranslator::class),
$container->get(Table\ThreatTable::class)
);
},
CoreInputValidator\Vulnerability\PostVulnerabilityDataInputValidator::class => static function (
Containerinterface $container
) {
return new CoreInputValidator\Vulnerability\PostVulnerabilityDataInputValidator(
$container->get('config'),
$container->get(CoreInputValidator\InputValidationTranslator::class),
$container->get(Table\VulnerabilityTable::class)
);
},

// Commands
Import\Command\ImportAnalysesCommand::class => static function (
Expand Down
4 changes: 0 additions & 4 deletions src/Controller/ApiAnrAbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ public function get($id)

$entity = $this->getService()->getEntity($identifier);

if (!$entity['anr'] || $entity['anr']->get('id') !== $anrId) {
throw new Exception('Anr ids diffence', 412);
}

if (count($this->dependencies)) {
$this->formatDependencies($entity, $this->dependencies);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Controller/ApiAnrInstancesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ public function get($id)

if ($this->params()->fromQuery('csv', false)) {
return $this->setCsvResponse(
$this->anrInstanceRiskOpService->getOperationalRisksInCsv($anr, $id, $this->parseParams())
$this->anrInstanceRiskOpService->getOperationalRisksInCsv($anr, (int)$id, $this->parseParams())
);
}

if ($this->params()->fromQuery('csvInfoInst', false)) {
return $this->setCsvResponse(
$this->anrInstanceRiskService->getInstanceRisksInCsv($anr, $id, $this->parseParams())
$this->anrInstanceRiskService->getInstanceRisksInCsv($anr, (int)$id, $this->parseParams())
);
}

$instanceData = $this->anrInstanceService->getInstanceData($anr, $id);
$instanceData = $this->anrInstanceService->getInstanceData($anr, (int)$id);

return $this->getPreparedJsonResponse($instanceData);
}
Expand Down Expand Up @@ -138,8 +138,8 @@ private function parseParams(): array
'order' => $params->fromQuery('order', 'maxRisk'),
'order_direction' => $params->fromQuery('order_direction', 'desc'),
'thresholds' => $params->fromQuery('thresholds'),
'page' => $params->fromQuery('page', 1),
'limit' => $params->fromQuery('limit', 0),
'page' => (int)$params->fromQuery('page', 1),
'limit' => (int)$params->fromQuery('limit', 0),
];
}

Expand Down
7 changes: 0 additions & 7 deletions src/Controller/ApiAnrRecordActorsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ public function get($id)
$anrId = (int)$this->params()->fromRoute('anrid');
$entity = $this->getService()->getEntity(['anr' => $anrId, 'id' => $id]);

if (empty($anrId)) {
throw new Exception('Anr id missing', 412);
}
if (!$entity['anr'] || $entity['anr']->get('id') != $anrId) {
throw new Exception('Anr ids are different', 412);
}

if (count($this->dependencies)) {
$this->formatDependencies($entity, $this->dependencies);
}
Expand Down
7 changes: 0 additions & 7 deletions src/Controller/ApiAnrRecordPersonalDataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ public function get($id)
$anrId = (int)$this->params()->fromRoute('anrid');
$entity = $this->getService()->getEntity(['anr' => $anrId, 'id' => $id]);

if (empty($anrId)) {
throw new Exception('Anr id missing', 412);
}
if (!$entity['anr'] || $entity['anr']->get('id') != $anrId) {
throw new Exception('Anr ids are different', 412);
}

$this->formatDependencies($entity, $this->dependencies);

return $this->getPreparedJsonResponse($entity);
Expand Down
7 changes: 0 additions & 7 deletions src/Controller/ApiAnrRecordProcessorsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ public function get($id)
$anrId = (int)$this->params()->fromRoute('anrid');
$entity = $this->getService()->getEntity(['anr' => $anrId, 'id' => $id]);

if (empty($anrId)) {
throw new Exception('Anr id missing', 412);
}
if (!$entity['anr'] || $entity['anr']->get('id') != $anrId) {
throw new Exception('Anr ids are different', 412);
}

$this->formatDependencies($entity, $this->dependencies);

return $this->getPreparedJsonResponse($entity);
Expand Down
6 changes: 0 additions & 6 deletions src/Controller/ApiAnrRecordsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ public function get($id)
$anrId = (int)$this->params()->fromRoute('anrid');
$entity = $this->getService()->getEntity(['id' => $id]);

if (empty($anrId)) {
throw new Exception('Anr id missing', 412);
}
if (!$entity['anr'] || $entity['anr']->get('id') !== $anrId) {
throw new Exception('Anr ids are different', 412);
}

$this->formatDependencies($entity, $this->dependencies);

Expand Down
7 changes: 0 additions & 7 deletions src/Controller/ApiAnrReferentialsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ public function get($id)
$anrId = (int)$this->params()->fromRoute('anrid');
$entity = $this->getService()->getEntity(['anr' => $anrId, 'uuid' => $id]);

if (empty($anrId)) {
throw new Exception('Anr id missing', 412);
}
if (!$entity['anr'] || $entity['anr']->get('id') != $anrId) {
throw new Exception('Anr ids diffence', 412);
}

$this->formatDependencies($entity, $this->dependencies);

return $this->getPreparedJsonResponse($entity);
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/ApiAnrRisksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ protected function prepareParams(): array
'order' => $params->fromQuery('order', 'maxRisk'),
'order_direction' => $params->fromQuery('order_direction', 'desc'),
'thresholds' => $params->fromQuery('thresholds'),
'page' => $params->fromQuery('page', 1),
'limit' => $params->fromQuery('limit', 50),
'page' => (int)$params->fromQuery('page', 1),
'limit' => (int)$params->fromQuery('limit', 50),
'amvs' => $params->fromQuery('amvs')
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ApiAnrScalesCommentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(
public function getList()
{
$formattedParams = $this->getFormattedInputParams($this->getScaleCommentsInputFormatter);
$formattedParams->setFilterValueFor('scale', (int)$this->params()->fromRoute('scaleId'));
$formattedParams->setFilterValueFor('scale', (int)$this->params()->fromRoute('scaleid'));

$comments = $this->anrScaleCommentService->getList($formattedParams);

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/ApiDashboardAnrRisksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ private function getParsedParams(): array
'order' => $this->params()->fromQuery('order', 'maxRisk'),
'order_direction' => $this->params()->fromQuery('order_direction', 'desc'),
'thresholds' => $this->params()->fromQuery('thresholds'),
'page' => $this->params()->fromQuery('page', 1),
'limit' => $this->params()->fromQuery('limit', 50)
'page' => (int)$this->params()->fromQuery('page', 1),
'limit' => (int)$this->params()->fromQuery('limit', 50)
];
}
}
4 changes: 2 additions & 2 deletions src/Controller/ApiSoaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ public function get($id)
$soaScaleCommentsData = $this->soaScaleCommentService->getSoaScaleCommentsData($anr);

$entity['anr'] = [
'id' => $measure->getAnr()->getId(),
'label' => $measure->getAnr()->getLabel(),
'id' => $anr->getId(),
'label' => $anr->getLabel(),
];
$entity['measure'] = $measure->getJsonArray();
$entity['measure']['category'] = $measure->getCategory()->getJsonArray();
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Controller/ApiAnrExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
use Monarc\FrontOffice\Export\Service\AnrExportService;
use Monarc\FrontOffice\Model\Entity\Anr;
use Monarc\FrontOffice\Entity\Anr;
use function strlen;

class ApiAnrExportController extends AbstractRestfulControllerRequestHandler
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Controller/ApiAnrInstancesExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
use Monarc\FrontOffice\Export\Service\AnrInstanceExportService;
use Monarc\FrontOffice\Model\Entity\Anr;
use Monarc\FrontOffice\Entity\Anr;

class ApiAnrInstancesExportController extends AbstractRestfulControllerRequestHandler
{
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Controller/ApiAnrObjectsExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\FrontOffice\Model\Entity\Anr;
use Monarc\FrontOffice\Entity\Anr;
use Monarc\FrontOffice\Export\Service\AnrObjectExportService;

class ApiAnrObjectsExportController extends AbstractRestfulControllerRequestHandler
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Service/AmvExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Monarc\FrontOffice\Export\Service;

use Monarc\FrontOffice\Model\Entity;
use Monarc\FrontOffice\Entity;

class AmvExportService
{
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Service/AnrExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Monarc\FrontOffice\Export\Service;

use Monarc\FrontOffice\Model\Entity;
use Monarc\FrontOffice\Entity;
use Monarc\FrontOffice\Model\Table as DeprecatedTable;
use Monarc\FrontOffice\Table;

Expand Down
Loading

0 comments on commit f668837

Please sign in to comment.