• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 22147773017

18 Feb 2026 04:16PM UTC coverage: 52.831%. First build
22147773017

Pull #6938

github

web-flow
Merge 312721399 into 725528158
Pull Request #6938: fix: docmdp first signature allow

59 of 68 new or added lines in 7 files covered. (86.76%)

9406 of 17804 relevant lines covered (52.83%)

6.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/lib/Service/DocMdp/Validator.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
7
 * SPDX-License-Identifier: AGPL-3.0-or-later
8
 */
9

10
namespace OCA\Libresign\Service\DocMdp;
11

12
use OCA\Libresign\Db\File;
13
use OCA\Libresign\Db\FileMapper;
14
use OCA\Libresign\Exception\LibresignException;
15
use OCA\Libresign\Service\File\Pdf\PdfValidator;
16
use OCP\AppFramework\Db\DoesNotExistException;
17
use OCP\Files\IRootFolder;
18
use OCP\IL10N;
19

20
class Validator {
21
        public function __construct(
22
                private IL10N $l10n,
23
                private FileMapper $fileMapper,
24
                private ConfigService $configService,
25
                private PdfValidator $pdfValidator,
26
                private IRootFolder $root,
27
        ) {
28
        }
67✔
29

30
        public function validateSignersCount(array $data): void {
31
                if (empty($data['signers'])) {
10✔
32
                        return;
1✔
33
                }
34

35
                $file = null;
9✔
36
                $docMdpLevel = $this->getDocMdpLevel($data, $file);
9✔
37

38
                if ($docMdpLevel === 1) {
9✔
39
                        if ($file && $file->getSignedHash()) {
5✔
40
                                throw new LibresignException(
2✔
41
                                        $this->l10n->t('This document has been certified with no changes allowed. You cannot add more signers to this document.')
2✔
42
                                );
2✔
43
                        }
44

45
                        if (count($data['signers']) > 1) {
3✔
46
                                throw new LibresignException(
2✔
47
                                        $this->l10n->t('This document has been certified with no changes allowed. You cannot add more signers to this document.')
2✔
48
                                );
2✔
49
                        }
50
                }
51
        }
52

53
        public function validatePdfRestrictions(File $file): void {
54
                if (!$file->getSignedHash()) {
3✔
55
                        return;
2✔
56
                }
57

58
                $node = $this->root->getById($file->getNodeId());
1✔
59
                if (empty($node)) {
1✔
NEW
60
                        throw new LibresignException($this->l10n->t('File not found'));
×
61
                }
62

63
                $firstNode = current($node);
1✔
64
                if (!$firstNode instanceof \OCP\Files\File) {
1✔
NEW
65
                        throw new LibresignException($this->l10n->t('Invalid file type'));
×
66
                }
67

68
                $content = $firstNode->getContent();
1✔
69
                $fileName = $firstNode->getName();
1✔
70

71
                $this->pdfValidator->validate($content, $fileName);
1✔
72
        }
73

74
        private function getDocMdpLevel(array $data, ?File &$file): int {
75
                $docMdpLevel = null;
9✔
76

77
                if (!empty($data['uuid'])) {
9✔
78
                        try {
79
                                $file = $this->fileMapper->getByUuid($data['uuid']);
7✔
80
                                $docMdpLevel = $file->getDocmdpLevel();
7✔
NEW
81
                        } catch (DoesNotExistException) {
×
82
                                // File doesn't exist, use global configured level
83
                        }
84
                }
85

86
                if ($docMdpLevel === null || $docMdpLevel === 0) {
9✔
87
                        return $this->configService->getLevel()->value;
4✔
88
                }
89

90
                return $docMdpLevel;
5✔
91
        }
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc