Skip to content

Commit

Permalink
Refactroed the Referential, Measure, SoaCategory functionality, other…
Browse files Browse the repository at this point in the history
… improvements.
  • Loading branch information
ruslanbaidan committed Apr 20, 2024
1 parent dbfec07 commit fcd4831
Show file tree
Hide file tree
Showing 66 changed files with 1,721 additions and 1,223 deletions.
49 changes: 19 additions & 30 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiAdminUsersRolesController::class),
'controller' => Controller\ApiAdminUsersRolesController::class,
],
],
],
Expand All @@ -67,8 +66,7 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiAdminUsersController::class),
'controller' => Controller\ApiAdminUsersController::class,
],
],
],
Expand All @@ -81,8 +79,7 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiAdminUsersController::class),
'controller' => Controller\ApiAdminUsersController::class,
'action' => 'resetPassword',
],
],
Expand All @@ -109,8 +106,7 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiModelsController::class),
'controller' => Controller\ApiModelsController::class,
],
],
],
Expand All @@ -120,7 +116,7 @@
'options' => [
'route' => '/api/referentials',
'defaults' => [
'controller' => Controller\ApiReferentialsController::class,
'controller' => Controller\ApiCoreReferentialsController::class,
],
],
],
Expand Down Expand Up @@ -165,8 +161,7 @@
'route' => '/api/admin/passwords',
'constraints' => [],
'defaults' => [
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiAdminPasswordsController::class),
'controller' => Controller\ApiAdminPasswordsController::class,
],
],
],
Expand Down Expand Up @@ -1382,7 +1377,7 @@
Controller\ApiAnrController::class => AutowireFactory::class,
Controller\ApiConfigController::class => AutowireFactory::class,
Controller\ApiClientsController::class => AutowireFactory::class,
Controller\ApiReferentialsController::class => AutowireFactory::class,
Controller\ApiCoreReferentialsController::class => AutowireFactory::class,
Controller\ApiUserPasswordController::class => AutowireFactory::class,
Controller\ApiUserTwoFAController::class => AutowireFactory::class,
Controller\ApiUserRecoveryCodesController::class => AutowireFactory::class,
Expand Down Expand Up @@ -1457,20 +1452,14 @@
DbCli::class => Service\Model\DbCliFactory::class,

