Skip to content

Commit

Permalink
chore: replace class and method to get app value
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Jan 10, 2025
1 parent bb7da0e commit c3fdf4d
Show file tree
Hide file tree
Showing 44 changed files with 195 additions and 184 deletions.
4 changes: 2 additions & 2 deletions lib/Command/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace OCA\Libresign\Command;

use OCA\Libresign\Service\Install\InstallService;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IAppConfig;
use OCP\IConfig;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -121,7 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$ok = true;
}
if ($input->getOption('cfssl') || $all) {
$currentEngine = $this->appConfig->getAppValue('certificate_engine', 'openssl');
$currentEngine = $this->appConfig->getValueString('certificate_engine', 'openssl');
$this->installService->installCfssl();
if ($currentEngine !== 'cfssl') {
$output->writeln('<comment>To use CFSSL, set the engine to cfssl with:</comment> config:app:set libresign certificate_engine --value cfssl');
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IAppConfig;
use OCP\IEventSource;
use OCP\IEventSourceFactory;
use OCP\IL10N;
Expand Down Expand Up @@ -225,7 +225,7 @@ public function installAndValidate(): void {
$this->installService->installJava($async);
$this->installService->installJSignPdf($async);
$this->installService->installPdftk($async);
if ($this->appConfig->getAppValue('certificate_engine') === 'cfssl') {
if ($this->appConfig->getValueString(Application::APP_ID, 'certificate_engine') === 'cfssl') {
$this->installService->installCfssl($async);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -95,7 +95,7 @@ public function index(): TemplateResponse {

$this->provideSignerSignatues();
$this->initialState->provideInitialState('identify_methods', $this->identifyMethodService->getIdentifyMethodsSettings());
$this->initialState->provideInitialState('legal_information', $this->appConfig->getAppValue('legal_information'));
$this->initialState->provideInitialState('legal_information', $this->appConfig->getValueString(Application::APP_ID, 'legal_information'));

Util::addScript(Application::APP_ID, 'libresign-main');

Expand Down Expand Up @@ -575,7 +575,7 @@ public function validationFilePublic(string $uuid): TemplateResponse {
);
}

$this->initialState->provideInitialState('legal_information', $this->appConfig->getAppValue('legal_information'));
$this->initialState->provideInitialState('legal_information', $this->appConfig->getValueString(Application::APP_ID, 'legal_information'));

$this->initialState->provideInitialState('file_info',
$this->fileService
Expand All @@ -598,7 +598,7 @@ public function validationFilePublic(string $uuid): TemplateResponse {
}

private function throwIfValidationPageNotAccessible(): void {
$isValidationUrlPrivate = (bool)$this->appConfig->getAppValue('make_validation_url_private', '0');
$isValidationUrlPrivate = (bool)$this->appConfig->getValueBool(Application::APP_ID, 'make_validation_url_private', false);
if ($this->userSession->isLoggedIn()) {
return;
}
Expand Down
20 changes: 10 additions & 10 deletions lib/Handler/CertificateEngine/AEngineHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

namespace OCA\Libresign\Handler\CertificateEngine;

use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Exception\EmptyCertificateException;
use OCA\Libresign\Exception\InvalidPasswordException;
use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Helper\MagicGetterSetterTrait;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\IAppData;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\ITempManager;
Expand Down Expand Up @@ -187,19 +188,18 @@ public function translateToLong($name): string {
}

public function setEngine(string $engine): void {
$this->appConfig->setAppValue('certificate_engine', $engine);
$this->appConfig->setValueString(Application::APP_ID, 'certificate_engine', $engine);
$this->engine = $engine;
}

public function getEngine(): string {
$this->engine = $this->appConfig->getAppValue('certificate_engine', 'openssl');
$this->engine = $this->appConfig->getValueString(Application::APP_ID, 'certificate_engine', 'openssl');
return $this->engine;
}

public function populateInstance(array $rootCert): self {
if (empty($rootCert)) {
$rootCert = $this->appConfig->getAppValue('root_cert');
$rootCert = json_decode($rootCert, true);
$rootCert = $this->appConfig->getValueString(Application::APP_ID, 'root_cert');
}
if (!$rootCert) {
return $this;
Expand All @@ -224,7 +224,7 @@ public function getConfigPath(): string {
if ($this->configPath) {
return $this->configPath;
}
$this->configPath = $this->appConfig->getAppValue('config_path');
$this->configPath = $this->appConfig->getValueString(Application::APP_ID, 'config_path');
if ($this->configPath && str_ends_with($this->configPath, $this->getName() . '_config')) {
return $this->configPath;
}
Expand Down Expand Up @@ -264,9 +264,9 @@ private function getInternalPathOfFolder(ISimpleFolder $node): string {

public function setConfigPath(string $configPath): void {
if (!$configPath) {
$this->appConfig->deleteAppValue('config_path');
$this->appConfig->deleteKey(Application::APP_ID, 'config_path');
} else {
$this->appConfig->setAppValue('config_path', $configPath);
$this->appConfig->setValueString(Application::APP_ID, 'config_path', $configPath);
}
$this->configPath = $configPath;
}
Expand Down Expand Up @@ -300,15 +300,15 @@ public function getUID(): string {
}

public function expirity(): int {
$expirity = $this->appConfig->getAppValueInt('expiry_in_days', 365);
$expirity = $this->appConfig->getValueInt(Application::APP_ID, 'expiry_in_days', 365);
if ($expirity < 0) {
return 365;
}
return $expirity;
}

public function isSetupOk(): bool {
return $this->appConfig->getAppValue('authkey') ? true : false;
return $this->appConfig->getValueBool(Application::APP_ID, 'authkey', false);
}

public function configureCheck(): array {
Expand Down
11 changes: 6 additions & 5 deletions lib/Handler/CertificateEngine/CfsslHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use OC\SystemConfig;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Handler\CfsslServerHandler;
use OCA\Libresign\Helper\ConfigureCheckHelper;
use OCA\Libresign\Service\Install\InstallService;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Files\AppData\IAppDataFactory;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\ITempManager;
Expand Down Expand Up @@ -125,7 +126,7 @@ public function configureCheck(): array {
public function toArray(): array {
$return = parent::toArray();
if (!empty($return['configPath'])) {
$return['cfsslUri'] = $this->appConfig->getAppValue('cfssl_uri');
$return['cfsslUri'] = $this->appConfig->getValueString(Application::APP_ID, 'cfssl_uri');
}
return $return;
}
Expand Down Expand Up @@ -316,7 +317,7 @@ private function getBinary(): string {
$appKeys = $this->appConfig->getAppKeys();

Check failure on line 317 in lib/Handler/CertificateEngine/CfsslHandler.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedInterfaceMethod

lib/Handler/CertificateEngine/CfsslHandler.php:317:32: UndefinedInterfaceMethod: Method OCP\IAppConfig::getAppKeys does not exist (see https://psalm.dev/181)
$binary = '';
if (in_array('cfssl_bin', $appKeys)) {
$binary = $this->appConfig->getAppValue('cfssl_bin');
$binary = $this->appConfig->getValueString(Application::APP_ID, 'cfssl_bin');
if (!file_exists($binary)) {
$this->appConfig->deleteAppValue('cfssl_bin');

Check failure on line 322 in lib/Handler/CertificateEngine/CfsslHandler.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedInterfaceMethod

lib/Handler/CertificateEngine/CfsslHandler.php:322:23: UndefinedInterfaceMethod: Method OCP\IAppConfig::deleteAppValue does not exist (see https://psalm.dev/181)
}
Expand All @@ -340,7 +341,7 @@ private function getCfsslUri(): string {

$appKeys = $this->appConfig->getAppKeys();

Check failure on line 342 in lib/Handler/CertificateEngine/CfsslHandler.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedInterfaceMethod

lib/Handler/CertificateEngine/CfsslHandler.php:342:32: UndefinedInterfaceMethod: Method OCP\IAppConfig::getAppKeys does not exist (see https://psalm.dev/181)
if (in_array('cfssl_uri', $appKeys)) {
if ($uri = $this->appConfig->getAppValue('cfssl_uri')) {
if ($uri = $this->appConfig->getValueString(Application::APP_ID, 'cfssl_uri')) {
return $uri;
}
// In case config is an empty string
Expand Down Expand Up @@ -368,7 +369,7 @@ private function checkBinaries(): array {
->setResource('cfssl'),
];
}
$binary = $this->appConfig->getAppValue('cfssl_bin');
$binary = $this->appConfig->getValueString(Application::APP_ID, 'cfssl_bin');
if (!$binary) {
return [
(new ConfigureCheckHelper())
Expand Down
5 changes: 3 additions & 2 deletions lib/Handler/CertificateEngine/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

namespace OCA\Libresign\Handler\CertificateEngine;

use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Exception\LibresignException;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IAppConfig;

class Handler {
public function __construct(
Expand All @@ -25,7 +26,7 @@ public function __construct(
*/
public function getEngine(string $engineName = '', array $rootCert = []): AEngineHandler {
if (!$engineName) {
$engineName = $this->appConfig->getAppValue('certificate_engine', 'openssl');
$engineName = $this->appConfig->getValueString(Application::APP_ID, 'certificate_engine', 'openssl');
}
if ($engineName === 'openssl') {
$engine = $this->openSslHandler;
Expand Down
2 changes: 1 addition & 1 deletion lib/Handler/CertificateEngine/OpenSslHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Helper\ConfigureCheckHelper;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Files\AppData\IAppDataFactory;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\ITempManager;
Expand Down
17 changes: 9 additions & 8 deletions lib/Handler/FooterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
use Endroid\QrCode\Writer\PngWriter;
use League\Plates\Engine;
use Mpdf\Mpdf;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Db\File as FileEntity;
use OCA\Libresign\Service\PdfParserService;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Files\File;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\ITempManager;
use OCP\IURLGenerator;
Expand All @@ -46,7 +47,7 @@ public function __construct(
public function getFooter(File $file, FileEntity $fileEntity): string {
$this->file = $file;
$this->fileEntity = $fileEntity;
$add_footer = (bool)$this->appConfig->getAppValue('add_footer', '1');
$add_footer = (bool)$this->appConfig->getValueBool(Application::APP_ID, 'add_footer', true);
if (!$add_footer) {
return '';
}
Expand Down Expand Up @@ -110,12 +111,12 @@ private function getTemplateVars(): array {
$this->templateVars['signedBy'] = iconv(
'UTF-8',
'windows-1252',
$this->appConfig->getAppValue('footer_signed_by', $this->l10n->t('Digital signed by LibreSign.'))
$this->appConfig->getValueString(Application::APP_ID, 'footer_signed_by', $this->l10n->t('Digital signed by LibreSign.'))
);

$this->templateVars['linkToSite'] = $this->appConfig->getAppValue('footer_link_to_site', 'https://libresign.coop');
$this->templateVars['linkToSite'] = $this->appConfig->getValueString(Application::APP_ID, 'footer_link_to_site', 'https://libresign.coop');

$this->templateVars['validationSite'] = $this->appConfig->getAppValue('validation_site');
$this->templateVars['validationSite'] = $this->appConfig->getValueString(Application::APP_ID, 'validation_site');
if ($this->templateVars['validationSite']) {
$this->templateVars['validationSite'] = rtrim($this->templateVars['validationSite'], '/') . '/' . $this->fileEntity->getUuid();
} else {
Expand All @@ -124,20 +125,20 @@ private function getTemplateVars(): array {
]);
}

$this->templateVars['validateIn'] = $this->appConfig->getAppValue('footer_validate_in', 'Validate in %s.');
$this->templateVars['validateIn'] = $this->appConfig->getValueString(Application::APP_ID, 'footer_validate_in', 'Validate in %s.');
if ($this->templateVars['validateIn'] === 'Validate in %s.') {
$this->templateVars['validateIn'] = $this->l10n->t('Validate in %s.', ['%s']);
}

if ($this->appConfig->getAppValue('write_qrcode_on_footer', '1')) {
if ($this->appConfig->getValueBool(Application::APP_ID, 'write_qrcode_on_footer', true)) {
$this->templateVars['qrcode'] = $this->getQrCodeImageBase64($this->templateVars['validationSite']);
}

return $this->templateVars;
}

private function getTemplate(): string {
return $this->appConfig->getAppValue('footer_template', file_get_contents(__DIR__ . '/Templates/footer.php'));
return $this->appConfig->getValueString(Application::APP_ID, 'footer_template', file_get_contents(__DIR__ . '/Templates/footer.php'));
}

private function getQrCodeImageBase64(string $text): string {
Expand Down
11 changes: 6 additions & 5 deletions lib/Handler/JSignPdfHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

use Jeidison\JSignPDF\JSignPDF;
use Jeidison\JSignPDF\Sign\JSignParam;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Exception\LibresignException;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IAppConfig;
use Psr\Log\LoggerInterface;

class JSignPdfHandler extends SignEngineHandler {
Expand Down Expand Up @@ -45,14 +46,14 @@ public function getJSignPdf(): JSignPDF {
*/
public function getJSignParam(): JSignParam {
if (!$this->jSignParam) {
$javaPath = $this->appConfig->getAppValue('java_path');
$javaPath = $this->appConfig->getValueString(Application::APP_ID, 'java_path');
$this->jSignParam = (new JSignParam())
->setTempPath(
$this->appConfig->getAppValue('jsignpdf_temp_path', sys_get_temp_dir() . DIRECTORY_SEPARATOR)
$this->appConfig->getValueString(Application::APP_ID, 'jsignpdf_temp_path', sys_get_temp_dir() . DIRECTORY_SEPARATOR)
)
->setIsUseJavaInstalled(empty($javaPath))
->setjSignPdfJarPath(
$this->appConfig->getAppValue('jsignpdf_jar_path', '/opt/jsignpdf-' . self::VERSION . '/JSignPdf.jar')
$this->appConfig->getValueString(Application::APP_ID, 'jsignpdf_jar_path', '/opt/jsignpdf-' . self::VERSION . '/JSignPdf.jar')
);
if (!empty($javaPath)) {
if (!file_exists($javaPath)) {
Expand Down Expand Up @@ -84,7 +85,7 @@ private function getHashAlgorithm(): string {
}
}

$hashAlgorithm = $this->appConfig->getAppValue('signature_hash_algorithm', 'SHA256');
$hashAlgorithm = $this->appConfig->getValueString(Application::APP_ID, 'signature_hash_algorithm', 'SHA256');
if (in_array($hashAlgorithm, ['SHA1', 'SHA256', 'SHA384', 'SHA512', 'RIPEMD160'])) {
return $hashAlgorithm;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Handler/Pkcs12Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Handler\CertificateEngine\Handler as CertificateEngineHandler;
use OCA\Libresign\Service\FolderService;
use OCP\IAppConfig;

use OCP\Files\File;

use OCP\IAppConfig;
use OCP\IL10N;
use OCP\ITempManager;
use phpseclib3\File\ASN1;
Expand Down
7 changes: 4 additions & 3 deletions lib/Helper/ValidateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use InvalidArgumentException;
use OC\AppFramework\Http;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Db\AccountFileMapper;
use OCA\Libresign\Db\File;
use OCA\Libresign\Db\FileElement;
Expand All @@ -25,11 +26,11 @@
use OCA\Libresign\Service\FileService;
use OCA\Libresign\Service\IdentifyMethodService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\IAppConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IUser;
Expand Down Expand Up @@ -433,7 +434,7 @@ private function getLibreSignFileByNodeId(int $nodeId) {
}

public function canRequestSign(IUser $user): void {
$authorized = json_decode($this->appConfig->getAppValue('groups_request_sign', '["admin"]'), true);
$authorized = $this->appConfig->getValueArray(Application::APP_ID, 'groups_request_sign', ['admin']);
if (empty($authorized)) {
$authorized = ['admin'];
}
Expand Down Expand Up @@ -732,7 +733,7 @@ public function userCanApproveValidationDocuments(?IUser $user, bool $throw = tr
return false;
}

$authorized = json_decode($this->appConfig->getAppValue('approval_group', '["admin"]'));
$authorized = $this->appConfig->getValueArray(Application::APP_ID, 'approval_group', ['admin']);
if (!$authorized || !is_array($authorized) || empty($authorized)) {
$authorized = ['admin'];
}
Expand Down
Loading

0 comments on commit c3fdf4d

Please sign in to comment.