Skip to content

Commit f668837

Browse files
committed
Removed useless anr validation across the controllers, fixed some services responses.
1 parent 908b574 commit f668837

34 files changed

+206
-172
lines changed

config/module.config.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Monarc\Core\Service\Helper\ScalesCacheHelper;
2020
use Monarc\Core\Storage\Authentication as StorageAuthentication;
2121
use Monarc\Core\Table\Factory\ClientEntityManagerFactory;
22+
use Monarc\Core\Validator\InputValidator as CoreInputValidator;
2223
use Monarc\FrontOffice\Controller;
2324
use Monarc\FrontOffice\CronTask;
2425
use Monarc\FrontOffice\Export;
@@ -1648,6 +1649,33 @@
16481649
ReflectionBasedAbstractFactory::class,
16491650
InputValidator\InstanceRiskOp\UpdateInstanceRiskOpDataInputValidator::class =>
16501651
ReflectionBasedAbstractFactory::class,
1652+
CoreInputValidator\Asset\PostAssetDataInputValidator::class => static function (
1653+
Containerinterface $container
1654+
) {
1655+
return new CoreInputValidator\Asset\PostAssetDataInputValidator(
1656+
$container->get('config'),
1657+
$container->get(CoreInputValidator\InputValidationTranslator::class),
1658+
$container->get(Table\AssetTable::class)
1659+
);
1660+
},
1661+
CoreInputValidator\Threat\PostThreatDataInputValidator::class => static function (
1662+
Containerinterface $container
1663+
) {
1664+
return new CoreInputValidator\Threat\PostThreatDataInputValidator(
1665+
$container->get('config'),
1666+
$container->get(CoreInputValidator\InputValidationTranslator::class),
1667+
$container->get(Table\ThreatTable::class)
1668+
);
1669+
},
1670+
CoreInputValidator\Vulnerability\PostVulnerabilityDataInputValidator::class => static function (
1671+
Containerinterface $container
1672+
) {
1673+
return new CoreInputValidator\Vulnerability\PostVulnerabilityDataInputValidator(
1674+
$container->get('config'),
1675+
$container->get(CoreInputValidator\InputValidationTranslator::class),
1676+
$container->get(Table\VulnerabilityTable::class)
1677+
);
1678+
},
16511679

16521680
// Commands
16531681
Import\Command\ImportAnalysesCommand::class => static function (

src/Controller/ApiAnrAbstractController.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ public function get($id)
7575

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

78-
if (!$entity['anr'] || $entity['anr']->get('id') !== $anrId) {
79-
throw new Exception('Anr ids diffence', 412);
80-
}
81-
8278
if (count($this->dependencies)) {
8379
$this->formatDependencies($entity, $this->dependencies);
8480
}

src/Controller/ApiAnrInstancesController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ public function get($id)
5151

5252
if ($this->params()->fromQuery('csv', false)) {
5353
return $this->setCsvResponse(
54-
$this->anrInstanceRiskOpService->getOperationalRisksInCsv($anr, $id, $this->parseParams())
54+
$this->anrInstanceRiskOpService->getOperationalRisksInCsv($anr, (int)$id, $this->parseParams())
5555
);
5656
}
5757

5858
if ($this->params()->fromQuery('csvInfoInst', false)) {
5959
return $this->setCsvResponse(
60-
$this->anrInstanceRiskService->getInstanceRisksInCsv($anr, $id, $this->parseParams())
60+
$this->anrInstanceRiskService->getInstanceRisksInCsv($anr, (int)$id, $this->parseParams())
6161
);
6262
}
6363

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

6666
return $this->getPreparedJsonResponse($instanceData);
6767
}
@@ -138,8 +138,8 @@ private function parseParams(): array
138138
'order' => $params->fromQuery('order', 'maxRisk'),
139139
'order_direction' => $params->fromQuery('order_direction', 'desc'),
140140
'thresholds' => $params->fromQuery('thresholds'),
141-
'page' => $params->fromQuery('page', 1),
142-
'limit' => $params->fromQuery('limit', 0),
141+
'page' => (int)$params->fromQuery('page', 1),
142+
'limit' => (int)$params->fromQuery('limit', 0),
143143
];
144144
}
145145

