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 (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
wadedvsa authored Apr 22, 2024
1 parent d312f9d commit 761fe35
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 @@ -36,6 +38,7 @@ abstract class AbstractUploadEvidenceController extends AbstractController
*/
private $application;
protected FileUploadHelperService $uploadHelper;
protected string $startTime;

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

parent::__construct(
$niTextTranslationUtil,
Expand All @@ -66,6 +70,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 @@ -162,11 +167,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 @@ -190,7 +198,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 @@ -275,7 +283,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 @@ -287,7 +295,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 @@ -307,7 +319,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 @@ -319,7 +331,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 761fe35

Please sign in to comment.