Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: exposed metadata column to frontend
Signed-off-by: Eduardo Morales <[email protected]>
  • Loading branch information
emoral435 committed Mar 11, 2024
commit 4cf4fdc2785d2ed634e0e23697847f9e58fa99d5
5 changes: 3 additions & 2 deletions apps/files_versions/lib/Listener/MetadataFileEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ public function handle(Event $event): void {
* @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);
}
}
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 {

Check notice

Code scanning / Psalm

DeprecatedInterface

OCA\Files_Versions\Versions\INameableVersion is marked deprecated
/** @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>`