DeprecatedTable\InterviewTable::class => AutowireFactory::class,
DeprecatedTable\MeasureTable::class => AutowireFactory::class,
DeprecatedTable\MeasureMeasureTable::class => AutowireFactory::class,
DeprecatedTable\RolfRiskTable::class => AutowireFactory::class,
DeprecatedTable\RolfTagTable::class => AutowireFactory::class,
DeprecatedTable\RecordActorTable::class => AutowireFactory::class,
DeprecatedTable\RecordDataCategoryTable::class => AutowireFactory::class,
DeprecatedTable\RecordInternationalTransferTable::class => AutowireFactory::class,
DeprecatedTable\RecordPersonalDataTable::class => AutowireFactory::class,
DeprecatedTable\RecordProcessorTable::class => AutowireFactory::class,
DeprecatedTable\RecordRecipientTable::class => AutowireFactory::class,
DeprecatedTable\RecordTable::class => AutowireFactory::class,
DeprecatedTable\ReferentialTable::class => AutowireFactory::class,
DeprecatedTable\SoaTable::class => AutowireFactory::class,
DeprecatedTable\SoaCategoryTable::class => AutowireFactory::class,
DeprecatedTable\QuestionTable::class => AutowireFactory::class,
DeprecatedTable\QuestionChoiceTable::class => AutowireFactory::class,
Table\AnrTable::class => ClientEntityManagerFactory::class,
Expand All @@ -1489,6 +1478,8 @@
Table\ScaleImpactTypeTable::class => ClientEntityManagerFactory::class,
Table\ClientTable::class => ClientEntityManagerFactory::class,
Table\MonarcObjectTable::class => ClientEntityManagerFactory::class,
Table\MeasureTable::class => ClientEntityManagerFactory::class,
Table\MeasureMeasureTable::class => ClientEntityManagerFactory::class,
Table\ObjectCategoryTable::class => ClientEntityManagerFactory::class,
Table\ObjectObjectTable::class => ClientEntityManagerFactory::class,
Table\OperationalRiskScaleTable::class => ClientEntityManagerFactory::class,
Expand All @@ -1499,6 +1490,10 @@
Table\RecommendationHistoryTable::class => ClientEntityManagerFactory::class,
Table\RecommendationRiskTable::class => ClientEntityManagerFactory::class,
Table\RecommendationSetTable::class => ClientEntityManagerFactory::class,
Table\RolfRiskTable::class => ClientEntityManagerFactory::class,
Table\RolfTagTable::class => ClientEntityManagerFactory::class,
Table\ReferentialTable::class => ClientEntityManagerFactory::class,
Table\SoaCategoryTable::class => ClientEntityManagerFactory::class,
Table\SnapshotTable::class => ClientEntityManagerFactory::class,
Table\SoaScaleCommentTable::class => ClientEntityManagerFactory::class,
Table\ThemeTable::class => ClientEntityManagerFactory::class,
Expand All @@ -1519,20 +1514,12 @@
Entity\RecordProcessor::class => ModelFactory\RecordProcessorServiceModelEntity::class,
Entity\RecordRecipient::class => ModelFactory\RecordRecipientServiceModelEntity::class,
Entity\Record::class => ModelFactory\RecordServiceModelEntity::class,
Entity\Referential::class => ModelFactory\ReferentialServiceModelEntity::class,
Entity\Measure::class => ModelFactory\MeasureServiceModelEntity::class,
Entity\MeasureMeasure::class => ModelFactory\MeasureMeasureServiceModelEntity::class,
Entity\RolfRisk::class => ModelFactory\RolfRiskServiceModelEntity::class,
Entity\RolfTag::class => ModelFactory\RolfTagServiceModelEntity::class,
Entity\Soa::class => ModelFactory\SoaServiceModelEntity::class,
Entity\SoaCategory::class => ModelFactory\SoaCategoryServiceModelEntity::class,
Entity\Question::class => ModelFactory\QuestionServiceModelEntity::class,
Entity\QuestionChoice::class => ModelFactory\QuestionChoiceServiceModelEntity::class,

// TODO: replace to autowiring.
Service\AnrInterviewService::class => Service\AnrInterviewServiceFactory::class,
Service\AnrMeasureService::class => Service\AnrMeasureServiceFactory::class,
Service\AnrMeasureMeasureService::class => Service\AnrMeasureMeasureServiceFactory::class,
Service\AnrRecordActorService::class => Service\AnrRecordActorServiceFactory::class,
Service\AnrRecordDataCategoryService::class => Service\AnrRecordDataCategoryServiceFactory::class,
Service\AnrRecordInternationalTransferService::class
Expand All @@ -1541,13 +1528,15 @@
Service\AnrRecordProcessorService::class => Service\AnrRecordProcessorServiceFactory::class,
Service\AnrRecordRecipientService::class => Service\AnrRecordRecipientServiceFactory::class,
Service\AnrRecordService::class => Service\AnrRecordServiceFactory::class,
Service\AnrReferentialService::class => Service\AnrReferentialServiceFactory::class,
Service\SoaService::class => Service\SoaServiceFactory::class,
Service\SoaCategoryService::class => Service\SoaCategoryServiceFactory::class,
Service\AnrQuestionService::class => Service\AnrQuestionServiceFactory::class,
Service\AnrQuestionChoiceService::class => Service\AnrQuestionChoiceServiceFactory::class,
Service\AnrRolfTagService::class => Service\AnrRolfTagServiceFactory::class,
Service\AnrRolfRiskService::class => Service\AnrRolfRiskServiceFactory::class,
Service\AnrMeasureService::class => AutowireFactory::class,
Service\AnrMeasureMeasureService::class => AutowireFactory::class,
Service\AnrReferentialService::class => AutowireFactory::class,
Service\SoaCategoryService::class => AutowireFactory::class,
Service\AnrRolfTagService::class => AutowireFactory::class,
Service\AnrRolfRiskService::class => AutowireFactory::class,
Service\AnrRecommendationService::class => AutowireFactory::class,
Service\AnrRecommendationHistoryService::class => AutowireFactory::class,
Service\AnrRecommendationRiskService::class => AutowireFactory::class,
Expand Down
61 changes: 61 additions & 0 deletions migrations/db/20230901112005_fix_positions_cleanup_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,51 @@ public function change()
$this->execute('UPDATE measures SET soacategory_id = ' . $soaCategoryIds[$anrId]
. ' WHERE uuid = "' . $measureData['uuid'] . '" and anr_id = ' . $anrId);
}
/* Correct MeasuresMeasures table structure. */
$this->table('measures_measures')
->addColumn('id', 'integer', ['signed' => false, 'after' => MysqlAdapter::FIRST])
->renameColumn('father_id', 'master_measure_id')
->renameColumn('child_id', 'linked_measure_id')
->dropForeignKey(['master_measure_id', 'linked_measure_id', 'anr_id'])
->removeColumn('creator')
->removeColumn('created_at')
->removeColumn('updater')
->removeColumn('updated_at')
->update();
$this->execute('SET @a = 0; UPDATE measures_measures SET id = @a := @a + 1 ORDER BY anr_id;');
$this->table('measures_measures')
->changePrimaryKey(['id'])
->addIndex(['master_measure_id', 'linked_measure_id', 'anr_id'], ['unique' => true])
->update();
$this->table('measures_measures')
->changeColumn('id', 'integer', ['identity' => true, 'signed' => false])
->update();
/* Remove unlinked measures links to measures. */
$this->execute('DELETE FROM measures_measures WHERE anr_id NOT IN (SELECT id FROM anrs);');
$voidMeasuresQuery = $this->query('
SELECT id FROM measures_measures WHERE CONCAT(master_measure_id, anr_id) NOT IN
(SELECT CONCAT(uuid, anr_id) FROM measures) OR CONCAT(linked_measure_id, anr_id)
NOT IN (SELECT CONCAT(uuid, anr_id) FROM measures)
');
$voidMeasuresIds = [];
foreach ($voidMeasuresQuery->fetchAll() as $voidMeasureData) {
$voidMeasuresIds[] = $voidMeasureData['id'];
}
$this->execute('DELETE FROM measures_measures WHERE id IN (' . implode(',', $voidMeasuresIds) . ');');
$this->table('measures_measures')
->addForeignKey(['anr_id'], 'anrs', ['id'], ['delete' => 'CASCADE'])
->addForeignKey(
['master_measure_id', 'anr_id'],
'measures',
['uuid', 'anr_id'],
['delete' => 'CASCADE', 'update' => 'RESTRICT']
)->addForeignKey(
['linked_measure_id', 'anr_id'],
'measures',
['uuid', 'anr_id'],
['delete' => 'CASCADE', 'update' => 'RESTRICT']
)->update();
$this->table('measures')->addForeignKey(['anr_id'], 'anrs', ['id'], ['delete' => 'CASCADE'])->update();

/* Rename column of owner_id to risk_owner_id. */
$this->table('instances_risks')->renameColumn('owner_id', 'risk_owner_id')->update();
Expand Down Expand Up @@ -368,6 +413,22 @@ public function change()
->addIndex(['anr_id', 'instance_risk_op_id', 'operational_risk_scale_type_id'], ['unique' => false])
->update();

/* Note: Temporary change fields types to avoid setting values from the code. Later will be dropped. */
$this->table('operational_risks_scales_types')
->changeColumn('label_translation_key', 'string', ['null' => false, 'default' => '', 'limit' => 255])
->update();
$this->table('operational_risks_scales_comments')
->changeColumn('comment_translation_key', 'string', ['null' => false, 'default' => '', 'limit' => 255])
->update();

/* Cleanup the table. */
$this->table('rolf_risks_tags')
->removeColumn('creator')
->removeColumn('created_at')
->removeColumn('updater')
->removeColumn('updated_at')
->update();

/* TODO: Should be added to the next release migration, to perform this release in a safe mode.
$this->table('anr_instance_metadata_fields')->removeColumn('label_translation_key')->update();
$this->table('instances_metadata')->removeColumn('comment_translation_key')->update();
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/ApiAdminPasswordsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

namespace Monarc\FrontOffice\Controller;

use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
use Laminas\Mvc\Controller\AbstractRestfulController;
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\Core\Exception\Exception;
use Monarc\Core\Service\PasswordService;

class ApiAdminPasswordsController extends AbstractRestfulControllerRequestHandler
class ApiAdminPasswordsController extends AbstractRestfulController
{
use ControllerRequestResponseHandlerTrait;

Expand All @@ -32,7 +32,7 @@ public function create($data)
if (!empty($data['email']) && empty($data['password'])) {
try {
$this->passwordService->passwordForgotten($data['email']);
} catch (\Exception $e) {
} catch (\Exception) {
// Ignore the \Exception to avoid the data leak.
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/ApiAdminUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

namespace Monarc\FrontOffice\Controller;

use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
use Laminas\Mvc\Controller\AbstractRestfulController;
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\Core\InputFormatter\User\GetUsersInputFormatter;
use Monarc\Core\Service\PasswordService;
use Monarc\FrontOffice\Validator\InputValidator\User\PostUserDataInputValidator;
use Monarc\FrontOffice\Service\UserService;

class ApiAdminUsersController extends AbstractRestfulControllerRequestHandler
class ApiAdminUsersController extends AbstractRestfulController
{
use ControllerRequestResponseHandlerTrait;

Expand Down
4 changes: 2 additions & 2 deletions src/Controller/ApiAdminUsersRolesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

namespace Monarc\FrontOffice\Controller;

use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
use Laminas\Mvc\Controller\AbstractRestfulController;
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\Core\Exception;
use Monarc\FrontOffice\Service\UserRoleService;

class ApiAdminUsersRolesController extends AbstractRestfulControllerRequestHandler
class ApiAdminUsersRolesController extends AbstractRestfulController
{
use ControllerRequestResponseHandlerTrait;

Expand Down
29 changes: 18 additions & 11 deletions src/Controller/ApiAnrAssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,26 @@ public function create($data)
$anr = $this->getRequest()->getAttribute('anr');

$isBatchData = $this->isBatchData($data);
$this->validatePostParams($this->postAssetDataInputValidator->setAnr($anr), $data, $isBatchData);

$assetsUuids = [];
$validatedData = $isBatchData
? $this->postAssetDataInputValidator->getValidDataSets()
: [$this->postAssetDataInputValidator->getValidData()];
$setsNum = \count($validatedData) - 1;
foreach ($validatedData as $setNum => $validatedDataRow) {
$assetsUuids[] = $this->anrAssetService->create($anr, $validatedDataRow, $setNum === $setsNum)->getUuid();
$this->validatePostParams(
$this->postAssetDataInputValidator->setIncludeFilter(['anr' => $anr]),
$data,
$isBatchData
);

if ($isBatchData) {
return $this->getSuccessfulJsonResponse([
'id' => $this->anrAssetService->createList(
$anr,
$this->postAssetDataInputValidator->getValidDataSets()
),
]);
}

return $this->getSuccessfulJsonResponse([
'id' => \count($assetsUuids) === 1 && !$isBatchData ? current($assetsUuids) : $assetsUuids,
'id' => $this->anrAssetService->create(
$anr,
$this->postAssetDataInputValidator->getValidData()
)->getUuid(),
]);
}

Expand All @@ -80,7 +87,7 @@ public function update($id, $data)
/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');
$this->validatePostParams(
$this->postAssetDataInputValidator->setExcludeFilter(['uuid' => $id])->setAnr($anr),
$this->postAssetDataInputValidator->setIncludeFilter(['anr' => $anr])->setExcludeFilter(['uuid' => $id]),
$data
);

Expand Down
Loading

0 comments on commit fcd4831

Please sign in to comment.