Skip to content

Commit f89ec9b

Browse files
authored
Merge pull request #6187 from LibreSign/feat/docmdp-per-file
feat: docmdp per file
2 parents 7a542b3 + 50b66c4 commit f89ec9b

16 files changed

Lines changed: 167 additions & 12 deletions

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Developed with ❤️ by [LibreCode](https://librecode.coop). Help us transform
2525
2626
* [Donate with GitHub Sponsor: ![Donate using GitHub Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/libresign)
2727
]]></description>
28-
<version>13.0.0-dev.2</version>
28+
<version>13.0.0-dev.3</version>
2929
<licence>agpl</licence>
3030
<author mail="[email protected]" homepage="https://librecode.coop">LibreCode</author>
3131
<types>

lib/Db/File.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
* @method int getModificationStatus()
4242
* @method void setSignatureFlow(int $signatureFlow)
4343
* @method int getSignatureFlow()
44+
* @method void setDocmdpLevel(int $docmdpLevel)
45+
* @method int getDocmdpLevel()
4446
*/
4547
class File extends Entity {
4648
protected int $nodeId = 0;
@@ -56,6 +58,7 @@ class File extends Entity {
5658
protected ?array $metadata = null;
5759
protected int $modificationStatus = 0;
5860
protected int $signatureFlow = SignatureFlow::NUMERIC_PARALLEL;
61+
protected int $docmdpLevel = 0;
5962
public const STATUS_NOT_LIBRESIGN_FILE = -1;
6063
public const STATUS_DRAFT = 0;
6164
public const STATUS_ABLE_TO_SIGN = 1;
@@ -83,6 +86,7 @@ public function __construct() {
8386
$this->addType('metadata', Types::JSON);
8487
$this->addType('modificationStatus', Types::SMALLINT);
8588
$this->addType('signatureFlow', Types::SMALLINT);
89+
$this->addType('docmdpLevel', Types::SMALLINT);
8690
}
8791

8892
public function isDeletedAccount(): bool {
@@ -102,4 +106,12 @@ public function getSignatureFlowEnum(): \OCA\Libresign\Enum\SignatureFlow {
102106
public function setSignatureFlowEnum(\OCA\Libresign\Enum\SignatureFlow $flow): void {
103107
$this->setSignatureFlow($flow->toNumeric());
104108
}
109+
110+
public function getDocmdpLevelEnum(): \OCA\Libresign\Enum\DocMdpLevel {
111+
return \OCA\Libresign\Enum\DocMdpLevel::tryFrom($this->docmdpLevel) ?? \OCA\Libresign\Enum\DocMdpLevel::NOT_CERTIFIED;
112+
}
113+
114+
public function setDocmdpLevelEnum(\OCA\Libresign\Enum\DocMdpLevel $level): void {
115+
$this->setDocmdpLevel($level->value);
116+
}
105117
}

lib/Db/SignRequestMapper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array
502502
'f.metadata',
503503
'f.created_at',
504504
'f.signature_flow',
505+
'f.docmdp_level',
505506
)
506507
->groupBy(
507508
'f.id',
@@ -513,6 +514,7 @@ private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array
513514
'f.status',
514515
'f.created_at',
515516
'f.signature_flow',
517+
'f.docmdp_level',
516518
);
517519
// metadata is a json column, the right way is to use f.metadata::text
518520
// when the database is PostgreSQL. The problem is that the command
@@ -624,12 +626,14 @@ private function formatListRow(array $row): array {
624626

625627
$row['name'] = $this->removeExtensionFromName($row['name'], $row['metadata']);
626628
$row['signatureFlow'] = SignatureFlow::fromNumeric((int)($row['signature_flow']))->value;
629+
$row['docmdpLevel'] = (int)($row['docmdp_level'] ?? 0);
627630

628631
unset(
629632
$row['user_id'],
630633
$row['node_id'],
631634
$row['signed_node_id'],
632635
$row['signature_flow'],
636+
$row['docmdp_level'],
633637
);
634638
return $row;
635639
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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\Migration;
10+
11+
use Closure;
12+
use OCP\DB\ISchemaWrapper;
13+
use OCP\DB\Types;
14+
use OCP\Migration\IOutput;
15+
use OCP\Migration\SimpleMigrationStep;
16+
17+
/**
18+
* Add DocMDP level support per file
19+
* - Adds 'docmdp_level' column to libresign_file table to store DocMDP certification level per file
20+
*/
21+
class Version15001Date20251214000000 extends SimpleMigrationStep {
22+
/**
23+
* @param IOutput $output
24+
* @param Closure(): ISchemaWrapper $schemaClosure
25+
* @param array $options
26+
* @return null|ISchemaWrapper
27+
*/
28+
#[\Override]
29+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
30+
/** @var ISchemaWrapper $schema */
31+
$schema = $schemaClosure();
32+
33+
if ($schema->hasTable('libresign_file')) {
34+
$tableFile = $schema->getTable('libresign_file');
35+
if (!$tableFile->hasColumn('docmdp_level')) {
36+
$tableFile->addColumn('docmdp_level', Types::SMALLINT, [
37+
'notnull' => true,
38+
'default' => 0,
39+
'comment' => 'DocMDP permission level for this file: 0=none, 1=no changes, 2=form fill, 3=form fill + annotations',
40+
]);
41+
}
42+
}
43+
44+
return $schema;
45+
}
46+
}

lib/ResponseDefinitions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
* statusText: string,
188188
* nodeId: non-negative-int,
189189
* signatureFlow: int,
190+
* docmdpLevel: int,
190191
* totalPages: non-negative-int,
191192
* size: non-negative-int,
192193
* pdfVersion: string,

lib/Service/FileService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ private function loadLibreSignData(): void {
712712
$this->fileData->statusText = $this->fileMapper->getTextOfStatus($this->file->getStatus());
713713
$this->fileData->nodeId = $this->file->getNodeId();
714714
$this->fileData->signatureFlow = $this->file->getSignatureFlow();
715+
$this->fileData->docmdpLevel = $this->file->getDocmdpLevel();
715716

716717
$this->fileData->requested_by = [
717718
'userId' => $this->file->getUserId(),

lib/Service/RequestSignatureService.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function __construct(
5656
protected IEventDispatcher $eventDispatcher,
5757
protected FileStatusService $fileStatusService,
5858
protected SignRequestStatusService $signRequestStatusService,
59+
protected DocMdpConfigService $docMdpConfigService,
5960
) {
6061
}
6162

@@ -128,6 +129,8 @@ public function saveFile(array $data): FileEntity {
128129
$this->setSignatureFlowFromGlobalConfig($file);
129130
}
130131

132+
$this->setDocMdpLevelFromGlobalConfig($file);
133+
131134
$this->fileMapper->insert($file);
132135
return $file;
133136
}
@@ -138,6 +141,13 @@ private function setSignatureFlowFromGlobalConfig(FileEntity $file): void {
138141
$file->setSignatureFlowEnum($globalFlow);
139142
}
140143

144+
private function setDocMdpLevelFromGlobalConfig(FileEntity $file): void {
145+
if ($this->docMdpConfigService->isEnabled()) {
146+
$docmdpLevel = $this->docMdpConfigService->getLevel();
147+
$file->setDocmdpLevelEnum($docmdpLevel);
148+
}
149+
}
150+
141151
private function getFileMetadata(\OCP\Files\Node $node): array {
142152
$metadata = [];
143153
if ($extension = strtolower($node->getExtension())) {

lib/Service/SignFileService.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -338,17 +338,28 @@ public function sign(): File {
338338
* @throws LibresignException If the document has DocMDP level 1 (no changes allowed)
339339
*/
340340
protected function validateDocMdpAllowsSignatures(): void {
341-
$resource = $this->getLibreSignFileAsResource();
341+
$docmdpLevel = $this->libreSignFile->getDocmdpLevelEnum();
342342

343-
try {
344-
if (!$this->docMdpHandler->allowsAdditionalSignatures($resource)) {
345-
throw new LibresignException(
346-
$this->l10n->t('This document has been certified with no changes allowed, so no additional signatures can be added.'),
347-
AppFrameworkHttp::STATUS_UNPROCESSABLE_ENTITY
348-
);
343+
if ($docmdpLevel === \OCA\Libresign\Enum\DocMdpLevel::CERTIFIED_NO_CHANGES_ALLOWED) {
344+
throw new LibresignException(
345+
$this->l10n->t('This document has been certified with no changes allowed. You cannot add more signers to this document.'),
346+
AppFrameworkHttp::STATUS_UNPROCESSABLE_ENTITY
347+
);
348+
}
349+
350+
if ($docmdpLevel === \OCA\Libresign\Enum\DocMdpLevel::NOT_CERTIFIED) {
351+
$resource = $this->getLibreSignFileAsResource();
352+
353+
try {
354+
if (!$this->docMdpHandler->allowsAdditionalSignatures($resource)) {
355+
throw new LibresignException(
356+
$this->l10n->t('This document has been certified with no changes allowed. You cannot add more signers to this document.'),
357+
AppFrameworkHttp::STATUS_UNPROCESSABLE_ENTITY
358+
);
359+
}
360+
} finally {
361+
fclose($resource);
349362
}
350-
} finally {
351-
fclose($resource);
352363
}
353364
}
354365

openapi-full.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,7 @@
10131013
"statusText",
10141014
"nodeId",
10151015
"signatureFlow",
1016+
"docmdpLevel",
10161017
"totalPages",
10171018
"size",
10181019
"pdfVersion",
@@ -1050,6 +1051,10 @@
10501051
"type": "integer",
10511052
"format": "int64"
10521053
},
1054+
"docmdpLevel": {
1055+
"type": "integer",
1056+
"format": "int64"
1057+
},
10531058
"totalPages": {
10541059
"type": "integer",
10551060
"format": "int64",

openapi.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@
863863
"statusText",
864864
"nodeId",
865865
"signatureFlow",
866+
"docmdpLevel",
866867
"totalPages",
867868
"size",
868869
"pdfVersion",
@@ -900,6 +901,10 @@
900901
"type": "integer",
901902
"format": "int64"
902903
},
904+
"docmdpLevel": {
905+
"type": "integer",
906+
"format": "int64"
907+
},
903908
"totalPages": {
904909
"type": "integer",
905910
"format": "int64",

0 commit comments

Comments
 (0)