Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
fix: Prevent previously uploaded evidence from being deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
wadedvsa committed Apr 19, 2024
1 parent 79e218b commit 6f9ba5e
Showing 1 changed file with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Common\RefData;
use Common\Service\Helper\FileUploadHelperService;
use Common\Service\Helper\FormHelperService;
use DateTimeImmutable;
use DateTimeInterface;
use Dvsa\Olcs\Transfer\Query\Application\UploadEvidence;
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
use Olcs\Controller\Lva\Traits\ApplicationControllerTrait;
Expand Down Expand Up @@ -38,6 +40,7 @@ abstract class AbstractUploadEvidenceController extends AbstractController

protected FormHelperService $formHelper;
protected FileUploadHelperService $uploadHelper;
protected string $startTime;

/**
* @param NiTextTranslation $niTextTranslationUtil
Expand All @@ -53,6 +56,7 @@ public function __construct(
) {
$this->formHelper = $formHelper;
$this->uploadHelper = $uploadHelper;
$this->startTime = (new DateTimeImmutable())->format(DateTimeInterface::ATOM);

parent::__construct(
$niTextTranslationUtil,
Expand All @@ -69,6 +73,7 @@ public function __construct(
public function indexAction()
{
$form = $this->getForm();
$form->get('correlationId')->setValue($this->startTime);

$request = $this->getRequest();
if ($request->isPost() && $request->getPost('saveAndContinue') !== null) {
Expand Down Expand Up @@ -165,11 +170,14 @@ private function getForm()
*/
public function operatingCentreLoadFileUpload()
{
$startDateTime = new DateTimeImmutable($this->getRequest()->getPost('correlationId', $this->startTime));
$data = $this->getData();
foreach ($data['operatingCentres'] as $aocData) {
if ($aocData['operatingCentre']['id'] === $this->operatingCentreId) {
$documents = $aocData['operatingCentre']['adDocuments'];
return array_filter($documents, fn($document) => $document['isPostSubmissionUpload']);
return array_filter(
$aocData['operatingCentre']['adDocuments'],
fn($document) => $document['isPostSubmissionUpload'] && (new DateTimeImmutable($document['createdOn'])) > $startDateTime,
);
}
}

Expand All @@ -193,7 +201,7 @@ public function operatingCentreProcessFileUpload($file)
'licence' => $this->getLicenceId(),
'application' => $this->getIdentifier(),
'operatingCentre' => $this->operatingCentreId,
'isPostSubmissionUpload' => true
'isPostSubmissionUpload' => true,
];

$this->uploadFile($file, $data);
Expand Down Expand Up @@ -278,7 +286,7 @@ public function financialEvidenceProcessFileUpload($file)
'subCategory' => \Common\Category::DOC_SUB_CATEGORY_FINANCIAL_EVIDENCE_DIGITAL,
'licence' => $applicationData['licence']['id'],
'isExternal' => true,
'isPostSubmissionUpload' => true
'isPostSubmissionUpload' => true,
];

$this->uploadFile($file, $data);
Expand All @@ -290,7 +298,11 @@ public function financialEvidenceProcessFileUpload($file)
/** Get list of financial evidence documents */
public function financialEvidenceLoadFileUpload(): array
{
return array_filter($this->getFinancialEvidenceData()['documents'], fn($doc) => $doc['isPostSubmissionUpload']);
$startDateTime = new DateTimeImmutable($this->getRequest()->getPost('correlationId', $this->startTime));
return array_filter(
$this->getFinancialEvidenceData()['documents'],
fn($doc) => $doc['isPostSubmissionUpload'] && (new DateTimeImmutable($doc['createdOn'])) > $startDateTime,
);
}

/**
Expand All @@ -310,7 +322,7 @@ public function supportingEvidenceProcessFileUpload($file)
'subCategory' => \Common\Category::DOC_SUB_CATEGORY_SUPPORTING_EVIDENCE,
'licence' => $applicationData['licence']['id'],
'isExternal' => true,
'isPostSubmissionUpload' => true
'isPostSubmissionUpload' => true,
];

$this->uploadFile($file, $data);
Expand All @@ -322,7 +334,11 @@ public function supportingEvidenceProcessFileUpload($file)
/** Get list of supporting evidence documents */
public function supportingEvidenceLoadFileUpload(): array
{
return array_filter($this->getData()['supportingEvidence'], fn($doc) => $doc['isPostSubmissionUpload']);
$startDateTime = new DateTimeImmutable($this->getRequest()->getPost('correlationId', $this->startTime));
return array_filter(
$this->getData()['supportingEvidence'],
fn($doc) => $doc['isPostSubmissionUpload'] && (new DateTimeImmutable($doc['createdOn'])) > $startDateTime,
);
}

/**
Expand Down

0 comments on commit 6f9ba5e

Please sign in to comment.