Skip to content

Commit ce3ab98

Browse files
AntDavidLimavitormattos
authored andcommitted
feat(files-app-integration): inject signature status and signed node id on libresign files
1 parent 95c90f6 commit ce3ab98

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

lib/Dav/SignatureStatusPlugin.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace OCA\Libresign\Dav;
44

5+
use OC;
6+
use OCA\DAV\Connector\Sabre\File;
7+
use OCA\Libresign\Service\FileService;
58
use Sabre\DAV\INode;
69
use Sabre\DAV\PropFind;
710
use Sabre\DAV\Server;
@@ -10,12 +13,22 @@
1013
class SignatureStatusPlugin extends ServerPlugin {
1114
protected $server;
1215

13-
public function initialize(Server $server) {
16+
public function initialize(Server $server): void {
1417
$this->server = $server;
1518
$server->on('propFind', [$this, 'propFind']);
1619
}
1720

18-
public function propFind(PropFind $propFind, INode $node) {
19-
$propFind->handle('{http://nextcloud.org/ns}node-name', $node->getName());
21+
public function propFind(PropFind $propFind, INode $node): void {
22+
if ($node instanceof File) {
23+
$fileService = OC::$server->get(FileService::class);
24+
$nodeId = $node->getId();
25+
26+
if ($fileService->isLibresignFile($nodeId)) {
27+
$fileService->setFileByType('FileId', $nodeId);
28+
29+
$propFind->handle('{http://nextcloud.org/ns}signature-status', $fileService->getStatus());
30+
$propFind->handle('{http://nextcloud.org/ns}signed-node-id', $fileService->getSignedNodeId());
31+
}
32+
}
2033
}
2134
}

lib/Db/FileMapper.php

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

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

lib/Service/FileService.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ private function getFile(): \OCP\Files\File {
250250
return current($fileToValidate);
251251
}
252252

253+
public function getStatus(): int {
254+
return $this->file->getStatus();
255+
}
256+
257+
public function getSignedNodeId(): int {
258+
return $this->file->getSignedNodeId();
259+
}
260+
253261
private function getFileContent(): string {
254262
if ($this->fileContent) {
255263
return $this->fileContent;
@@ -265,6 +273,14 @@ private function getFileContent(): string {
265273
return '';
266274
}
267275

276+
public function isLibresignFile(int $nodeId): bool {
277+
try {
278+
return $this->fileMapper->fileIdExists($nodeId);
279+
} catch (\Throwable) {
280+
throw new LibresignException($this->l10n->t('Invalid data to validate file'), 404);
281+
}
282+
}
283+
268284
private function loadFileMetadata(): void {
269285
if (!$content = $this->getFileContent()) {
270286
return;

src/init.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Vue.prototype.n = translatePlural
2121
Vue.prototype.OC = OC
2222
Vue.prototype.OCA = OCA
2323

24-
registerDavProperty('nc:node-name', { nc: 'http://nextcloud.org/ns' })
24+
registerDavProperty('nc:signature-status', { nc: 'http://nextcloud.org/ns' })
25+
registerDavProperty('nc:signed-node-id', { nc: 'http://nextcloud.org/ns' })
2526

2627
addNewFileMenuEntry({
2728
id: 'libresign-request',

0 commit comments

Comments
 (0)