Skip to content

Commit 9651041

Browse files
committed
feat: exposed metadata column to frontend
Signed-off-by: Eduardo Morales <emoral435@gmail.com>
1 parent dd0828c commit 9651041

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

apps/files_versions/lib/Listener/MetadataFileEvents.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ public function handle(Event $event): void {
5454
* @param Node $node the node that is currently being written
5555
*/
5656
public function post_write_hook(Node $node): void {
57+
$user = $this->userSession->getUser();
5758
// Do not handle folders or users that we cannot get metadata from
58-
if ($node instanceof Folder || is_null($this->userSession->getUser())) {
59+
if ($node instanceof Folder || is_null($user)) {
5960
return;
6061
}
6162
// check if our version manager supports setting the metadata
6263
if ($this->versionManager instanceof IMetadataVersionBackend) {
63-
$author = $this->userSession->getUser()->getDisplayName() ?? '';
64+
$author = $user->getUID();
6465
$this->versionManager->setMetadataValue($node, "author", $author);
6566
}
6667
}

apps/files_versions/lib/Sabre/Plugin.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class Plugin extends ServerPlugin {
4444

4545
public const VERSION_LABEL = '{http://nextcloud.org/ns}version-label';
4646

47+
public const VERSION_AUTHOR = '{http://nextcloud.org/ns}version-author'; // dav property for author
48+
4749
public function __construct(
4850
private IRequest $request,
4951
private IPreview $previewManager,
@@ -93,6 +95,7 @@ public function afterGet(RequestInterface $request, ResponseInterface $response)
9395
public function propFind(PropFind $propFind, INode $node): void {
9496
if ($node instanceof VersionFile) {
9597
$propFind->handle(self::VERSION_LABEL, fn () => $node->getLabel());
98+
$propFind->handle(self::VERSION_AUTHOR, fn () => $node->getMetadataAuthor());
9699
$propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => $this->previewManager->isMimeSupported($node->getContentType()));
97100
}
98101
}

apps/files_versions/lib/Sabre/VersionFile.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
namespace OCA\Files_Versions\Sabre;
2828

2929
use OCA\Files_Versions\Versions\IDeletableVersionBackend;
30+
use OCA\Files_Versions\Versions\IMetadataVersion;
3031
use OCA\Files_Versions\Versions\INameableVersion;
3132
use OCA\Files_Versions\Versions\INameableVersionBackend;
3233
use OCA\Files_Versions\Versions\IVersion;
@@ -109,6 +110,13 @@ public function setLabel($label): bool {
109110
}
110111
}
111112

113+
public function getMetadataAuthor(): string {
114+
if ($this->version instanceof IMetadataVersion) {
115+
return $this->version->getMetadataValue("author");
116+
}
117+
return '';
118+
}
119+
112120
public function getLastModified(): int {
113121
return $this->version->getTimestamp();
114122
}

apps/files_versions/lib/Versions/Version.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
namespace OCA\Files_Versions\Versions;
2727

2828
use OCP\Files\FileInfo;
29+
use OCP\Files\Node;
2930
use OCP\IUser;
3031

31-
class Version implements IVersion, INameableVersion {
32+
class Version implements IVersion, INameableVersion, IMetadataVersion {
3233
/** @var int */
3334
private $timestamp;
3435

@@ -121,4 +122,11 @@ public function getVersionPath(): string {
121122
public function getUser(): IUser {
122123
return $this->user;
123124
}
125+
126+
public function getMetadataValue(string $key): string {
127+
if ($this->backend instanceof IMetadataVersionBackend && $this->sourceFileInfo instanceof Node) {
128+
return $this->backend->getMetadataValue($this->sourceFileInfo, "author") ?? '';
129+
}
130+
return '';
131+
}
124132
}

apps/files_versions/src/utils/davRequest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default `<?xml version="1.0"?>
3131
<d:getlastmodified />
3232
<d:getetag />
3333
<nc:version-label />
34+
<nc:version-author />
3435
<nc:has-preview />
3536
</d:prop>
3637
</d:propfind>`

0 commit comments

Comments
 (0)