diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index 94872e4e24..50513760e4 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -80,7 +80,7 @@ jobs: with: php-version: ${{ matrix.php-versions }} tools: phpunit - extensions: mbstring, iconv, fileinfo, intl, imagick, sqlite, pdo_sqlite, mysql, pdo_mysql, pgsql, pdo_pgsql, + extensions: mbstring, iconv, fileinfo, intl, sqlite, pdo_sqlite, mysql, pdo_mysql, pgsql, pdo_pgsql, coverage: none - name: Set up dependencies @@ -89,11 +89,6 @@ jobs: composer install --no-dev composer --working-dir=tests/integration install - - name: Install Ghostscript - run: | - sudo apt-get update - sudo apt-get install ghostscript - - name: Set up Nextcloud run: | if [ "${{ matrix.databases }}" = "mysql" ]; then diff --git a/appinfo/routes/routesFileController.php b/appinfo/routes/routesFileController.php index 5fec0a64aa..1ee64bcc29 100644 --- a/appinfo/routes/routesFileController.php +++ b/appinfo/routes/routesFileController.php @@ -12,6 +12,5 @@ ['name' => 'File#validate', 'url' => '/api/{apiVersion}/file/validate/', 'verb' => 'GET', 'requirements' => $requirements], ['name' => 'File#validateUuid', 'url' => '/api/{apiVersion}/file/validate/uuid/{uuid}', 'verb' => 'GET', 'requirements' => $requirements], ['name' => 'File#validateFileId', 'url' => '/api/{apiVersion}/file/validate/file_id/{fileId}', 'verb' => 'GET', 'requirements' => $requirements], - ['name' => 'File#getPage', 'url' => '/api/{apiVersion}/file/page/{uuid}/{page}.png', 'verb' => 'GET', 'requirements' => $requirements], ], ]; diff --git a/lib/Command/Configure/Check.php b/lib/Command/Configure/Check.php index 2a08d19806..d94be25d66 100644 --- a/lib/Command/Configure/Check.php +++ b/lib/Command/Configure/Check.php @@ -25,7 +25,6 @@ namespace OCA\Libresign\Command\Configure; use OC\Core\Command\Base; -use OCA\Libresign\AppInfo\Application; use OCA\Libresign\Service\Install\ConfigureCheckService; use OCP\IConfig; use Symfony\Component\Console\Helper\Table; @@ -37,7 +36,6 @@ class Check extends Base { private ConfigureCheckService $configureCheckService; - private bool $pagePreviewAsImage = false; public function __construct( ConfigureCheckService $configureCheckService, @@ -45,7 +43,6 @@ public function __construct( ) { parent::__construct(); $this->configureCheckService = $configureCheckService; - $this->pagePreviewAsImage = (bool) $this->config->getAppValue(Application::APP_ID, 'page_preview_as_image', '0'); } protected function configure(): void { @@ -64,33 +61,17 @@ protected function configure(): void { mode: InputOption::VALUE_NONE, description: 'Check requirements to use root certificate' ); - if ($this->pagePreviewAsImage) { - $this - ->addOption( - name: 'preview', - shortcut: 'p', - mode: InputOption::VALUE_NONE, - description: 'Check requirements to generate image preview' - ); - } } protected function execute(InputInterface $input, OutputInterface $output): int { $sign = $input->getOption('sign'); $certificate = $input->getOption('certificate'); $all = (!$sign && !$certificate); - if ($this->pagePreviewAsImage) { - $preview = $input->getOption('preview'); - $all = (!$preview && $all); - } $result = []; if ($all) { $result = $this->configureCheckService->checkAll(); } else { - if ($preview) { - $result = array_merge($result, $this->configureCheckService->canPreview()); - } if ($sign) { $result = array_merge($result, $this->configureCheckService->checkSign()); } diff --git a/lib/Controller/FileController.php b/lib/Controller/FileController.php index 3f20af3306..49198e0b71 100644 --- a/lib/Controller/FileController.php +++ b/lib/Controller/FileController.php @@ -41,7 +41,6 @@ use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\Attribute\PublicPage; -use OCP\AppFramework\Http\DataDisplayResponse; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Http\JSONResponse; @@ -163,29 +162,6 @@ public function list($page = null, $length = null): JSONResponse { return new JSONResponse($return, Http::STATUS_OK); } - /** - * @return DataDisplayResponse|JSONResponse - */ - #[NoAdminRequired] - #[NoCSRFRequired] - public function getPage(string $uuid, int $page) { - try { - $page = $this->fileService->getPage($uuid, $page, $this->userSession->getUser()->getUID()); - return new DataDisplayResponse( - $page, - Http::STATUS_OK, - ['Content-Type' => 'image/png'] - ); - } catch (\Throwable $th) { - $this->logger->error($th->getMessage()); - $return = [ - 'errors' => [$th->getMessage()] - ]; - $statusCode = $th->getCode() > 0 ? $th->getCode() : Http::STATUS_NOT_FOUND; - return new JSONResponse($return, $statusCode); - } - } - #[NoAdminRequired] #[NoCSRFRequired] public function getThumbnail( diff --git a/lib/Service/AccountService.php b/lib/Service/AccountService.php index b65b4c942a..b6ccd9c6dd 100644 --- a/lib/Service/AccountService.php +++ b/lib/Service/AccountService.php @@ -331,18 +331,10 @@ public function canRequestSign(?IUser $user = null): bool { public function getSettings(?IUser $user = null): array { $return['canRequestSign'] = $this->canRequestSign($user); - $return['canPreviewPageAsImage'] = $this->canPreviewPageAsImage(); $return['hasSignatureFile'] = $this->hasSignatureFile($user); return $return; } - private function canPreviewPageAsImage(): bool { - if ((bool) $this->appConfig->getAppValue('page_preview_as_image', '0')) { - return true; - } - return false; - } - public function addFilesToAccount(array $files, IUser $user): void { $this->validateAccountFiles($files, $user); foreach ($files as $fileData) { diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index a902bb3d28..25af403cda 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -30,7 +30,6 @@ use OCA\Libresign\Db\SignRequest; use OCA\Libresign\Db\SignRequestMapper; use OCA\Libresign\Exception\LibresignException; -use OCA\Libresign\Handler\TCPDILibresign; use OCA\Libresign\Helper\ValidateHelper; use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod; use OCP\Accounts\IAccountManager; @@ -433,47 +432,6 @@ public function formatFile(): array { return $return; } - public function getPage(string $uuid, int $page, string $uid): string { - $canPreviewAsImage = (bool) $this->appConfig->getAppValue('page_preview_as_image', '0'); - if (!$canPreviewAsImage) { - throw new LibresignException($this->l10n->t('Page not found.')); - } - $libreSignFile = $this->fileMapper->getByUuid($uuid); - $uid = $this->userSession->getUser()->getUID(); - if ($libreSignFile->getUserId() !== $uid) { - $signers = $this->signRequestMapper->getByFileId($libreSignFile->id); - if (!$signers) { - throw new LibresignException($this->l10n->t('No signers.')); - } - $iNeedSign = false; - foreach ($signers as $signer) { - if ($signer->getUserId() === $uid) { - $iNeedSign = true; - break; - } - } - if (!$iNeedSign) { - throw new LibresignException($this->l10n->t('You must not sign this file.')); - } - } - $userFolder = $this->rootFolder->getUserFolder($libreSignFile->getUserId()); - $file = $userFolder->getById($libreSignFile->getNodeId()); - $pdf = new TCPDILibresign(); - $pageCount = $pdf->setSourceData($file[0]->getContent()); - if ($page > $pageCount || $page < 1) { - throw new LibresignException($this->l10n->t('Page not found.')); - } - $templateId = $pdf->importPage($page); - $pdf->AddPage(); - $pdf->useTemplate($templateId); - $blob = $pdf->Output('', 'S'); - $imagick = new \Imagick(); - $imagick->setResolution(100, 100); - $imagick->readImageBlob($blob); - $imagick->setImageFormat('png'); - return $imagick->getImageBlob(); - } - public function setFileByPath(string $path): self { $node = $this->folderService->getFileByPath($path); $this->setFileByType('FileId', $node->getId()); diff --git a/lib/Service/Install/ConfigureCheckService.php b/lib/Service/Install/ConfigureCheckService.php index da47db1863..ccc79b20c0 100644 --- a/lib/Service/Install/ConfigureCheckService.php +++ b/lib/Service/Install/ConfigureCheckService.php @@ -24,7 +24,6 @@ namespace OCA\Libresign\Service\Install; -use ImagickException; use OC\SystemConfig; use OCA\Libresign\Handler\CertificateEngine\Handler as CertificateEngine; use OCA\Libresign\Handler\JSignPdfHandler; @@ -48,7 +47,6 @@ public function __construct( public function checkAll(): array { $result = []; $result = array_merge($result, $this->checkSign()); - $result = array_merge($result, $this->canPreview()); $result = array_merge($result, $this->checkCertificate()); return $result; } @@ -66,56 +64,6 @@ public function checkSign(): array { return $return; } - /** - * Can preview PDF Files - * - * @return ConfigureCheckHelper[] - */ - public function canPreview(): array { - $pagePreviewAsImage = (bool) $this->appConfig->getAppValue('page_preview_as_image', '0'); - if (!$pagePreviewAsImage) { - return []; - } - if (!extension_loaded('imagick')) { - return [ - (new ConfigureCheckHelper()) - ->setErrorMessage('Extension Imagick required') - ->setResource('imagick') - ->setTip('https://github.com/LibreSign/libresign/issues/829'), - ]; - } - - if (!shell_exec(sprintf("which %s", escapeshellarg('ghostscript')))) { - return [ - (new ConfigureCheckHelper()) - ->setErrorMessage('Is necessary install ghostscript in your operational system to make possible Imagick read PDF files. This feature will be used only if you need to add visible signatures in your PDF files using the web interface.') - ->setResource('imagick') - ->setTip('https://www.php.net/manual/en/imagick.requirements.php '), - ]; - } - - $imagick = new \Imagick(); - $imagick->setResolution(100, 100); - $pdf = file_get_contents(__DIR__ . '/../../tests/fixtures/small_valid.pdf'); - try { - $imagick->readImageBlob($pdf); - } catch (ImagickException $ie) { - if ($ie->getCode() === 499) { - return [ - (new ConfigureCheckHelper()) - ->setErrorMessage('Is necessary to configure the ImageMagick security policy to work with PDF.') - ->setResource('imagick') - ->setTip('https://github.com/LibreSign/libresign/issues/829'), - ]; - } - } - return [ - (new ConfigureCheckHelper()) - ->setSuccessMessage('Can generate the preview') - ->setResource('imagick'), - ]; - } - /** * Check all requirements to use JSignPdf * diff --git a/tests/integration/features/account/me.feature b/tests/integration/features/account/me.feature index 8549de4285..c5d8e3399f 100644 --- a/tests/integration/features/account/me.feature +++ b/tests/integration/features/account/me.feature @@ -15,4 +15,4 @@ Feature: account/me And the response should be a JSON array with the following mandatory values | key | value | | account | {"uid":"signer1","emailAddress":"","displayName":"signer1-displayname"} | - | settings | {"canPreviewPageAsImage": false, "canRequestSign":false,"hasSignatureFile":false} | + | settings | {"canRequestSign":false,"hasSignatureFile":false} |