Skip to content

Commit

Permalink
feat: Make ISharedStorage public API and reuse where possible
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux authored and AndyScherzinger committed Aug 7, 2024
1 parent 320cfb7 commit 162f9b0
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 22 deletions.
27 changes: 14 additions & 13 deletions apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCP\Files\FileInfo;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\ISharedStorage;
use OCP\Files\StorageNotAvailableException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
Expand Down Expand Up @@ -262,8 +263,8 @@ public function getSharePermissions($user) {
$storage = null;
}

if ($storage && $storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
/** @var \OCA\Files_Sharing\SharedStorage $storage */
if ($storage && $storage->instanceOfStorage(ISharedStorage::class)) {
/** @var ISharedStorage $storage */
$permissions = (int)$storage->getShare()->getPermissions();
} else {
$permissions = $this->info->getPermissions();
Expand Down Expand Up @@ -306,8 +307,8 @@ public function getShareAttributes(): array {
}

$attributes = [];
if (method_exists($storage, 'getShare')) {
/** @var \OCA\Files_Sharing\SharedStorage $storage */
if ($storage->instanceOfStorage(ISharedStorage::class)) {
/** @var ISharedStorage $storage */
$attributes = $storage->getShare()->getAttributes();
if ($attributes === null) {
return [];
Expand All @@ -326,17 +327,17 @@ public function getNoteFromShare(?string $user): string {
return '';
}

if (!method_exists($storage, 'getShare')) {
return '';
$note = '';
if ($storage->instanceOfStorage(ISharedStorage::class)) {
/** @var ISharedStorage $storage */
$share = $storage->getShare();
$note = $share->getNote();
if ($user === $share->getShareOwner()) {
// Note is only for recipient not the owner
return '';
}
}
/** @var \OCA\Files_Sharing\SharedStorage $storage */

$share = $storage->getShare();
$note = $share->getNote();
if ($user === $share->getShareOwner()) {
// Note is only for recipient not the owner
return '';
}
return $note;
}

Expand Down
5 changes: 3 additions & 2 deletions apps/dav/lib/DAV/ViewOnlyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\Files_Versions\Sabre\VersionFile;
use OCP\Files\Folder;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\ISharedStorage;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
Expand Down Expand Up @@ -81,11 +82,11 @@ public function checkViewOnly(RequestInterface $request): bool {

$storage = $node->getStorage();

if (!$storage->instanceOfStorage(\OCA\Files_Sharing\SharedStorage::class)) {
if (!$storage->instanceOfStorage(ISharedStorage::class)) {
return true;
}
// Extract extra permissions
/** @var \OCA\Files_Sharing\SharedStorage $storage */
/** @var ISharedStorage $storage */
$share = $storage->getShare();

$attributes = $share->getAttributes();
Expand Down
3 changes: 2 additions & 1 deletion apps/dav/lib/Storage/PublicShareWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\DAV\Storage;

use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Files\Storage\ISharedStorage;
use OCP\Share\IShare;

class PublicShareWrapper extends Wrapper {

Check notice

Code scanning / Psalm

DeprecatedInterface Note

OCP\Files\Storage is marked deprecated
Expand All @@ -29,7 +30,7 @@ public function __construct($arguments) {
public function getShare(): IShare {
$storage = parent::getWrapperStorage();
if (method_exists($storage, 'getShare')) {
/** @var \OCA\Files_Sharing\SharedStorage $storage */
/** @var ISharedStorage $storage */
return $storage->getShare();
}

Expand Down
7 changes: 5 additions & 2 deletions apps/files_sharing/lib/ISharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*/
namespace OCA\Files_Sharing;

use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\ISharedStorage as PublicISharedStorage;

interface ISharedStorage extends IStorage {
/**
* @deprecated 30.0.0 use `\OCP\Files\Storage\ISharedStorage` instead
*/
interface ISharedStorage extends PublicISharedStorage {
}
7 changes: 3 additions & 4 deletions apps/files_versions/lib/Versions/LegacyVersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
use Exception;
use OC\Files\View;
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
use OCA\Files_Sharing\ISharedStorage;
use OCA\Files_Sharing\SharedStorage;
use OCA\Files_Versions\Db\VersionEntity;
use OCA\Files_Versions\Db\VersionsMapper;
use OCA\Files_Versions\Storage;
Expand All @@ -24,6 +22,7 @@
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\ISharedStorage;
use OCP\Files\Storage\IStorage;
use OCP\IUser;
use OCP\IUserManager;
Expand All @@ -48,7 +47,7 @@ public function useBackendForStorage(IStorage $storage): bool {
public function getVersionsForFile(IUser $user, FileInfo $file): array {
$storage = $file->getStorage();

if ($storage->instanceOfStorage(SharedStorage::class)) {
if ($storage->instanceOfStorage(ISharedStorage::class)) {
$owner = $storage->getOwner('');
$user = $this->userManager->get($owner);

Expand Down Expand Up @@ -192,7 +191,7 @@ public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): Fi

// Shared files have their versions in the owners root folder so we need to obtain them from there
if ($storage->instanceOfStorage(ISharedStorage::class) && $owner) {
/** @var SharedStorage $storage */
/** @var ISharedStorage $storage */
$userFolder = $this->rootFolder->getUserFolder($owner->getUID());
$user = $owner;
$ownerPathInStorage = $sourceFile->getInternalPath();
Expand Down
26 changes: 26 additions & 0 deletions lib/public/Files/Storage/ISharedStorage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Files\Storage;

use OCP\Share\IShare;

/**
* Interface for a storage that is based on a file share
*
* @since 30.0.0
*/
interface ISharedStorage extends IStorage {
/**
* The the associated share
*
* @return IShare
* @since 30.0.0
*/
public function getShare(): IShare;
}

0 comments on commit 162f9b0

Please sign in to comment.