summaryrefslogtreecommitdiffstats
path: root/apps/files_versions
diff options
context:
space:
mode:
authorEduardo Morales <emoral435@gmail.com>2024-03-09 11:05:25 -0600
committerEduardo Morales <emoral435@gmail.com>2024-03-11 15:57:12 -0500
commit4cf4fdc2785d2ed634e0e23697847f9e58fa99d5 (patch)
treebba447b4276c2223ed0fcef57cafa9e048e75498 /apps/files_versions
parentb2c855451c3131e6cb9d2e5e2a6a41ae0b661bb3 (diff)
downloadnextcloud-server-4cf4fdc2785d2ed634e0e23697847f9e58fa99d5.tar.gz
nextcloud-server-4cf4fdc2785d2ed634e0e23697847f9e58fa99d5.zip
feat: exposed metadata column to frontend
Signed-off-by: Eduardo Morales <emoral435@gmail.com>
Diffstat (limited to 'apps/files_versions')
-rw-r--r--apps/files_versions/lib/Listener/MetadataFileEvents.php5
-rw-r--r--apps/files_versions/lib/Sabre/Plugin.php3
-rw-r--r--apps/files_versions/lib/Sabre/VersionFile.php8
-rw-r--r--apps/files_versions/lib/Versions/Version.php10
-rw-r--r--apps/files_versions/src/utils/davRequest.js1
5 files changed, 24 insertions, 3 deletions
diff --git a/apps/files_versions/lib/Listener/MetadataFileEvents.php b/apps/files_versions/lib/Listener/MetadataFileEvents.php
index b58b6b4394a..f23b23cdb40 100644
--- a/apps/files_versions/lib/Listener/MetadataFileEvents.php
+++ b/apps/files_versions/lib/Listener/MetadataFileEvents.php
@@ -54,13 +54,14 @@ class MetadataFileEvents implements IEventListener {
* @param Node $node the node that is currently being written
*/
public function post_write_hook(Node $node): void {
+ $user = $this->userSession->getUser();
// Do not handle folders or users that we cannot get metadata from
- if ($node instanceof Folder || is_null($this->userSession->getUser())) {
+ if ($node instanceof Folder || is_null($user)) {
return;
}
// check if our version manager supports setting the metadata
if ($this->versionManager instanceof IMetadataVersionBackend) {
- $author = $this->userSession->getUser()->getDisplayName() ?? '';
+ $author = $user->getUID();
$this->versionManager->setMetadataValue($node, "author", $author);
}
}
diff --git a/apps/files_versions/lib/Sabre/Plugin.php b/apps/files_versions/lib/Sabre/Plugin.php
index de933ecc7d3..04065bde4cc 100644
--- a/apps/files_versions/lib/Sabre/Plugin.php
+++ b/apps/files_versions/lib/Sabre/Plugin.php
@@ -44,6 +44,8 @@ class Plugin extends ServerPlugin {
public const VERSION_LABEL = '{http://nextcloud.org/ns}version-label';
+ public const VERSION_AUTHOR = '{http://nextcloud.org/ns}version-author'; // dav property for author
+
public function __construct(
private IRequest $request,
private IPreview $previewManager,
@@ -93,6 +95,7 @@ class Plugin extends ServerPlugin {
public function propFind(PropFind $propFind, INode $node): void {
if ($node instanceof VersionFile) {
$propFind->handle(self::VERSION_LABEL, fn () => $node->getLabel());
+ $propFind->handle(self::VERSION_AUTHOR, fn () => $node->getMetadataAuthor());
$propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => $this->previewManager->isMimeSupported($node->getContentType()));
}
}
diff --git a/apps/files_versions/lib/Sabre/VersionFile.php b/apps/files_versions/lib/Sabre/VersionFile.php
index 8fd97b0636f..ec98d24dd06 100644
--- a/apps/files_versions/lib/Sabre/VersionFile.php
+++ b/apps/files_versions/lib/Sabre/VersionFile.php
@@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OCA\Files_Versions\Sabre;
use OCA\Files_Versions\Versions\IDeletableVersionBackend;
+use OCA\Files_Versions\Versions\IMetadataVersion;
use OCA\Files_Versions\Versions\INameableVersion;
use OCA\Files_Versions\Versions\INameableVersionBackend;
use OCA\Files_Versions\Versions\IVersion;
@@ -109,6 +110,13 @@ class VersionFile implements IFile {
}
}
+ public function getMetadataAuthor(): string {
+ if ($this->version instanceof IMetadataVersion) {
+ return $this->version->getMetadataValue("author");
+ }
+ return '';
+ }
+
public function getLastModified(): int {
return $this->version->getTimestamp();
}
diff --git a/apps/files_versions/lib/Versions/Version.php b/apps/files_versions/lib/Versions/Version.php
index 0dade222abc..0e5417783e4 100644
--- a/apps/files_versions/lib/Versions/Version.php
+++ b/apps/files_versions/lib/Versions/Version.php
@@ -26,9 +26,10 @@ declare(strict_types=1);
namespace OCA\Files_Versions\Versions;
use OCP\Files\FileInfo;
+use OCP\Files\Node;
use OCP\IUser;
-class Version implements IVersion, INameableVersion {
+class Version implements IVersion, INameableVersion, IMetadataVersion {
/** @var int */
private $timestamp;
@@ -121,4 +122,11 @@ class Version implements IVersion, INameableVersion {
public function getUser(): IUser {
return $this->user;
}
+
+ public function getMetadataValue(string $key): string {
+ if ($this->backend instanceof IMetadataVersionBackend && $this->sourceFileInfo instanceof Node) {
+ return $this->backend->getMetadataValue($this->sourceFileInfo, "author") ?? '';
+ }
+ return '';
+ }
}
diff --git a/apps/files_versions/src/utils/davRequest.js b/apps/files_versions/src/utils/davRequest.js
index d3fe729aaab..93f1861006b 100644
--- a/apps/files_versions/src/utils/davRequest.js
+++ b/apps/files_versions/src/utils/davRequest.js
@@ -31,6 +31,7 @@ export default `<?xml version="1.0"?>
<d:getlastmodified />
<d:getetag />
<nc:version-label />
+ <nc:version-author />
<nc:has-preview />
</d:prop>
</d:propfind>`