Skip to content

Commit

Permalink
feat: updated plugins - exposes version owner
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 8, 2024
1 parent 0cdc86c commit f1a6ffe
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 102 deletions.
19 changes: 19 additions & 0 deletions apps/files_versions/lib/Db/VersionEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,23 @@ public function setLabel(string $label): void {
$this->metadata['label'] = $label;
$this->markFieldUpdated('metadata');
}

/**
* @abstract given a key, return the value associated with the key in the metadata column
* if nothing is found, we return an empty string
* @param string $key key associated with the value
*/
public function getMetadataValue(string $key): string {
return $this->metadata[$key] ?? '';
}

/**
* @abstract sets a key value pair in the metadata column
* @param string $key key associated with the value
* @param string $value value associated with the key
*/
public function setMetadataValue(string $key, $value): void {
$this->metadata[$key] = $value;
$this->markFieldUpdated('metadata');
}
}
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 IMetadataVersion) {
$owner = $this->userSession->getUser()->getDisplayName();
$owner = $this->userSession->getUser()->getDisplayName() ?? '';

Check notice

Code scanning / Psalm

RedundantConditionGivenDocblockType Note

Docblock-defined type string for $2087 is never null

Check notice

Code scanning / Psalm

PossiblyNullReference Note

Cannot call method getDisplayName on possibly null value

Check notice

Code scanning / Psalm

DocblockTypeContradiction Note

Cannot resolve types for $2087 - docblock-defined type string does not contain null
$this->versionManager->setMetadataValue($node, "owner", $owner);
}
}
Expand Down
58 changes: 0 additions & 58 deletions apps/files_versions/lib/Listener/MetadetaFileEvents.php

This file was deleted.

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_OWNER = 'version-owner'; // dav property for owner

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_OWNER, fn () => $node->getOwner());
$propFind->handle(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, fn () => $this->previewManager->isMimeSupported($node->getContentType()));
}
}
Expand Down
23 changes: 23 additions & 0 deletions apps/files_versions/lib/Sabre/VersionFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
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;
use OCA\Files_Versions\Versions\IVersionManager;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
Expand Down Expand Up @@ -109,6 +111,27 @@ public function setLabel($label): bool {
}
}

public function getOwner(): ?string {
$source = $this->version->getSourceFile();
if ($this->versionManager instanceof IMetadataVersion && $source instanceof Node) {
return $this->versionManager->getMetadataValue($source, "owner") ?? '';
}
return null;
}

/**
* @abstract sets the owner in the metadata column
* @param string $owner the value that will be set for the owner in the metadata column
*/
public function setOwner(string $ownerValue): bool {
$source = $this->version->getSourceFile();
if ($this->versionManager instanceof IMetadataVersion && $source instanceof Node) {
$this->versionManager->setMetadataValue($source, "owner", $ownerValue);
return true;
}
return false;
}

public function getLastModified(): int {
return $this->version->getTimestamp();
}
Expand Down
43 changes: 0 additions & 43 deletions apps/files_versions/lib/Versions/IStoreMetadataBackend.php

This file was deleted.

4 changes: 4 additions & 0 deletions apps/files_versions/lib/Versions/LegacyVersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ private function currentUserHasPermissions(IVersion $version, int $permissions):
}

public function setMetadataValue(Node $node, string $key, string $value): void {
if (!($node instanceof File)) {
return;
}

try {
$versionEntity = $this->versionsMapper->findVersionForFileId($node->getId(), $node->getMTime());
} catch (\InvalidArgumentException $e) { // means that we have not created the version
Expand Down
1 change: 1 addition & 0 deletions apps/files_versions/lib/Versions/VersionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public function getMetadataValue(Node $node, string $key): ?string {
if ($backend instanceof IMetadataVersion) {
return $backend->getMetadataValue($node, $key);
}
return null;
}

/**
Expand Down
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-owner />
<nc:has-preview />
</d:prop>
</d:propfind>`

0 comments on commit f1a6ffe

Please sign in to comment.