diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 90c3e880ab..5fd070aab7 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -45,6 +45,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Cache\CacheEntryRemovedEvent; use OCP\Files\Events\Node\BeforeNodeDeletedEvent; use OCP\User\Events\UserDeletedEvent; @@ -75,6 +76,7 @@ public function register(IRegistrationContext $context): void { $context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class); $context->registerEventListener(BeforeNodeDeletedEvent::class, BeforeNodeDeletedListener::class); + $context->registerEventListener(CacheEntryRemovedEvent::class, BeforeNodeDeletedListener::class); $context->registerEventListener(SignedEvent::class, SignedListener::class); // Files newFile listener diff --git a/lib/Listener/BeforeNodeDeletedListener.php b/lib/Listener/BeforeNodeDeletedListener.php index 01d294b1cd..dd50d28b68 100644 --- a/lib/Listener/BeforeNodeDeletedListener.php +++ b/lib/Listener/BeforeNodeDeletedListener.php @@ -30,12 +30,13 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\Files\Cache\CacheEntryRemovedEvent; use OCP\Files\Events\Node\BeforeNodeDeletedEvent; use OCP\Files\File; use OCP\IDBConnection; /** - * @template-implements IEventListener + * @template-implements IEventListener */ class BeforeNodeDeletedListener implements IEventListener { public function __construct( @@ -46,17 +47,25 @@ public function __construct( } public function handle(Event $event): void { - if (!$event instanceof BeforeNodeDeletedEvent) { + if ($event instanceof BeforeNodeDeletedEvent) { + $node = $event->getNode(); + if (!$node instanceof File) { + return; + } + if (!in_array($node->getMimeType(), ValidateHelper::VALID_MIMETIPE)) { + return; + } + $nodeId = $node->getId(); + $this->delete($nodeId); return; } - $node = $event->getNode(); - if (!$node instanceof File) { - return; - } - if (!in_array($node->getMimeType(), ValidateHelper::VALID_MIMETIPE)) { - return; + if ($event instanceof CacheEntryRemovedEvent) { + $this->delete($event->getFileId()); } - $nodeId = $node->getId(); + return; + } + + private function delete(int $nodeId): void { $type = $this->fileMapper->getFileType($nodeId); if ($type === 'not_libresign_file') { return; @@ -69,24 +78,16 @@ public function handle(Event $event): void { break; case 'file': $libresignFile = $this->fileMapper->getByFileId($nodeId); - if ($libresignFile->getStatus() === $libresignFile::STATUS_SIGNED) { - $libresignFile->setNodeId(null); - $this->fileMapper->update($libresignFile); - break; - } $this->requestSignatureService->deleteRequestSignature(['file' => ['fileId' => $nodeId]]); + $this->fileMapper->delete($libresignFile); break; case 'user_element': case 'file_element': - $this->deleteByType($nodeId, $type); + $field = $type === 'file' ? 'node_id' : 'file_id'; + $qb = $this->db->getQueryBuilder(); + $qb->delete('libresign_' . $type) + ->where($qb->expr()->eq($field, $qb->createNamedParameter($nodeId, IQueryBuilder::PARAM_INT))) + ->executeStatement(); } } - - private function deleteByType(int $nodeId, string $type): void { - $field = $type === 'file' ? 'node_id' : 'file_id'; - $qb = $this->db->getQueryBuilder(); - $qb->delete('libresign_' . $type) - ->where($qb->expr()->eq($field, $qb->createNamedParameter($nodeId, IQueryBuilder::PARAM_INT))) - ->executeStatement(); - } } diff --git a/src/Components/Request/VisibleElements.vue b/src/Components/Request/VisibleElements.vue index 500d4be5f9..3a0462411c 100644 --- a/src/Components/Request/VisibleElements.vue +++ b/src/Components/Request/VisibleElements.vue @@ -256,8 +256,11 @@ export default { })) }, async goToSign() { + // after save, the document is no more acessible by this way, + // this is the reason to retain the UUID before save action + const uuid = this.document.settings.signerFileUuid if (await this.save()) { - const route = this.$router.resolve({ name: 'SignPDF', params: { uuid: this.document.settings.signerFileUuid } }) + const route = this.$router.resolve({ name: 'SignPDF', params: { uuid } }) window.location.href = route.href } }, diff --git a/tests/Unit/Controller/AEnvironmentPageAwareControllerTest.php b/tests/Unit/Controller/AEnvironmentPageAwareControllerTest.php index 7823bd05d6..35888e53e4 100644 --- a/tests/Unit/Controller/AEnvironmentPageAwareControllerTest.php +++ b/tests/Unit/Controller/AEnvironmentPageAwareControllerTest.php @@ -113,10 +113,9 @@ public function testLoadFileUuidWhenFileNotFound(): void { $this->getExpectedExceptionCode(404); $this->expectExceptionMessage(json_encode([ 'action' => 2000, - 'errors' => ['File not found'], + 'errors' => ['Invalid UUID'], ])); - $signers = $this->getSignersFromFileId($file->getId()); - $this->controller->loadNextcloudFileFromSignRequestUuid($signers[0]->getUuid()); + $this->controller->validateSignRequestUuid($file->getUuid()); } }