Skip to content

Commit b739d51

Browse files
authored
Merge pull request #7070 from guilhermercarvalho/feat/6590-setup-check-implementation
feat: setup check implementation
2 parents c69628e + 9e022ba commit b739d51

32 files changed

Lines changed: 2782 additions & 707 deletions

lib/AppInfo/Application.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,14 @@ public function register(IRegistrationContext $context): void {
9494
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
9595

9696
$context->registerDashboardWidget(PendingSignaturesWidget::class);
97+
98+
$context->registerSetupCheck(\OCA\Libresign\SetupCheck\JavaSetupCheck::class);
99+
$context->registerSetupCheck(\OCA\Libresign\SetupCheck\JSignPdfSetupCheck::class);
100+
$context->registerSetupCheck(\OCA\Libresign\SetupCheck\PDFtkSetupCheck::class);
101+
102+
$context->registerSetupCheck(\OCA\Libresign\SetupCheck\PopplerSetupCheck::class);
103+
$context->registerSetupCheck(\OCA\Libresign\SetupCheck\ImagickSetupCheck::class);
104+
105+
$context->registerSetupCheck(\OCA\Libresign\SetupCheck\CertificateEngineSetupCheck::class);
97106
}
98107
}

lib/Command/Configure/Check.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
namespace OCA\Libresign\Command\Configure;
1010

1111
use OC\Core\Command\Base;
12-
use OCA\Libresign\Service\Install\ConfigureCheckService;
13-
use OCP\IConfig;
12+
use OCA\Libresign\Service\SetupCheck\ConfigureCheckResult;
13+
use OCA\Libresign\Service\SetupCheckResultService;
1414
use Symfony\Component\Console\Helper\Table;
1515
use Symfony\Component\Console\Helper\TableCell;
1616
use Symfony\Component\Console\Helper\TableCellStyle;
@@ -19,9 +19,9 @@
1919
use Symfony\Component\Console\Output\OutputInterface;
2020

