Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.67% |
11 / 12 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SignatureStatusPlugin | |
91.67% |
11 / 12 |
|
66.67% |
2 / 3 |
7.03 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| initialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| propFind | |
100.00% |
10 / 10 |
|
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 | |
| 8 | namespace OCA\Libresign\Dav; |
| 9 | |
| 10 | use OCA\DAV\Connector\Sabre\Directory; |
| 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 __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 | } |