diff options
author | Louis Chemineau <louis@chmn.me> | 2022-11-29 16:26:54 +0100 |
---|---|---|
committer | Louis (Rebase PR Action) <artonge@users.noreply.github.com> | 2023-01-26 10:12:23 +0000 |
commit | 6a2f8bc5997a4b40baf8b967d6d8ccdf29735d3b (patch) | |
tree | 116fa4a442c97ac44839e14460b797d50f77e4f2 /apps/files_versions | |
parent | 629de6c8c97f9a455944046737421b927b1e2d9b (diff) | |
download | nextcloud-server-6a2f8bc5997a4b40baf8b967d6d8ccdf29735d3b.tar.gz nextcloud-server-6a2f8bc5997a4b40baf8b967d6d8ccdf29735d3b.zip |
Allow to delete a version through DAV
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'apps/files_versions')
-rw-r--r-- | apps/files_versions/lib/Capabilities.php | 3 | ||||
-rw-r--r-- | apps/files_versions/lib/Sabre/VersionFile.php | 8 | ||||
-rw-r--r-- | apps/files_versions/lib/Storage.php | 11 | ||||
-rw-r--r-- | apps/files_versions/lib/Versions/IDeletableVersionBackend.php | 36 | ||||
-rw-r--r-- | apps/files_versions/lib/Versions/LegacyVersionsBackend.php | 9 | ||||
-rw-r--r-- | apps/files_versions/lib/Versions/VersionManager.php | 9 | ||||
-rw-r--r-- | apps/files_versions/src/components/Version.vue | 4 |
7 files changed, 74 insertions, 6 deletions
diff --git a/apps/files_versions/lib/Capabilities.php b/apps/files_versions/lib/Capabilities.php index 031cabb83ec..6524943690a 100644 --- a/apps/files_versions/lib/Capabilities.php +++ b/apps/files_versions/lib/Capabilities.php @@ -46,12 +46,13 @@ class Capabilities implements ICapability { * @return array */ public function getCapabilities() { - $groupFolderOrS3VersioningInstalled = $this->appManager->isInstalled('groupfolders') || !$this->appManager->isInstalled('groupfolders'); + $groupFolderOrS3VersioningInstalled = $this->appManager->isInstalled('groupfolders') || $this->appManager->isInstalled('groupfolders'); return [ 'files' => [ 'versioning' => true, 'version_labeling' => !$groupFolderOrS3VersioningInstalled && $this->config->getSystemValueBool('enable_version_labeling', true), + 'version_deletion' => !$groupFolderOrS3VersioningInstalled && $this->config->getSystemValueBool('enable_version_deletion', true), ] ]; } diff --git a/apps/files_versions/lib/Sabre/VersionFile.php b/apps/files_versions/lib/Sabre/VersionFile.php index 9018f75703d..12590fe9efd 100644 --- a/apps/files_versions/lib/Sabre/VersionFile.php +++ b/apps/files_versions/lib/Sabre/VersionFile.php @@ -26,6 +26,7 @@ declare(strict_types=1); */ namespace OCA\Files_Versions\Sabre; +use OCA\Files_Versions\Versions\IDeletableVersionBackend; use OCA\Files_Versions\Versions\INameableVersion; use OCA\Files_Versions\Versions\INameableVersionBackend; use OCA\Files_Versions\Versions\IVersion; @@ -72,8 +73,11 @@ class VersionFile implements IFile { } public function delete() { - // TODO: implement version deletion - throw new Forbidden(); + if ($this->versionManager instanceof IDeletableVersionBackend) { + $this->versionManager->deleteVersion($this->version); + } else { + throw new Forbidden(); + } } public function getName(): string { diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php index 024e1debc92..2f56397ebb8 100644 --- a/apps/files_versions/lib/Storage.php +++ b/apps/files_versions/lib/Storage.php @@ -291,6 +291,17 @@ class Storage { } /** + * Delete a version of a file + */ + public static function deleteRevision(string $path, int $revision): void { + [$uid, $filename] = self::getUidAndFilename($path); + $view = new View('/' . $uid . '/files_versions'); + \OC_Hook::emit('\OCP\Versions', 'preDelete', ['path' => $path . $revision, 'trigger' => self::DELETE_TRIGGER_MASTER_REMOVED]); + self::deleteVersion($view, $filename . '.v' . $revision); + \OC_Hook::emit('\OCP\Versions', 'delete', ['path' => $path . $revision, 'trigger' => self::DELETE_TRIGGER_MASTER_REMOVED]); + } + + /** * Rename or copy versions of a file of the given paths * * @param string $sourcePath source path of the file to move, relative to diff --git a/apps/files_versions/lib/Versions/IDeletableVersionBackend.php b/apps/files_versions/lib/Versions/IDeletableVersionBackend.php new file mode 100644 index 00000000000..abb43d09d90 --- /dev/null +++ b/apps/files_versions/lib/Versions/IDeletableVersionBackend.php @@ -0,0 +1,36 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022 Louis Chmn <louis@chmn.me> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +namespace OCA\Files_Versions\Versions; + +/** + * @since 26.0.0 + */ +interface IDeletableVersionBackend { + /** + * Delete a version. + * + * @since 26.0.0 + */ + public function deleteVersion(IVersion $version): void; +} diff --git a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php index 90c7cb930d5..d5ca4d2a11c 100644 --- a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php +++ b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php @@ -187,4 +187,13 @@ class LegacyVersionsBackend implements IVersionBackend, INameableVersionBackend, $versionEntity->setLabel($label ?? ''); $this->versionsMapper->update($versionEntity); } + + public function deleteVersion(IVersion $version): void { + Storage::deleteRevision($version->getVersionPath(), $version->getRevisionId()); + $versionEntity = $this->versionsMapper->findVersionForFileId( + $version->getSourceFile()->getId(), + $version->getTimestamp(), + ); + $this->versionsMapper->delete($versionEntity); + } } diff --git a/apps/files_versions/lib/Versions/VersionManager.php b/apps/files_versions/lib/Versions/VersionManager.php index 4787de7fdac..bfae0937df8 100644 --- a/apps/files_versions/lib/Versions/VersionManager.php +++ b/apps/files_versions/lib/Versions/VersionManager.php @@ -30,7 +30,7 @@ use OCP\Files\FileInfo; use OCP\Files\Storage\IStorage; use OCP\IUser; -class VersionManager implements IVersionManager, INameableVersionBackend { +class VersionManager implements IVersionManager, INameableVersionBackend, IDeletableVersionBackend { /** @var (IVersionBackend[])[] */ private $backends = []; @@ -117,4 +117,11 @@ class VersionManager implements IVersionManager, INameableVersionBackend { $backend->setVersionLabel($version, $label); } } + + public function deleteVersion(IVersion $version): void { + $backend = $this->getBackendForStorage($version->getSourceFile()->getStorage()); + if ($backend instanceof IDeletableVersionBackend) { + $backend->deleteVersion($version); + } + } } diff --git a/apps/files_versions/src/components/Version.vue b/apps/files_versions/src/components/Version.vue index a06d6a0ba8e..8aafabddfad 100644 --- a/apps/files_versions/src/components/Version.vue +++ b/apps/files_versions/src/components/Version.vue @@ -62,7 +62,7 @@ </template> {{ t('files_versions', 'Download version') }} </NcActionLink> - <NcActionButton v-if="!isCurrent" + <NcActionButton v-if="!isCurrent && capabilities.files.version_deletion === true" :close-after-click="true" @click="deleteVersion"> <template #icon> @@ -175,7 +175,7 @@ export default { return { showVersionLabelForm: false, formVersionLabelValue: this.version.label, - capabilities: loadState('core', 'capabilities', { files: { version_labeling: false } }), + capabilities: loadState('core', 'capabilities', { files: { version_labeling: false, version_deletion: false } }), } }, computed: { |