Skip to content

Commit

Permalink
Updated the deliveries, cartography services, controllers methods and…
Browse files Browse the repository at this point in the history
… declarations, other services and entities.
  • Loading branch information
ruslanbaidan committed Feb 11, 2024
1 parent f651822 commit a7cd852
Show file tree
Hide file tree
Showing 116 changed files with 3,900 additions and 6,818 deletions.
192 changes: 90 additions & 102 deletions config/module.config.php

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions migrations/db/20230901112005_fix_positions_cleanup_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ public function change()
->removeColumn('token_import')
->update();

$this->table('deliveries')
->renameColumn('resp_smile', 'responsible_manager')
->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
36 changes: 15 additions & 21 deletions src/Controller/ApiAnrAbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
namespace Monarc\FrontOffice\Controller;

use Monarc\Core\Controller\AbstractController;
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\Core\Exception\Exception;
use Ramsey\Uuid\Uuid;
use Laminas\View\Model\JsonModel;
use function in_array;

/**
Expand All @@ -19,9 +19,8 @@
*/
abstract class ApiAnrAbstractController extends AbstractController
{
/**
* @inheritdoc
*/
use ControllerRequestResponseHandlerTrait;

public function getList()
{
$page = $this->params()->fromQuery('page');
Expand Down Expand Up @@ -50,9 +49,9 @@ public function getList()
}
}

return new JsonModel([
return $this->getPreparedJsonResponse([
'count' => $service->getFilteredCount($filter, $filterAnd),
$this->name => $entities
$this->name => $entities,
]);
}

Expand Down Expand Up @@ -84,7 +83,7 @@ public function get($id)
$this->formatDependencies($entity, $this->dependencies);
}

return new JsonModel($entity);
return $this->getPreparedJsonResponse($entity);
}

/**
Expand Down Expand Up @@ -130,8 +129,7 @@ public function create($data)
$created_objects[] = $id;
}

return new JsonModel([
'status' => 'ok',
return $this->getSuccessfulJsonResponse([
'id' => count($created_objects) == 1 ? $created_objects[0] : $created_objects,
]);
}
Expand Down Expand Up @@ -159,7 +157,7 @@ public function update($id, $data)

$this->getService()->update($id, $data);

return new JsonModel(['status' => 'ok']);
return $this->getSuccessfulJsonResponse();
}

/**
Expand All @@ -186,7 +184,7 @@ public function patch($id, $data)

$this->getService()->patch($id, $data);

return new JsonModel(['status' => 'ok']);
return $this->getSuccessfulJsonResponse();
}

/**
Expand All @@ -206,11 +204,9 @@ public function delete($id)
$id = ['uuid' => $id, 'anr' => $anrId];
}

if ($this->getService()->deleteFromAnr($id, $anrId)) {
return new JsonModel(['status' => 'ok']);
}
$this->getService()->deleteFromAnr($id, $anrId);

return new JsonModel(['status' => 'ok']); // Todo : may be add error message
return $this->getSuccessfulJsonResponse();
}

/**
Expand All @@ -223,19 +219,17 @@ public function deleteList($data)
$class = $this->getService()->get('entity');
$entity = new $class();
$ids = $class->getDbAdapter()->getClassMetadata(get_class($entity))->getIdentifierFieldNames();
if (count($ids) > 1) {
if (\count($ids) > 1) {
foreach ($data as $key => $value) {
if (count($ids) > 1 && in_array('anr', $ids) && in_array('uuid', $ids) && !is_array($value)) {
if (in_array('anr', $ids) && in_array('uuid', $ids) && !is_array($value)) {
$data[$key] = ['uuid' => $value, 'anr' => $anrId];
}
}
}

if ($this->getService()->deleteListFromAnr($data, $anrId)) {
return new JsonModel(['status' => 'ok']);
}
$this->getService()->deleteListFromAnr($data, $anrId);

return new JsonModel(['status' => 'ok']); // Todo: may be add error message
return $this->getSuccessfulJsonResponse();
}

/**
Expand Down
17 changes: 4 additions & 13 deletions src/Controller/ApiAnrAmvsController.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php declare(strict_types=1);
/**
* @link https://github.com/monarc-project for the canonical source repository
* @copyright Copyright (c) 2016-2023 Luxembourg House of Cybersecurity LHC.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
*/

