-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the operational risks functionality.
- Loading branch information
1 parent
60db3c6
commit f651822
Showing
17 changed files
with
673 additions
and
757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,98 @@ | ||
<?php | ||
<?php declare(strict_types=1); | ||
/** | ||
* @link https://github.com/monarc-project for the canonical source repository | ||
* @copyright Copyright (c) 2016-2020 SMILE GIE Securitymadein.lu - Licensed under GNU Affero GPL v3 | ||
* @copyright Copyright (c) 2016-2024 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3 | ||
* @license MONARC is licensed under GNU Affero General Public License version 3 | ||
*/ | ||
|
||
namespace Monarc\FrontOffice\Controller; | ||
|
||
use Laminas\Mvc\Controller\AbstractRestfulController; | ||
use Laminas\View\Model\JsonModel; | ||
use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler; | ||
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait; | ||
use Monarc\Core\Validator\InputValidator\InstanceRiskOp\PatchInstanceRiskOpDataInputValidator; | ||
use Monarc\FrontOffice\Model\Entity\Anr; | ||
use Monarc\FrontOffice\Service\AnrInstanceRiskOpService; | ||
use Monarc\FrontOffice\Validator\InputValidator\InstanceRiskOp\PostSpecificInstanceRiskOpDataInputValidator; | ||
use Monarc\FrontOffice\Validator\InputValidator\InstanceRiskOp\UpdateInstanceRiskOpDataInputValidator; | ||
|
||
class ApiAnrInstancesRisksOpController extends AbstractRestfulController | ||
class ApiAnrInstancesRisksOpController extends AbstractRestfulControllerRequestHandler | ||
{ | ||
private AnrInstanceRiskOpService $anrInstanceRiskOpService; | ||
use ControllerRequestResponseHandlerTrait; | ||
|
||
public function __construct(AnrInstanceRiskOpService $anrInstanceRiskOpService) | ||
public function __construct( | ||
private AnrInstanceRiskOpService $anrInstanceRiskOpService, | ||
private PostSpecificInstanceRiskOpDataInputValidator $postSpecificInstanceRiskOpDataInputValidator, | ||
private UpdateInstanceRiskOpDataInputValidator $updateInstanceRiskOpDataInputValidator, | ||
private PatchInstanceRiskOpDataInputValidator $patchInstanceRiskOpDataInputValidator | ||
) { | ||
} | ||
|
||
public function create($data) | ||
{ | ||
$this->anrInstanceRiskOpService = $anrInstanceRiskOpService; | ||
$this->validatePostParams($this->postSpecificInstanceRiskOpDataInputValidator, $data); | ||
|
||
/** @var Anr $anr */ | ||
$anr = $this->getRequest()->getAttribute('anr'); | ||
|
||
$operationalInstanceRisk = $this->anrInstanceRiskOpService->createSpecificOperationalInstanceRisk( | ||
$anr, | ||
$this->postSpecificInstanceRiskOpDataInputValidator->getValidData() | ||
); | ||
|
||
return $this->getSuccessfulJsonResponse(['id' => $operationalInstanceRisk->getId()]); | ||
} | ||
|
||
// TODO: update the calls and usages as on BackOffice side. | ||
/** | ||
* @param array $data | ||
*/ | ||
public function update($id, $data) | ||
{ | ||
$risk = $this->anrInstanceRiskOpService->update((int)$id, $data); | ||
unset($risk['anr'], $risk['instance'], $risk['object'], $risk['rolfRisk']); | ||
$this->validatePostParams($this->updateInstanceRiskOpDataInputValidator, $data); | ||
|
||
return new JsonModel($risk); | ||
} | ||
/** @var Anr $anr */ | ||
$anr = $this->getRequest()->getAttribute('anr'); | ||
|
||
$instanceRiskOp = $this->anrInstanceRiskOpService->update( | ||
$anr, | ||
(int)$id, | ||
$this->updateInstanceRiskOpDataInputValidator->getValidData() | ||
); | ||
|
||
return $this->getPreparedJsonResponse([ | ||
'cacheBrutRisk' => $instanceRiskOp->getCacheBrutRisk(), | ||
'cacheNetRisk' => $instanceRiskOp->getCacheNetRisk(), | ||
'cacheTargetedRisk' => $instanceRiskOp->getCacheTargetedRisk(), | ||
]); | ||
} | ||
/** | ||
* @param array $data | ||
*/ | ||
public function patch($id, $data) | ||
{ | ||
$risk = $this->anrInstanceRiskOpService->updateScaleValue((int)$id, $data); | ||
unset($risk['anr'], $risk['instance'], $risk['object'], $risk['rolfRisk']); | ||
$this->validatePostParams($this->patchInstanceRiskOpDataInputValidator, $data); | ||
/** @var Anr $anr */ | ||
$anr = $this->getRequest()->getAttribute('anr'); | ||
|
||
$instanceRiskOp = $this->anrInstanceRiskOpService->updateScaleValue( | ||
$anr, | ||
(int)$id, | ||
$this->patchInstanceRiskOpDataInputValidator->getValidData() | ||
); | ||
|
||
return $this->getPreparedJsonResponse([ | ||
'cacheBrutRisk' => $instanceRiskOp->getCacheBrutRisk(), | ||
'cacheNetRisk' => $instanceRiskOp->getCacheNetRisk(), | ||
'cacheTargetedRisk' => $instanceRiskOp->getCacheTargetedRisk(), | ||
]); | ||
} | ||
|
||
public function delete($id) | ||
{ | ||
/** @var Anr $anr */ | ||
$anr = $this->getRequest()->getAttribute('anr'); | ||
|
||
$this->anrInstanceRiskOpService->delete($anr, (int)$id); | ||
|
||
return new JsonModel($risk); | ||
return $this->getSuccessfulJsonResponse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,30 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* @link https://github.com/monarc-project for the canonical source repository | ||
* @copyright Copyright (c) 2016-2022 SMILE GIE Securitymadein.lu - Licensed under GNU Affero GPL v3 | ||
* @copyright Copyright (c) 2016-2024 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3 | ||
* @license MONARC is licensed under GNU Affero General Public License version 3 | ||
*/ | ||
|
||
namespace Monarc\FrontOffice\Controller; | ||
|
||
use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler; | ||
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait; | ||
use Monarc\Core\Model\Entity\Anr; | ||
use Monarc\FrontOffice\Model\Entity\Anr; | ||
use Monarc\FrontOffice\Service\AnrObjectService; | ||
use Laminas\View\Model\JsonModel; | ||
|
||
/** | ||
* TODO: refactor me... | ||
*/ | ||
class ApiAnrLibraryController extends AbstractRestfulControllerRequestHandler | ||
{ | ||
use ControllerRequestResponseHandlerTrait; | ||
|
||
protected $name = 'categories'; | ||
|
||
protected $dependencies = ['anr', 'parent']; | ||
public function __construct(private AnrObjectService $anrObjectService) | ||
{ | ||
} | ||
|
||
public function getList() | ||
{ | ||
// TODO: Attach the middleware. | ||
/** @var Anr $anr */ | ||
$anr = $this->getRequest()->getAttribute('anr'); | ||
|
||
/** @var AnrObjectService $service */ | ||
$service = $this->getService(); | ||
$objectsCategories = $service->getLibraryTreeStructure($anr); | ||
|
||
$this->formatDependencies($objectsCategories, $this->dependencies); | ||
|
||
$fields = ['id', 'label1', 'label2', 'label3', 'label4', 'position', 'objects', 'child']; | ||
$objectsCategories = $this->recursiveArray($objectsCategories, null, 0, $fields); | ||
|
||
return new JsonModel([ | ||
$this->name => $objectsCategories | ||
]); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function create($data) | ||
{ | ||
// TODO: Anr object is from the attribute. | ||
$anrId = $this->params()->fromRoute('anrid'); | ||
if (empty($anrId)) { | ||
throw new \Monarc\Core\Exception\Exception('Anr id missing', 412); | ||
} | ||
$data['anr'] = $anrId; | ||
|
||
if (!isset($data['objectId'])) { | ||
throw new \Monarc\Core\Exception\Exception('objectId is missing'); | ||
} | ||
|
||
/** @var AnrObjectService $service */ | ||
$service = $this->getService(); | ||
$id = $service->attachObjectToAnr($data['objectId'], $anrId); | ||
|
||
return new JsonModel([ | ||
'status' => 'ok', | ||
'id' => $id, | ||
]); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function delete($id) | ||
{ | ||
$anrId = $this->params()->fromRoute('anrid'); | ||
if (empty($anrId)) { | ||
throw new \Monarc\Core\Exception\Exception('Anr id missing', 412); | ||
} | ||
|
||
/** @var AnrObjectService $service */ | ||
$service = $this->getService(); | ||
$service->detachObjectFromAnr($id, $anrId); | ||
|
||
return new JsonModel([ | ||
'status' => 'ok' | ||
]); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function get($id) | ||
{ | ||
return $this->methodNotAllowed(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function update($id, $data) | ||
{ | ||
return $this->methodNotAllowed(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function patch($id, $data) | ||
{ | ||
return $this->methodNotAllowed(); | ||
return $this->getPreparedJsonResponse(['categories' => $this->anrObjectService->getLibraryTreeStructure($anr)]); | ||
} | ||
} |
Oops, something went wrong.