Skip to content

Commit

Permalink
feat: exposed metadata column to frontend
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Morales <emoral435@gmail.com>
  • Loading branch information
emoral435 committed Mar 9, 2024
1 parent 7117c57 commit 77ed897
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/files_versions/lib/Listener/MetadataFileEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function post_write_hook(Node $node): void {
}
// check if our version manager supports setting the metadata
if ($this->versionManager instanceof IMetadataVersionBackend) {
$author = $this->userSession->getUser()->getDisplayName() ?? '';
$author = $this->userSession->getUser()->getUID();

Check notice

Code scanning / Psalm

PossiblyNullReference Note

Cannot call method getUID on possibly null value
$this->versionManager->setMetadataValue($node, "author", $author);
}
}
Expand Down
3 changes: 3 additions & 0 deletions apps/files_versions/lib/Sabre/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -93,6 +95,7 @@ public function afterGet(RequestInterface $request, ResponseInterface $response)
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()));
}
}
Expand Down
8 changes: 8 additions & 0 deletions apps/files_versions/lib/Sabre/VersionFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -109,6 +110,13 @@ public function setLabel($label): bool {
}
}

public function getMetadataAuthor(): string {
if ($this->version instanceof IMetadataVersion) {
return $this->version->getMetadataValue("author");
}
return '';
}

public function getLastModified(): int {
return $this->version->getTimestamp();
}
Expand Down
10 changes: 9 additions & 1 deletion apps/files_versions/lib/Versions/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
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;

Expand Down Expand Up @@ -121,4 +122,11 @@ public function getVersionPath(): string {
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 '';
}
}
1 change: 1 addition & 0 deletions apps/files_versions/src/utils/davRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>`

0 comments on commit 77ed897

Please sign in to comment.