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

LibreSign / libresign / 20398911259

20 Dec 2025 07:18PM UTC coverage: 43.096%. First build
20398911259

Pull #6242

github

web-flow
Merge 84a3bfc58 into fae2922ee
Pull Request #6242: feat: envelope support

173 of 554 new or added lines in 13 files covered. (31.23%)

6061 of 14064 relevant lines covered (43.1%)

5.05 hits per line

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

80.95
/lib/Service/EnvelopeService.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8

9
namespace OCA\Libresign\Service;
10

11
use DateTime;
12
use OCA\Libresign\AppInfo\Application;
13
use OCA\Libresign\Db\File as FileEntity;
14
use OCA\Libresign\Db\FileMapper;
15
use OCA\Libresign\Enum\NodeType;
16
use OCA\Libresign\Exception\LibresignException;
17
use OCP\AppFramework\Db\DoesNotExistException;
18
use OCP\IAppConfig;
19
use OCP\IL10N;
20
use Sabre\DAV\UUIDUtil;
21

22
class EnvelopeService {
23
        public function __construct(
24
                protected FileMapper $fileMapper,
25
                protected IL10N $l10n,
26
                protected IAppConfig $appConfig,
27
                protected FolderService $folderService,
28
        ) {
29
        }
50✔
30

31
        public function isEnabled(): bool {
NEW
32
                return $this->appConfig->getValueBool(Application::APP_ID, 'envelope_enabled', true);
×
33
        }
34

35
        /**
36
         * @throws LibresignException
37
         */
38
        public function validateEnvelopeConstraints(int $fileCount): void {
NEW
39
                if (!$this->isEnabled()) {
×
NEW
40
                        throw new LibresignException($this->l10n->t('Envelope feature is disabled'));
×
41
                }
42

NEW
43
                $maxFiles = $this->getMaxFilesPerEnvelope();
×
NEW
44
                if ($fileCount > $maxFiles) {
×
NEW
45
                        throw new LibresignException(
×
NEW
46
                                $this->l10n->t('Maximum number of files per envelope (%s) exceeded', [$maxFiles])
×
NEW
47
                        );
×
48
                }
49
        }
50

51
        public function createEnvelope(string $name, string $userId, int $filesCount = 0): FileEntity {
52
                $this->folderService->setUserId($userId);
2✔
53

54
                $parentFolder = $this->folderService->getFolder();
2✔
55

56
                $folderName = $name . '_' . substr(UUIDUtil::getUUID(), 0, 8);
2✔
57
                $envelopeFolder = $parentFolder->newFolder($folderName);
2✔
58

59
                $envelope = new FileEntity();
2✔
60
                $envelope->setNodeId($envelopeFolder->getId());
2✔
61
                $envelope->setNodeTypeEnum(NodeType::ENVELOPE);
2✔
62
                $envelope->setName($name);
2✔
63
                $envelope->setUuid(UUIDUtil::getUUID());
2✔
64
                $envelope->setCreatedAt(new DateTime());
2✔
65
                $envelope->setStatus(FileEntity::STATUS_DRAFT);
2✔
66

67
                $envelope->setMetadata(['filesCount' => $filesCount]);
2✔
68

69
                if ($userId) {
2✔
70
                        $envelope->setUserId($userId);
2✔
71
                }
72

73
                return $this->fileMapper->insert($envelope);
2✔
74
        }
75

76
        public function addFileToEnvelope(int $envelopeId, FileEntity $file): FileEntity {
77
                $envelope = $this->fileMapper->getById($envelopeId);
5✔
78

79
                if (!$envelope->isEnvelope()) {
5✔
80
                        throw new LibresignException($this->l10n->t('The specified ID is not an envelope'));
1✔
81
                }
82

83
                if ($envelope->getStatus() > FileEntity::STATUS_DRAFT) {
4✔
84
                        throw new LibresignException($this->l10n->t('Cannot add files to an envelope that is already in signing process'));
1✔
85
                }
86

87
                $maxFiles = $this->getMaxFilesPerEnvelope();
3✔
88
                $currentCount = $this->fileMapper->countChildrenFiles($envelopeId);
3✔
89
                if ($currentCount >= $maxFiles) {
3✔
90
                        throw new LibresignException(
1✔
91
                                $this->l10n->t('Maximum number of files per envelope (%s) exceeded', [$maxFiles])
1✔
92
                        );
1✔
93
                }
94

95
                $file->setParentFileId($envelopeId);
2✔
96
                $file->setNodeTypeEnum(NodeType::FILE);
2✔
97

98
                return $this->fileMapper->update($file);
2✔
99
        }
100

101
        public function getEnvelopeByFileId(int $fileId): ?FileEntity {
102
                try {
103
                        return $this->fileMapper->getParentEnvelope($fileId);
2✔
104
                } catch (DoesNotExistException) {
1✔
105
                        return null;
1✔
106
                }
107
        }
108

109
        private function getMaxFilesPerEnvelope(): int {
110
                return $this->appConfig->getValueInt(Application::APP_ID, 'envelope_max_files', 50);
3✔
111
        }
112
}
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

© 2025 Coveralls, Inc