Expand All @@ -18,20 +18,11 @@ class ApiAnrAmvsController extends AbstractRestfulControllerRequestHandler
{
use ControllerRequestResponseHandlerTrait;

private AnrAmvService $anrAmvService;

private GetAmvsInputFormatter $getAmvsInputFormatter;

private PostAmvDataInputValidator $postAmvDataInputValidator;

public function __construct(
AnrAmvService $anrAmvService,
GetAmvsInputFormatter $getAmvsInputFormatter,
PostAmvDataInputValidator $postAmvDataInputValidator
private AnrAmvService $anrAmvService,
private GetAmvsInputFormatter $getAmvsInputFormatter,
private PostAmvDataInputValidator $postAmvDataInputValidator
) {
$this->anrAmvService = $anrAmvService;
$this->getAmvsInputFormatter = $getAmvsInputFormatter;
$this->postAmvDataInputValidator = $postAmvDataInputValidator;
}

public function getList()
Expand Down
91 changes: 27 additions & 64 deletions src/Controller/ApiAnrDeliverableController.php
Original file line number Diff line number Diff line change
@@ -1,98 +1,61 @@
<?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 Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\Core\Exception\Exception;
use Monarc\FrontOffice\Model\Entity\Anr;
use Monarc\FrontOffice\Service\DeliverableGenerationService;
use Laminas\Mvc\Controller\AbstractRestfulController;
use Laminas\View\Model\JsonModel;

/**
* Api Anr Deliverable Controller
*
* Class ApiAnrDeliverableController
* @package Monarc\FrontOffice\Controller
*/
class ApiAnrDeliverableController extends AbstractRestfulController
class ApiAnrDeliverableController extends AbstractRestfulControllerRequestHandler
{
/** @var DeliverableGenerationService */
private $deliverableGenerationService;
use ControllerRequestResponseHandlerTrait;

public function __construct(DeliverableGenerationService $deliverableGenerationService)
public function __construct(private DeliverableGenerationService $deliverableGenerationService)
{
$this->deliverableGenerationService = $deliverableGenerationService;
}

public function create($data)
{
$anrId = (int)$this->params()->fromRoute('anrid');
$data['anr'] = $anrId;

$typeDoc = $data['typedoc'];
$typeDoc = (int)$data['typedoc'];
if (empty($typeDoc)) {
throw new Exception('Document type missing', 412);
}

$params = [
'txt' => [
'VERSION' => htmlspecialchars($data['version']),
'STATE' => $data['status'] == 0 ? 'Draft' : 'Final',
'CLASSIFICATION' => htmlspecialchars($data['classification']),
'COMPANY' => htmlspecialchars($this->deliverableGenerationService->getCompanyName()),
'DOCUMENT' => htmlspecialchars($data['docname']),
'DATE' => date('d/m/Y'),
'CLIENT' => htmlspecialchars($data['managers']),
'SMILE' => htmlspecialchars($data['consultants']),
'SUMMARY_EVAL_RISK' => $data['summaryEvalRisk'] ?? '',
],
];
/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');

// Generate the DOCX file
$filePath = $this->deliverableGenerationService
->generateDeliverableWithValues($anrId, $typeDoc, $params, $data);
$filePath = $this->deliverableGenerationService->generateDeliverableWithValues($anr, $typeDoc, $data);
if (!file_exists($filePath)) {
throw new Exception('Generated file is not found: ' . $filePath);
}

if (file_exists($filePath)) {
$response = $this->getResponse();
$response->setContent(file_get_contents($filePath));
$response = $this->getResponse();
$response->setContent(file_get_contents($filePath));

unlink($filePath);
unlink($filePath);

$headers = $response->getHeaders();
$headers->clearHeaders()
->addHeaderLine('Content-Type', 'text/plain; charset=utf-8')
->addHeaderLine('Content-Disposition', 'attachment; filename="deliverable.docx"');
$headers = $response->getHeaders();
$headers->clearHeaders()
->addHeaderLine('Content-Type', 'text/plain; charset=utf-8')
->addHeaderLine('Content-Disposition', 'attachment; filename="deliverable.docx"');

return $this->response;
}

throw new Exception('Generated file not found: ' . $filePath);
return $this->response;
}

public function get($id)
{
return new JsonModel([
'delivery' => $this->deliverableGenerationService->getLastDeliveries(
(int)$this->params()->fromRoute('anrid'),
$id
),
]);
}
/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');

/**
* @inheritdoc
*/
public function getList()
{
return new JsonModel([
'models' => $this->deliverableGenerationService->getDeliveryModels(),
'delivery' => $this->deliverableGenerationService->getLastDeliveries(
(int)$this->params()->fromRoute('anrid')
),
return $this->getPreparedJsonResponse([
'delivery' => $this->deliverableGenerationService->getLastDelivery($anr, (int)$id),
]);
}
}
21 changes: 12 additions & 9 deletions src/Controller/ApiAnrInstancesConsequencesController.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
<?php declare(strict_types=1);
/**
* @link https://github.com/monarc-project for the canonical source repository
* @copyright Copyright (c) 2016-2023 Luxembourg House of Cybersecurity LHC.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\Core\Validator\InputValidator\InstanceConsequence\PatchConsequenceDataInputValidator;
use Monarc\FrontOffice\Model\Entity\Anr;
use Monarc\FrontOffice\Service\AnrInstanceConsequenceService;

class ApiAnrInstancesConsequencesController extends AbstractRestfulControllerRequestHandler
{
use ControllerRequestResponseHandlerTrait;

private AnrInstanceConsequenceService $anrInstanceConsequenceService;

public function __construct(AnrInstanceConsequenceService $anrInstanceConsequenceService)
{
$this->anrInstanceConsequenceService = $anrInstanceConsequenceService;
public function __construct(
private AnrInstanceConsequenceService $anrInstanceConsequenceService,
private PatchConsequenceDataInputValidator $patchConsequenceDataInputValidator
) {
}

/**
* The patch endpoint is called only when we hide/show a consequence.
* The patch endpoint is called only when hide/show consequence action is performed.
* Possible data params: $data['isHidden'] = 0|1
*/
public function patch($id, $data)
{
/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');

$this->anrInstanceConsequenceService->patchConsequence($anr, $id, $data);
$this->validatePostParams($this->patchConsequenceDataInputValidator, $data);

$this->anrInstanceConsequenceService
->patchConsequence($anr, $id, $this->patchConsequenceDataInputValidator->getValidData());

return $this->getSuccessfulJsonResponse();
}
Expand Down
Loading

0 comments on commit a7cd852

Please sign in to comment.