Skip to content

Commit 2a9e708

Browse files
committed
Added the reassessment trigger criteria functionality, corrected the translations for the risk sources.
1 parent 8305958 commit 2a9e708

10 files changed

Lines changed: 541 additions & 10 deletions

config/module.config.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,23 @@
12481248
],
12491249
],
12501250
],
1251+
1252+
'reassessment_triggers' => [
1253+
'type' => 'segment',
1254+
'options' => [
1255+
'route' => 'reassessment-triggers[/:id]',
1256+
'constraints' => [
1257+
'id' => '[0-9]+',
1258+
],
1259+
'defaults' => [
1260+
'controller' => PipeSpec::class,
1261+
'middleware' => new PipeSpec(
1262+
AnrValidationMiddleware::class,
1263+
Controller\ApiAnrReassessmentTriggersController::class,
1264+
),
1265+
],
1266+
],
1267+
],
12511268
],
12521269
],
12531270
'monarc_api_doc_models' => [
@@ -1419,6 +1436,7 @@
14191436
Controller\ApiClientsController::class => AutowireFactory::class,
14201437
Controller\ApiCoreReferentialsController::class => AutowireFactory::class,
14211438
Controller\ApiAnrRiskSourcesController::class => AutowireFactory::class,
1439+
Controller\ApiAnrReassessmentTriggersController::class => AutowireFactory::class,
14221440
Controller\ApiUserPasswordController::class => AutowireFactory::class,
14231441
Controller\ApiUserTwoFAController::class => AutowireFactory::class,
14241442
Controller\ApiUserRecoveryCodesController::class => AutowireFactory::class,
@@ -1528,6 +1546,7 @@
15281546
Table\OperationalRiskScaleCommentTable::class => ClientEntityManagerFactory::class,
15291547
Table\OperationalInstanceRiskScaleTable::class => ClientEntityManagerFactory::class,
15301548
Table\RiskSourceTable::class => ClientEntityManagerFactory::class,
1549+
Table\ReassessmentTriggerTable::class => ClientEntityManagerFactory::class,
15311550
Table\RecommendationTable::class => ClientEntityManagerFactory::class,
15321551
Table\RecommendationHistoryTable::class => ClientEntityManagerFactory::class,
15331552
Table\RecommendationRiskTable::class => ClientEntityManagerFactory::class,
@@ -1613,6 +1632,7 @@
16131632
Service\SoaScaleCommentService::class => AutowireFactory::class,
16141633
Service\SystemMessageService::class => AutowireFactory::class,
16151634
Service\RiskSourceService::class => AutowireFactory::class,
1635+
Service\ReassessmentTriggerService::class => AutowireFactory::class,
16161636
Stats\Service\StatsAnrService::class => ReflectionBasedAbstractFactory::class,
16171637
Stats\Service\StatsSettingsService::class => AutowireFactory::class,
16181638
CronTask\Service\CronTaskService::class => AutowireFactory::class,
@@ -1866,6 +1886,7 @@
18661886
'monarc_api_models',
18671887
'monarc_api_referentials',
18681888
'monarc_api_global_client_anr/risk_sources',
1889+
'monarc_api_global_client_anr/reassessment_triggers',
18691890
'monarc_api_client',
18701891
'monarc_api_global_client_anr/carto_risks',
18711892
'monarc_api_global_client_anr/risk_owners',
@@ -1881,6 +1902,7 @@
18811902
'monarc_api_models',
18821903
'monarc_api_referentials',
18831904
'monarc_api_global_client_anr/risk_sources',
1905+
'monarc_api_global_client_anr/reassessment_triggers',
18841906
'monarc_api_admin_users_roles',
18851907
'monarc_api_global_client_anr/anr_instance_metadata_field',
18861908
'monarc_api_global_client_anr/instance_metadata',
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php declare(strict_types=1);
2+
/**
3+
* @link https://github.com/monarc-project for the canonical source repository
4+
* @copyright Copyright (c) 2016-2026 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3
5+
* @license MONARC is licensed under GNU Affero General Public License version 3
6+
*/
7+
8+
use Phinx\Migration\AbstractMigration;
9+
10+
class AddAnrReassessmentTriggers extends AbstractMigration
11+
{
12+
public function up(): void
13+
{
14+
$this->execute(
15+
'CREATE TABLE IF NOT EXISTS `anr_reassessment_triggers` (
16+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
17+
`anr_id` int(11) unsigned NOT NULL,
18+
`trigger_type` varchar(255) DEFAULT "",
19+
`description` text NOT NULL,
20+
`is_active` tinyint(1) NOT NULL DEFAULT 1,
21+
`position` int(11) NOT NULL DEFAULT 0,
22+
`creator` varchar(255) DEFAULT NULL,
23+
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
24+
`updater` varchar(255) DEFAULT NULL,
25+
`updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
26+
PRIMARY KEY (`id`),
27+
KEY `anr_reassessment_triggers_anr_id_indx` (`anr_id`),
28+
KEY `anr_reassessment_triggers_anr_id_trigger_type_indx` (`anr_id`, `trigger_type`),
29+
KEY `anr_reassessment_triggers_anr_id_position_indx` (`anr_id`, `position`),
30+
CONSTRAINT `fk_anr_reassessment_triggers_anr`
31+
FOREIGN KEY (`anr_id`) REFERENCES `anrs` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT
32+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;'
33+
);
34+
}
35+
36+
public function down(): void
37+
{
38+
$this->table('anr_reassessment_triggers')->drop()->save();
39+
}
40+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php declare(strict_types=1);
2+
/**
3+
* @link https://github.com/monarc-project for the canonical source repository
4+
* @copyright Copyright (c) 2016-2026 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3
5+
* @license MONARC is licensed under GNU Affero General Public License version 3
6+
*/
7+
8+
namespace Monarc\FrontOffice\Controller;
9+
10+
use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
11+
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
12+
use Monarc\Core\InputFormatter\ReassessmentTrigger\GetReassessmentTriggersInputFormatter;
13+
use Monarc\Core\Service\ReassessmentTriggerService as CoreReassessmentTriggerService;
14+
use Monarc\Core\Validator\InputValidator\ReassessmentTrigger\PatchReassessmentTriggerDataInputValidator;
15+
use Monarc\Core\Validator\InputValidator\ReassessmentTrigger\PostReassessmentTriggerDataInputValidator;
16+
use Monarc\FrontOffice\Entity\Anr;
17+
use Monarc\FrontOffice\Entity\ReassessmentTrigger;
18+
use Monarc\FrontOffice\Service\ReassessmentTriggerService;
19+
20+
class ApiAnrReassessmentTriggersController extends AbstractRestfulControllerRequestHandler
21+
{
22+
use ControllerRequestResponseHandlerTrait;
23+
24+
public function __construct(
25+
private GetReassessmentTriggersInputFormatter $getReassessmentTriggersInputFormatter,
26+
private ReassessmentTriggerService $reassessmentTriggerService,
27+
private CoreReassessmentTriggerService $coreReassessmentTriggerService,
28+
private PostReassessmentTriggerDataInputValidator $postReassessmentTriggerDataInputValidator,
29+
private PatchReassessmentTriggerDataInputValidator $patchReassessmentTriggerDataInputValidator
30+
) {
31+
}
32+
33+
public function getList()
34+
{
35+
$formattedParams = $this->getFormattedInputParams($this->getReassessmentTriggersInputFormatter);
36+
/** @var Anr $anr */
37+
$anr = $this->getRequest()->getAttribute('anr');
38+
39+
return $this->getPreparedJsonResponse([
40+
'count' => $this->reassessmentTriggerService->getCount($formattedParams),
41+
'reassessmentTriggers' => array_map(
42+
[$this, 'prepareReassessmentTriggerData'],
43+
$this->reassessmentTriggerService->getList($formattedParams)
44+
),
45+
'availableReassessmentTriggers' => $this->coreReassessmentTriggerService->getSelectionData(
46+
$anr->getLanguageCode()
47+
),
48+
]);
49+
}
50+
51+
public function get($id)
52+
{
53+
/** @var Anr $anr */
54+
$anr = $this->getRequest()->getAttribute('anr');
55+
56+
return $this->getPreparedJsonResponse(
57+
$this->prepareReassessmentTriggerData($this->reassessmentTriggerService->get($anr, (int)$id))
58+
);
59+
}
60+
61+
public function create($data)
62+
{
63+
/** @var Anr $anr */
64+
$anr = $this->getRequest()->getAttribute('anr');
65+
$this->validatePostParams($this->postReassessmentTriggerDataInputValidator, $data);
66+
67+
return $this->getSuccessfulJsonResponse($this->prepareReassessmentTriggerData(
68+
$this->reassessmentTriggerService->create(
69+
$anr,
70+
$this->postReassessmentTriggerDataInputValidator->getValidData()
71+
)
72+
));
73+
}
74+
75+
public function update($id, $data)
76+
{
77+
/** @var Anr $anr */
78+
$anr = $this->getRequest()->getAttribute('anr');
79+
$this->validatePostParams($this->patchReassessmentTriggerDataInputValidator, $data);
80+
81+
return $this->getSuccessfulJsonResponse($this->prepareReassessmentTriggerData(
82+
$this->reassessmentTriggerService->update(
83+
$anr,
84+
(int)$id,
85+
$this->patchReassessmentTriggerDataInputValidator->getValidData()
86+
)
87+
));
88+
}
89+
90+
public function delete($id)
91+
{
92+
/** @var Anr $anr */
93+
$anr = $this->getRequest()->getAttribute('anr');
94+
$this->reassessmentTriggerService->delete($anr, (int)$id);
95+
96+
return $this->getSuccessfulJsonResponse();
97+
}
98+
99+
private function prepareReassessmentTriggerData(ReassessmentTrigger $reassessmentTrigger): array
100+
{
101+
return [
102+
'id' => $reassessmentTrigger->getId(),
103+
'triggerType' => $reassessmentTrigger->getTriggerType(),
104+
'description' => $reassessmentTrigger->getDescription(),
105+
'isActive' => $reassessmentTrigger->isActive(),
106+
'position' => $reassessmentTrigger->getPosition(),
107+
];
108+
}
109+
}

src/Entity/ReassessmentTrigger.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php declare(strict_types=1);
2+
/**
3+
* @link https://github.com/monarc-project for the canonical source repository
4+
* @copyright Copyright (c) 2016-2026 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3
5+
* @license MONARC is licensed under GNU Affero General Public License version 3
6+
*/
7+
8+
namespace Monarc\FrontOffice\Entity;
9+
10+
use Doctrine\ORM\Mapping as ORM;
11+
use Monarc\Core\Entity\ReassessmentTriggerSuperClass;
12+
13+
/**
14+
* @ORM\Table(
15+
* name="anr_reassessment_triggers",
16+
* indexes={
17+
* @ORM\Index(name="anr_reassessment_triggers_anr_id_indx", columns={"anr_id"}),
18+
* @ORM\Index(name="anr_reassessment_triggers_anr_id_trigger_type_indx", columns={"anr_id", "trigger_type"}),
19+
* @ORM\Index(name="anr_reassessment_triggers_anr_id_position_indx", columns={"anr_id", "position"})
20+
* }
21+
* )
22+
* @ORM\Entity
23+
* @ORM\HasLifecycleCallbacks()
24+
*/
25+
class ReassessmentTrigger extends ReassessmentTriggerSuperClass
26+
{
27+
/**
28+
* @var Anr
29+
*
30+
* @ORM\ManyToOne(targetEntity="Anr")
31+
* @ORM\JoinColumns({
32+
* @ORM\JoinColumn(name="anr_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
33+
* })
34+
*/
35+
protected $anr;
36+
37+
public function getAnr(): Anr
38+
{
39+
return $this->anr;
40+
}
41+
42+
public function setAnr(Anr $anr): self
43+
{
44+
$this->anr = $anr;
45+
46+
return $this;
47+
}
48+
49+
public function getImplicitPositionRelationsValues(): array
50+
{
51+
return ['anr' => $this->anr];
52+
}
53+
}

src/Export/Service/AnrExportService.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __construct(
3535
private Table\ThreatTable $threatTable,
3636
private Table\VulnerabilityTable $vulnerabilityTable,
3737
private Table\RiskSourceTable $riskSourceTable,
38+
private Table\ReassessmentTriggerTable $reassessmentTriggerTable,
3839
private Table\AmvTable $amvTable,
3940
private Table\RolfTagTable $rolfTagTable,
4041
private Table\RolfRiskTable $rolfRiskTable,
@@ -84,6 +85,7 @@ private function prepareExportData(Entity\Anr $anr, array $exportParams): array
8485
$withInterviews = $withEval && !empty($exportParams['interviews']);
8586
$withSoas = $withEval && !empty($exportParams['soas']);
8687
$withRecords = $withEval && !empty($exportParams['records']);
88+
$withReassessmentTriggers = $withEval && !empty($exportParams['reassessmentTriggers']);
8789
$withLibrary = !empty($exportParams['assetsLibrary']);
8890
$withKnowledgeBase = !empty($exportParams['knowledgeBase']);
8991

@@ -98,6 +100,7 @@ private function prepareExportData(Entity\Anr $anr, array $exportParams): array
98100
'withInterviews' => $withInterviews,
99101
'withSoas' => $withSoas,
100102
'withRecords' => $withRecords,
103+
'withReassessmentTriggers' => $withReassessmentTriggers,
101104
'withLibrary' => $withLibrary,
102105
'withKnowledgeBase' => $withKnowledgeBase,
103106
'languageCode' => $anr->getLanguageCode(),
@@ -126,6 +129,7 @@ private function prepareExportData(Entity\Anr $anr, array $exportParams): array
126129
'method' => $withMethodSteps ? $this->prepareMethodData($anr, !$withKnowledgeBase) : [],
127130
'thresholds' => $withEval ? $this->prepareAnrTrashholdsData($anr) : [],
128131
'interviews' => $withInterviews ? $this->prepareInterviewsData($anr) : [],
132+
'reassessmentTriggers' => $withReassessmentTriggers ? $this->prepareReassessmentTriggersData($anr) : [],
129133
'gdprRecords' => $withRecords ? $this->prepareGdprRecordsData($anr) : [],
130134
];
131135
}
@@ -563,6 +567,21 @@ private function prepareInterviewsData(Entity\Anr $anr): array
563567
return $result;
564568
}
565569

570+
private function prepareReassessmentTriggersData(Entity\Anr $anr): array
571+
{
572+
$result = [];
573+
foreach ($this->reassessmentTriggerTable->findByAnrOrderedByPosition($anr) as $reassessmentTrigger) {
574+
$result[] = [
575+
'triggerType' => $reassessmentTrigger->getTriggerType(),
576+
'description' => $reassessmentTrigger->getDescription(),
577+
'isActive' => $reassessmentTrigger->isActive(),
578+
'position' => $reassessmentTrigger->getPosition(),
579+
];
580+
}
581+
582+
return $result;
583+
}
584+
566585
private function prepareGdprRecordsData(Entity\Anr $anr): array
567586
{
568587
$result = [];

src/Import/Service/InstanceImportService.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,15 @@ public function __construct(
3939
private Processor\OperationalRiskImportProcessor $operationalRiskImportProcessor,
4040
private Processor\RecommendationImportProcessor $recommendationImportProcessor,
4141
private Processor\ObjectCategoryImportProcessor $objectCategoryImportProcessor,
42-
private Processor\ObjectImportProcessor $objectImportProcessor,
4342
private Processor\AnrInstanceMetadataFieldImportProcessor $anrInstanceMetadataFieldImportProcessor,
4443
private Processor\AnrMethodStepImportProcessor $anrMethodStepImportProcessor,
4544
private Processor\InstanceImportProcessor $instanceImportProcessor,
46-
private Processor\InstanceConsequenceImportProcessor $instanceConsequenceImportProcessor,
4745
private Processor\ScaleImportProcessor $scaleImportProcessor,
4846
private Processor\OperationalRiskScaleImportProcessor $operationalRiskScaleImportProcessor,
49-
private Processor\OperationalInstanceRiskImportProcessor $operationalInstanceRiskImportProcessor,
5047
private Processor\SoaImportProcessor $soaImportProcessor,
5148
private ImportCacheHelper $importCacheHelper,
5249
private Service\AnrRecordService $anrRecordService,
50+
private Service\ReassessmentTriggerService $reassessmentTriggerService,
5351
private Table\InstanceTable $instanceTable,
5452
private Table\AnrTable $anrTable,
5553
) {
@@ -172,6 +170,10 @@ private function processAnrImport(
172170
/* Process the interviews' data. */
173171
$this->anrMethodStepImportProcessor->processInterviewsData($anr, $data['interviews']);
174172
}
173+
if (!empty($data['reassessmentTriggers'])) {
174+
$this->reassessmentTriggerService
175+
->processForImport($anr, $data['reassessmentTriggers'], $importMode === 'merge');
176+
}
175177
if (!empty($data['knowledgeBase'])) {
176178
/* Process the Knowledge Base data. */
177179
$this->processKnowledgeBaseData($anr, $data['knowledgeBase']);

0 commit comments

Comments
 (0)