src/Controller/ApiAnrRecordActorsController.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ public function get($id)
2525
$anrId = (int)$this->params()->fromRoute('anrid');
2626
$entity = $this->getService()->getEntity(['anr' => $anrId, 'id' => $id]);
2727

28-
if (empty($anrId)) {
29-
throw new Exception('Anr id missing', 412);
30-
}
31-
if (!$entity['anr'] || $entity['anr']->get('id') != $anrId) {
32-
throw new Exception('Anr ids are different', 412);
33-
}
34-
3528
if (count($this->dependencies)) {
3629
$this->formatDependencies($entity, $this->dependencies);
3730
}

src/Controller/ApiAnrRecordPersonalDataController.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ public function get($id)
5050
$anrId = (int)$this->params()->fromRoute('anrid');
5151
$entity = $this->getService()->getEntity(['anr' => $anrId, 'id' => $id]);
5252

53-
if (empty($anrId)) {
54-
throw new Exception('Anr id missing', 412);
55-
}
56-
if (!$entity['anr'] || $entity['anr']->get('id') != $anrId) {
57-
throw new Exception('Anr ids are different', 412);
58-
}
59-
6053
$this->formatDependencies($entity, $this->dependencies);
6154

6255
return $this->getPreparedJsonResponse($entity);

src/Controller/ApiAnrRecordProcessorsController.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ public function get($id)
2525
$anrId = (int)$this->params()->fromRoute('anrid');
2626
$entity = $this->getService()->getEntity(['anr' => $anrId, 'id' => $id]);
2727

28-
if (empty($anrId)) {
29-
throw new Exception('Anr id missing', 412);
30-
}
31-
if (!$entity['anr'] || $entity['anr']->get('id') != $anrId) {
32-
throw new Exception('Anr ids are different', 412);
33-
}
34-
3528
$this->formatDependencies($entity, $this->dependencies);
3629

3730
return $this->getPreparedJsonResponse($entity);

src/Controller/ApiAnrRecordsController.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ public function get($id)
7272
$anrId = (int)$this->params()->fromRoute('anrid');
7373
$entity = $this->getService()->getEntity(['id' => $id]);
7474

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

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

src/Controller/ApiAnrReferentialsController.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ public function get($id)
4949
$anrId = (int)$this->params()->fromRoute('anrid');
5050
$entity = $this->getService()->getEntity(['anr' => $anrId, 'uuid' => $id]);
5151

52-
if (empty($anrId)) {
53-
throw new Exception('Anr id missing', 412);
54-
}
55-
if (!$entity['anr'] || $entity['anr']->get('id') != $anrId) {
56-
throw new Exception('Anr ids diffence', 412);
57-
}
58-
5952
$this->formatDependencies($entity, $this->dependencies);
6053

6154
return $this->getPreparedJsonResponse($entity);

src/Controller/ApiAnrRisksController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ protected function prepareParams(): array
7373
'order' => $params->fromQuery('order', 'maxRisk'),
7474
'order_direction' => $params->fromQuery('order_direction', 'desc'),
7575
'thresholds' => $params->fromQuery('thresholds'),
76-
'page' => $params->fromQuery('page', 1),
77-
'limit' => $params->fromQuery('limit', 50),
76+
'page' => (int)$params->fromQuery('page', 1),
77+
'limit' => (int)$params->fromQuery('limit', 50),
7878
'amvs' => $params->fromQuery('amvs')
7979
];
8080
}

src/Controller/ApiAnrScalesCommentsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(
2626
public function getList()
2727
{
2828
$formattedParams = $this->getFormattedInputParams($this->getScaleCommentsInputFormatter);
29-
$formattedParams->setFilterValueFor('scale', (int)$this->params()->fromRoute('scaleId'));
29+
$formattedParams->setFilterValueFor('scale', (int)$this->params()->fromRoute('scaleid'));
3030

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

0 commit comments

Comments
 (0)