Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
91.67% covered (success)
91.67%
11 / 12
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SignatureStatusPlugin
91.67% covered (success)
91.67%
11 / 12
66.67% covered (warning)
66.67%
2 / 3
7.03
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 initialize
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 propFind
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3/**
4 * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
5 * SPDX-License-Identifier: AGPL-3.0-or-later
6 */
7
8namespace OCA\Libresign\Dav;
9
10use OCA\DAV\Connector\Sabre\Directory;
11use OCA\DAV\Connector\Sabre\File;
12use OCA\Libresign\Service\FileService;
13use Sabre\DAV\INode;
14use Sabre\DAV\PropFind;
15use Sabre\DAV\Server;
16use Sabre\DAV\ServerPlugin;
17
18class SignatureStatusPlugin extends ServerPlugin {
19    public function __construct(
20        private readonly FileService $fileService,
21    ) {
22    }
23
24    #[\Override]
25    public function initialize(Server $server): void {
26        $server->on('propFind', $this->propFind(...));
27    }
28
29    public function propFind(PropFind $propFind, INode $node): void {
30        if (!$node instanceof File && !$node instanceof Directory) {
31            return;
32        }
33
34        $nodeId = $node->getId();
35
36        if (!$this->fileService->isLibresignFile($nodeId)) {
37            return;
38        }
39
40        try {
41            $this->fileService->setFileByNodeId($nodeId);
42        } catch (\Throwable) {
43            // Avoid breaking WebDAV property lookup when the node mapping is invalid.
44            return;
45        }
46
47        $propFind->handle('{http://nextcloud.org/ns}libresign-signature-status', $this->fileService->getStatus());
48        $propFind->handle('{http://nextcloud.org/ns}libresign-signed-node-id', $this->fileService->getSignedNodeId());
49    }
50}