2121
class Check extends Base {
22+
2223
public function __construct(
23-
private ConfigureCheckService $configureCheckService,
24-
private IConfig $config,
24+
private SetupCheckResultService $setupCheckResultService,
2525
) {
2626
parent::__construct();
2727
}
@@ -49,22 +49,25 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4949
$certificate = $input->getOption('certificate');
5050
$all = (!$sign && !$certificate);
5151

52-
$result = [];
53-
if ($all) {
54-
$result = $this->configureCheckService->checkAll();
55-
} else {
56-
if ($sign) {
57-
$result = array_merge($result, $this->configureCheckService->checkSign());
52+
$allChecks = $this->setupCheckResultService->getFormattedChecks();
53+
54+
$filteredRows = array_filter($allChecks, function (ConfigureCheckResult $check) use ($all, $sign, $certificate) {
55+
if ($all) {
56+
return true;
5857
}
59-
if ($certificate) {
60-
$result = array_merge($result, $this->configureCheckService->checkCertificate());
58+
if ($sign && $check->getCategory() === 'system') {
59+
return true;
6160
}
62-
}
61+
if ($certificate && $check->getCategory() === 'security') {
62+
return true;
63+
}
64+
return false;
65+
});
6366

64-
if (count($result)) {
67+
if (!empty($filteredRows)) {
6568
$table = new Table($output);
6669
$table->setColumnMaxWidth(3, 40);
67-
foreach ($result as $row) {
70+
foreach ($filteredRows as $row) {
6871
$table->addRow([
6972
new TableCell($row->getStatus(), ['style' => new TableCellStyle([
7073
'bg' => $this->getStatusColor($row->getStatus()),
@@ -86,10 +89,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8689
->setStyle('symfony-style-guide')
8790
->render();
8891
}
92+
8993
return 0;
9094
}
9195

92-
private function getStatusColor($status): string {
96+
private function getStatusColor(string $status): string {
9397
return match ($status) {
9498
'success' => 'green',
9599
'error' => 'red',

lib/Controller/AdminController.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
use OCA\Libresign\Service\DocMdp\ConfigService as DocMdpConfigService;
2323
use OCA\Libresign\Service\FooterService;
2424
use OCA\Libresign\Service\IdentifyMethodService;
25-
use OCA\Libresign\Service\Install\ConfigureCheckService;
2625
use OCA\Libresign\Service\Install\InstallService;
2726
use OCA\Libresign\Service\ReminderService;
27+
use OCA\Libresign\Service\SetupCheckResultService;
2828
use OCA\Libresign\Service\SignatureBackgroundService;
2929
use OCA\Libresign\Service\SignatureTextService;
3030
use OCA\Libresign\Settings\Admin;
@@ -71,7 +71,6 @@ class AdminController extends AEnvironmentAwareController {
7171
public function __construct(
7272
IRequest $request,
7373
private IAppConfig $appConfig,
74-
private ConfigureCheckService $configureCheckService,
7574
private InstallService $installService,
7675
private CertificateEngineFactory $certificateEngineFactory,
7776
private IEventSourceFactory $eventSourceFactory,
@@ -86,6 +85,7 @@ public function __construct(
8685
private DocMdpConfigService $docMdpConfigService,
8786
private IdentifyMethodService $identifyMethodService,
8887
private FileMapper $fileMapper,
88+
private SetupCheckResultService $setupCheckResultService,
8989
) {
9090
parent::__construct(Application::APP_ID, $request);
9191
$this->eventSource = $this->eventSourceFactory->create();
@@ -258,11 +258,9 @@ public function loadCertificate(): DataResponse {
258258
#[NoCSRFRequired]
259259
#[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/admin/configure-check', requirements: ['apiVersion' => '(v1)'])]
260260
public function configureCheck(): DataResponse {
261-
/** @var LibresignConfigureChecksResponse $configureCheckList */
262-
$configureCheckList = array_values($this->configureCheckService->checkAll());
263-
return new DataResponse(
264-
$configureCheckList
265-
);
261+
/** @var LibresignConfigureChecksResponse $checks */
262+
$checks = $this->setupCheckResultService->getFormattedChecks();
263+
return new DataResponse($checks);
266264
}
267265

268266
/**
@@ -301,8 +299,7 @@ public function installAndValidate(): void {
301299
$this->installService->installCfssl($async);
302300
}
303301

304-
$this->configureCheckService->disableCache();
305-
$this->eventSource->send('configure_check', $this->configureCheckService->checkAll());
302+
$this->eventSource->send('configure_check', $this->setupCheckResultService->getFormattedChecks());
306303
$seconds = 0;
307304
while ($this->installService->isDownloadWip()) {
308305
$totalSize = $this->installService->getTotalSize();
@@ -313,7 +310,7 @@ public function installAndValidate(): void {
313310
usleep(200000); // 0.2 seconds
314311
$seconds += 0.2;
315312
if ($seconds === 5.0) {
316-
$this->eventSource->send('configure_check', $this->configureCheckService->checkAll());
313+
$this->eventSource->send('configure_check', $this->setupCheckResultService->getFormattedChecks());
317314
$seconds = 0;
318315
}
319316
}
@@ -327,7 +324,7 @@ public function installAndValidate(): void {
327324
]));
328325
}
329326

330-
$this->eventSource->send('configure_check', $this->configureCheckService->checkAll());
327+
$this->eventSource->send('configure_check', $this->setupCheckResultService->getFormattedChecks());
331328
$this->eventSource->send('done', '');
332329
$this->eventSource->close();
333330
// Nextcloud inject a lot of headers that is incompatible with SSE
@@ -564,7 +561,7 @@ public function signerName(
564561
float $fontSize,
565562
bool $isDarkTheme,
566563
string $align,
567-
): FileDisplayResponse|DataResponse {
564+
): FileDisplayResponse|DataResponse {
568565
try {
569566
$blob = $this->signatureTextService->signerNameImage(
570567
width: $width,

lib/Handler/CertificateEngine/AEngineHandler.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,11 @@ private function getConfigPathForApi(bool $generated): string {
777777
}
778778

779779
private function filterNameValue(string $name, mixed $value, bool $generated): mixed {
780-
if ($name === 'OU' && is_array($value) && !$generated) {
781-
$filtered = $this->removeCaIdFromOrganizationalUnit($value);
782-
return empty($filtered) ? null : $filtered;
780+
if ($name === 'OU' && is_array($value)) {
781+
if (!$generated) {
782+
$value = $this->removeCaIdFromOrganizationalUnit($value);
783+
}
784+
return empty($value) ? null : implode(', ', $value);
783785
}
784786
return $value;
785787
}

lib/ResponseDefinitions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
* @psalm-type LibresignConfigureCheck = array{
267267
* message: string,
268268
* resource: string,
269-
* status: "error"|"success",
269+
* status: "error"|"info"|"success",
270270
* tip: string,
271271
* }
272272
* @psalm-type LibresignConfigureChecksResponse = list<LibresignConfigureCheck>

0 commit comments

Comments
 (0)