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

LibreSign / libresign / 20395868261

20 Dec 2025 02:42PM UTC coverage: 43.246%. First build
20395868261

Pull #6242

github

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

162 of 510 new or added lines in 13 files covered. (31.76%)

6064 of 14022 relevant lines covered (43.25%)

5.07 hits per line

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

76.19
/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 = null): FileEntity {
52
                if ($userId) {
2✔
NEW
53
                        $this->folderService->setUserId($userId);
×
54
                }
55
                $parentFolder = $this->folderService->getFolder();
2✔
56

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

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

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

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

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

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

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

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

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

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

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

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