Skip to content

Commit b0f4f24

Browse files
authored
Merge pull request #5225 from LibreSign/feat/show-signature-status-on-files-app
feat: show signature status on files app
2 parents 614bbd4 + 2ef1f85 commit b0f4f24

File tree

19 files changed

+285
-18
lines changed

19 files changed

+285
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: AGPL-3.0-or-later
33
.idea
44
.vscode
5+
.phpactor*
56
.env
67
.secrets
78
*.iml

appinfo/info.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Developed with ❤️ by [LibreCode](https://librecode.coop). Help us transform
2828
<version>13.0.0-dev.2</version>
2929
<licence>agpl</licence>
3030
<author mail="[email protected]" homepage="https://librecode.coop">LibreCode</author>
31+
<types>
32+
<dav/>
33+
</types>
3134
<documentation>
3235
<admin>https://github.com/LibreSign/libresign/blob/master/README.md</admin>
3336
</documentation>
@@ -94,4 +97,9 @@ Developed with ❤️ by [LibreCode](https://librecode.coop). Help us transform
9497
<route>libresign.page.index</route>
9598
</navigation>
9699
</navigations>
100+
<sabre>
101+
<plugins>
102+
<plugin>OCA\Libresign\Dav\SignatureStatusPlugin</plugin>
103+
</plugins>
104+
</sabre>
97105
</info>

lib/Controller/FileController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private function validate(?string $type = null, $identifier = null): DataRespons
236236
* List identification documents that need to be approved
237237
*
238238
* @param string|null $signer_uuid Signer UUID
239-
* @param string|null $nodeId The nodeId (also called fileId). Is the id of a file at Nextcloud
239+
* @param list<string>|null $nodeIds The list of nodeIds (also called fileIds). It's the ids of files at Nextcloud
240240
* @param list<int>|null $status Status could be none or many of 0 = draft, 1 = able to sign, 2 = partial signed, 3 = signed, 4 = deleted.
241241
* @param int|null $page the number of page to return
242242
* @param int|null $length Total of elements to return
@@ -255,7 +255,7 @@ public function list(
255255
?int $page = null,
256256
?int $length = null,
257257
?string $signer_uuid = null,
258-
?string $nodeId = null,
258+
?array $nodeIds = null,
259259
?array $status = null,
260260
?int $start = null,
261261
?int $end = null,
@@ -264,7 +264,7 @@ public function list(
264264
): DataResponse {
265265
$filter = array_filter([
266266
'signer_uuid' => $signer_uuid,
267-
'nodeId' => $nodeId,
267+
'nodeIds' => $nodeIds,
268268
'status' => $status,
269269
'start' => $start,
270270
'end' => $end,

lib/Dav/SignatureStatusPlugin.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
namespace OCA\Libresign\Dav;
9+
10+
use OC;
11+
use OCA\DAV\Connector\Sabre\File;
12+
use OCA\Libresign\Service\FileService;
13+
use Sabre\DAV\INode;
14+
use Sabre\DAV\PropFind;
15+
use Sabre\DAV\Server;
16+
use Sabre\DAV\ServerPlugin;
17+
18+
class SignatureStatusPlugin extends ServerPlugin {
19+
public function initialize(Server $server): void {
20+
$server->on('propFind', [$this, 'propFind']);
21+
}
22+
23+
public function propFind(PropFind $propFind, INode $node): void {
24+
if (!$node instanceof File) {
25+
return;
26+
}
27+
28+
$fileService = OC::$server->get(FileService::class);
29+
$nodeId = $node->getId();
30+
31+
if (!$fileService->isLibresignFile($nodeId)) {
32+
return;
33+
}
34+
35+
$fileService->setFileByType('FileId', $nodeId);
36+
37+
$propFind->handle('{http://nextcloud.org/ns}libresign-signature-status', $fileService->getStatus());
38+
$propFind->handle('{http://nextcloud.org/ns}libresign-signed-node-id', $fileService->getSignedNodeId());
39+
}
40+
}

lib/Db/FileMapper.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,33 @@ public function getByFileId(?int $nodeId = null): File {
167167
return $file;
168168
}
169169

170+
public function fileIdExists(int $nodeId): bool {
171+
$exists = array_filter($this->file, fn ($f) => $f->getNodeId() === $nodeId || $f->getSignedNodeId() === $nodeId);
172+
if (!empty($exists)) {
173+
return true;
174+
}
175+
176+
$qb = $this->db->getQueryBuilder();
177+
178+
$qb->select('*')
179+
->from($this->getTableName())
180+
->where(
181+
$qb->expr()->orX(
182+
$qb->expr()->eq('node_id', $qb->createNamedParameter($nodeId, IQueryBuilder::PARAM_INT)),
183+
$qb->expr()->eq('signed_node_id', $qb->createNamedParameter($nodeId, IQueryBuilder::PARAM_INT))
184+
)
185+
);
186+
187+
$files = $this->findEntities($qb);
188+
if (!empty($files)) {
189+
foreach ($files as $file) {
190+
$this->file[] = $file;
191+
}
192+
return true;
193+
}
194+
return false;
195+
}
196+
170197
/**
171198
* @return File[]
172199
*/

lib/Db/SignRequestMapper.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array
492492
$qb->select(
493493
'f.id',
494494
'f.node_id',
495+
'f.signed_node_id',
495496
'f.user_id',
496497
'f.uuid',
497498
'f.name',
@@ -502,6 +503,7 @@ private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array
502503
->groupBy(
503504
'f.id',
504505
'f.node_id',
506+
'f.signed_node_id',
505507
'f.user_id',
506508
'f.uuid',
507509
'f.name',
@@ -541,9 +543,9 @@ private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array
541543
$qb->expr()->eq('sr.uuid', $qb->createNamedParameter($filter['signer_uuid']))
542544
);
543545
}
544-
if (!empty($filter['nodeId'])) {
546+
if (!empty($filter['nodeIds'])) {
545547
$qb->andWhere(
546-
$qb->expr()->eq('f.node_id', $qb->createNamedParameter($filter['nodeId'], IQueryBuilder::PARAM_INT))
548+
$qb->expr()->in('f.node_id', $qb->createNamedParameter($filter['nodeIds'], IQueryBuilder::PARAM_STR_ARRAY))
547549
);
548550
}
549551
if (!empty($filter['status'])) {
@@ -603,6 +605,7 @@ private function formatListRow(array $row): array {
603605
$row['status'] = (int)$row['status'];
604606
$row['statusText'] = $this->fileMapper->getTextOfStatus($row['status']);
605607
$row['nodeId'] = (int)$row['node_id'];
608+
$row['signedNodeId'] = (int)$row['signed_node_id'];
606609
$row['requested_by'] = [
607610
'userId' => $row['user_id'],
608611
'displayName' => $this->userManager->get($row['user_id'])?->getDisplayName(),
@@ -616,6 +619,7 @@ private function formatListRow(array $row): array {
616619
unset(
617620
$row['user_id'],
618621
$row['node_id'],
622+
$row['signed_node_id'],
619623
);
620624
return $row;
621625
}

lib/ResponseDefinitions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@
219219
* file: array{
220220
* type: string,
221221
* nodeId: non-negative-int,
222+
* signedNodeId: non-negative-int,
222223
* url: string,
223224
* },
224225
* callback: ?string,

lib/Service/FileService.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,19 @@ private function getFile(): \OCP\Files\File {
257257
return $fileToValidate;
258258
}
259259

260+
public function getStatus(): int {
261+
return $this->file->getStatus();
262+
}
263+
264+
public function getSignedNodeId(): ?int {
265+
$status = $this->file->getStatus();
266+
267+
if (!in_array($status, [File::STATUS_PARTIAL_SIGNED, File::STATUS_SIGNED])) {
268+
return null;
269+
}
270+
return $this->file->getSignedNodeId();
271+
}
272+
260273
private function getFileContent(): string {
261274
if ($this->fileContent) {
262275
return $this->fileContent;
@@ -272,6 +285,14 @@ private function getFileContent(): string {
272285
return '';
273286
}
274287

288+
public function isLibresignFile(int $nodeId): bool {
289+
try {
290+
return $this->fileMapper->fileIdExists($nodeId);
291+
} catch (\Throwable) {
292+
throw new LibresignException($this->l10n->t('Invalid data to validate file'), 404);
293+
}
294+
}
295+
275296
private function loadFileMetadata(): void {
276297
if (!$content = $this->getFileContent()) {
277298
return;

openapi-full.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
"required": [
335335
"type",
336336
"nodeId",
337+
"signedNodeId",
337338
"url"
338339
],
339340
"properties": {
@@ -345,6 +346,11 @@
345346
"format": "int64",
346347
"minimum": 0
347348
},
349+
"signedNodeId": {
350+
"type": "integer",
351+
"format": "int64",
352+
"minimum": 0
353+
},
348354
"url": {
349355
"type": "string"
350356
}
@@ -3877,12 +3883,15 @@
38773883
}
38783884
},
38793885
{
3880-
"name": "nodeId",
3886+
"name": "nodeIds[]",
38813887
"in": "query",
3882-
"description": "The nodeId (also called fileId). Is the id of a file at Nextcloud",
3888+
"description": "The list of nodeIds (also called fileIds). It's the ids of files at Nextcloud",
38833889
"schema": {
3884-
"type": "string",
3885-
"nullable": true
3890+
"type": "array",
3891+
"nullable": true,
3892+
"items": {
3893+
"type": "string"
3894+
}
38863895
}
38873896
},
38883897
{

openapi.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
"required": [
265265
"type",
266266
"nodeId",
267+
"signedNodeId",
267268
"url"
268269
],
269270
"properties": {
@@ -275,6 +276,11 @@
275276
"format": "int64",
276277
"minimum": 0
277278
},
279+
"signedNodeId": {
280+
"type": "integer",
281+
"format": "int64",
282+
"minimum": 0
283+
},
278284
"url": {
279285
"type": "string"
280286
}
@@ -3727,12 +3733,15 @@
37273733
}
37283734
},
37293735
{
3730-
"name": "nodeId",
3736+
"name": "nodeIds[]",
37313737
"in": "query",
3732-
"description": "The nodeId (also called fileId). Is the id of a file at Nextcloud",
3738+
"description": "The list of nodeIds (also called fileIds). It's the ids of files at Nextcloud",
37333739
"schema": {
3734-
"type": "string",
3735-
"nullable": true
3740+
"type": "array",
3741+
"nullable": true,
3742+
"items": {
3743+
"type": "string"
3744+
}
37363745
}
37373746
},
37383747
{

0 commit comments

Comments
 (0)