Skip to content

Commit

Permalink
Merge pull request #2609 from LibreSign/backport/2156/stable28
Browse files Browse the repository at this point in the history
[stable28] Remove dead code
  • Loading branch information
vitormattos authored Mar 28, 2024
2 parents 6ddb9c6 + 39a23f6 commit 4964fca
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 153 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion appinfo/routes/routesFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
],
];
19 changes: 0 additions & 19 deletions lib/Command/Configure/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,15 +36,13 @@

class Check extends Base {
private ConfigureCheckService $configureCheckService;
private bool $pagePreviewAsImage = false;

public function __construct(
ConfigureCheckService $configureCheckService,
private IConfig $config,
) {
parent::__construct();
$this->configureCheckService = $configureCheckService;
$this->pagePreviewAsImage = (bool) $this->config->getAppValue(Application::APP_ID, 'page_preview_as_image', '0');
}

protected function configure(): void {
Expand All @@ -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());
}
Expand Down
24 changes: 0 additions & 24 deletions lib/Controller/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 0 additions & 8 deletions lib/Service/AccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
42 changes: 0 additions & 42 deletions lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
52 changes: 0 additions & 52 deletions lib/Service/Install/ConfigureCheckService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/features/account/me.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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} |

0 comments on commit 4964fca

Please sign in to comment.