Skip to content

Commit f1a6ffe

Browse files
committed
feat: updated plugins - exposes version owner
Signed-off-by: Eduardo Morales <emoral435@gmail.com>
1 parent 0cdc86c commit f1a6ffe

File tree

9 files changed

+52
-102
lines changed

9 files changed

+52
-102
lines changed

apps/files_versions/lib/Db/VersionEntity.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,23 @@ public function setLabel(string $label): void {
7878
$this->metadata['label'] = $label;
7979
$this->markFieldUpdated('metadata');
8080
}
81+
82+
/**
83+
* @abstract given a key, return the value associated with the key in the metadata column
84+
* if nothing is found, we return an empty string
85+
* @param string $key key associated with the value
86+
*/
87+
public function getMetadataValue(string $key): string {
88+
return $this->metadata[$key] ?? '';
89+
}
90+
91+
/**
92+
* @abstract sets a key value pair in the metadata column
93+
* @param string $key key associated with the value
94+
* @param string $value value associated with the key
95+
*/
96+
public function setMetadataValue(string $key, $value): void {
97+
$this->metadata[$key] = $value;
98+
$this->markFieldUpdated('metadata');
99+
}
81100
}

apps/files_versions/lib/Listener/MetadataFileEvents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function post_write_hook(Node $node): void {
6060
}
6161
// check if our version manager supports setting the metadata
6262
if ($this->versionManager instanceof IMetadataVersion) {
63-
$owner = $this->userSession->getUser()->getDisplayName();
63+
$owner = $this->userSession->getUser()->getDisplayName() ?? '';
6464
$this->versionManager->setMetadataValue($node, "owner", $owner);
6565
}
6666
}

apps/files_versions/lib/Listener/MetadetaFileEvents.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

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_OWNER = 'version-owner'; // dav property for owner
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_OWNER, fn () => $node->getOwner());
9699
$propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => $this->previewManager->isMimeSupported($node->getContentType()));
97100
}
98101
}

apps/files_versions/lib/Sabre/VersionFile.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
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;
3334
use OCA\Files_Versions\Versions\IVersionManager;
35+
use OCP\Files\Node;
3436
use OCP\Files\NotFoundException;
3537
use Sabre\DAV\Exception\Forbidden;
3638
use Sabre\DAV\Exception\NotFound;
@@ -109,6 +111,27 @@ public function setLabel($label): bool {
109111
}
110112
}
111113

114+
public function getOwner(): ?string {
115+
$source = $this->version->getSourceFile();
116+
if ($this->versionManager instanceof IMetadataVersion && $source instanceof Node) {
117+
return $this->versionManager->getMetadataValue($source, "owner") ?? '';
118+
}
119+
return null;
120+
}
121+
122+
/**
123+
* @abstract sets the owner in the metadata column
124+
* @param string $owner the value that will be set for the owner in the metadata column
125+
*/
126+
public function setOwner(string $ownerValue): bool {
127+
$source = $this->version->getSourceFile();
128+
if ($this->versionManager instanceof IMetadataVersion && $source instanceof Node) {
129+
$this->versionManager->setMetadataValue($source, "owner", $ownerValue);
130+
return true;
131+
}
132+
return false;
133+
}
134+
112135
public function getLastModified(): int {
113136
return $this->version->getTimestamp();
114137
}

apps/files_versions/lib/Versions/IStoreMetadataBackend.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

apps/files_versions/lib/Versions/LegacyVersionsBackend.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ private function currentUserHasPermissions(IVersion $version, int $permissions):
315315
}
316316

317317
public function setMetadataValue(Node $node, string $key, string $value): void {
318+
if (!($node instanceof File)) {
319+
return;
320+
}
321+
318322
try {
319323
$versionEntity = $this->versionsMapper->findVersionForFileId($node->getId(), $node->getMTime());
320324
} catch (\InvalidArgumentException $e) { // means that we have not created the version

apps/files_versions/lib/Versions/VersionManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public function getMetadataValue(Node $node, string $key): ?string {
174174
if ($backend instanceof IMetadataVersion) {
175175
return $backend->getMetadataValue($node, $key);
176176
}
177+
return null;
177178
}
178179

179180
/**

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-owner />
3435
<nc:has-preview />
3536
</d:prop>
3637
</d:propfind>`

0 commit comments

Comments
 (0)