Skip to content

Commit d436dc7

Browse files
committed
feat: Make ISharedStorage public API and reuse where possible
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent cb1b366 commit d436dc7

File tree

13 files changed

+75
-35
lines changed

13 files changed

+75
-35
lines changed

apps/dav/lib/Connector/Sabre/FilesPlugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,14 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
345345
return $node->getNode()->getInternalPath() === '' ? 'true' : 'false';
346346
});
347347

348-
$propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest): string {
348+
$propFind->handle(self::SHARE_NOTE, function () use ($node): null|string {
349349
$user = $this->userSession->getUser();
350350
return $node->getNoteFromShare(
351351
$user?->getUID()
352352
);
353353
});
354354

355-
$propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () use ($node) {
355+
$propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () {
356356
return $this->config->getSystemValue('data-fingerprint', '');
357357
});
358358
$propFind->handle(self::CREATIONDATE_PROPERTYNAME, function () use ($node) {

apps/dav/lib/Connector/Sabre/Node.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OCP\Files\FileInfo;
1717
use OCP\Files\IRootFolder;
1818
use OCP\Files\NotFoundException;
19+
use OCP\Files\Storage\ISharedStorage;
1920
use OCP\Files\StorageNotAvailableException;
2021
use OCP\Share\Exceptions\ShareNotFound;
2122
use OCP\Share\IManager;
@@ -262,8 +263,8 @@ public function getSharePermissions($user) {
262263
$storage = null;
263264
}
264265

265-
if ($storage && $storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
266-
/** @var \OCA\Files_Sharing\SharedStorage $storage */
266+
if ($storage && $storage->instanceOfStorage(ISharedStorage::class)) {
267+
/** @var ISharedStorage $storage */
267268
$permissions = (int)$storage->getShare()->getPermissions();
268269
} else {
269270
$permissions = $this->info->getPermissions();
@@ -306,8 +307,8 @@ public function getShareAttributes(): array {
306307
}
307308

308309
$attributes = [];
309-
if (method_exists($storage, 'getShare')) {
310-
/** @var \OCA\Files_Sharing\SharedStorage $storage */
310+
if ($storage->instanceOfStorage(ISharedStorage::class)) {
311+
/** @var ISharedStorage $storage */
311312
$attributes = $storage->getShare()->getAttributes();
312313
if ($attributes === null) {
313314
return [];
@@ -319,25 +320,24 @@ public function getShareAttributes(): array {
319320
return $attributes;
320321
}
321322

322-
public function getNoteFromShare(?string $user): string {
323+
public function getNoteFromShare(?string $user): string|null {
323324
try {
324325
$storage = $this->node->getStorage();
325326
} catch (NotFoundException) {
326-
return '';
327+
return null;
327328
}
328329

329-
if (!method_exists($storage, 'getShare')) {
330-
return '';
330+
if ($storage->instanceOfStorage(ISharedStorage::class)) {
331+
/** @var ISharedStorage $storage */
332+
$share = $storage->getShare();
333+
if ($user === $share->getShareOwner()) {
334+
// Note is only for recipient not the owner
335+
return null;
336+
}
337+
return $share->getNote();
331338
}
332-
/** @var \OCA\Files_Sharing\SharedStorage $storage */
333339

334-
$share = $storage->getShare();
335-
$note = $share->getNote();
336-
if ($user === $share->getShareOwner()) {
337-
// Note is only for recipient not the owner
338-
return '';
339-
}
340-
return $note;
340+
return null;
341341
}
342342

343343
/**

apps/dav/lib/DAV/ViewOnlyPlugin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCA\Files_Versions\Sabre\VersionFile;
1414
use OCP\Files\Folder;
1515
use OCP\Files\NotFoundException;
16+
use OCP\Files\Storage\ISharedStorage;
1617
use Sabre\DAV\Exception\NotFound;
1718
use Sabre\DAV\Server;
1819
use Sabre\DAV\ServerPlugin;
@@ -81,11 +82,11 @@ public function checkViewOnly(RequestInterface $request): bool {
8182

8283
$storage = $node->getStorage();
8384

84-
if (!$storage->instanceOfStorage(\OCA\Files_Sharing\SharedStorage::class)) {
85+
if (!$storage->instanceOfStorage(ISharedStorage::class)) {
8586
return true;
8687
}
8788
// Extract extra permissions
88-
/** @var \OCA\Files_Sharing\SharedStorage $storage */
89+
/** @var ISharedStorage $storage */
8990
$share = $storage->getShare();
9091

9192
$attributes = $share->getAttributes();

apps/dav/lib/Storage/PublicShareWrapper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
namespace OCA\DAV\Storage;
1010

1111
use OC\Files\Storage\Wrapper\Wrapper;
12+
use OCP\Files\Storage\ISharedStorage;
1213
use OCP\Share\IShare;
1314

14-
class PublicShareWrapper extends Wrapper {
15+
class PublicShareWrapper extends Wrapper implements ISharedStorage {
1516

1617
private IShare $share;
1718

@@ -29,7 +30,7 @@ public function __construct($arguments) {
2930
public function getShare(): IShare {
3031
$storage = parent::getWrapperStorage();
3132
if (method_exists($storage, 'getShare')) {
32-
/** @var \OCA\Files_Sharing\SharedStorage $storage */
33+
/** @var ISharedStorage $storage */
3334
return $storage->getShare();
3435
}
3536

apps/dav/tests/unit/Connector/Sabre/NodeTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use OC\Files\FileInfo;
1212
use OC\Files\Mount\MountPoint;
13+
use OC\Files\Node\Folder;
1314
use OC\Files\View;
1415
use OC\Share20\ShareAttributes;
1516
use OCA\Files_Sharing\SharedMount;
@@ -21,6 +22,7 @@
2122
use OCP\ICache;
2223
use OCP\Share\IManager;
2324
use OCP\Share\IShare;
25+
use PHPUnit\Framework\MockObject\MockObject;
2426

2527
/**
2628
* Class NodeTest
@@ -201,14 +203,16 @@ public function testShareAttributes(): void {
201203

202204
$share->expects($this->once())->method('getAttributes')->willReturn($attributes);
203205

204-
$info = $this->getMockBuilder(FileInfo::class)
206+
/** @var Folder&MockObject $info */
207+
$info = $this->getMockBuilder(Folder::class)
205208
->disableOriginalConstructor()
206-
->setMethods(['getStorage', 'getType'])
209+
->onlyMethods(['getStorage', 'getType'])
207210
->getMock();
208211

209212
$info->method('getStorage')->willReturn($storage);
210213
$info->method('getType')->willReturn(FileInfo::TYPE_FOLDER);
211214

215+
/** @var View&MockObject $view */
212216
$view = $this->getMockBuilder(View::class)
213217
->disableOriginalConstructor()
214218
->getMock();
@@ -225,14 +229,16 @@ public function testShareAttributesNonShare(): void {
225229

226230
$shareManager = $this->getMockBuilder(IManager::class)->disableOriginalConstructor()->getMock();
227231

228-
$info = $this->getMockBuilder(FileInfo::class)
232+
/** @var Folder&MockObject */
233+
$info = $this->getMockBuilder(Folder::class)
229234
->disableOriginalConstructor()
230-
->setMethods(['getStorage', 'getType'])
235+
->onlyMethods(['getStorage', 'getType'])
231236
->getMock();
232237

233238
$info->method('getStorage')->willReturn($storage);
234239
$info->method('getType')->willReturn(FileInfo::TYPE_FOLDER);
235240

241+
/** @var View&MockObject */
236242
$view = $this->getMockBuilder(View::class)
237243
->disableOriginalConstructor()
238244
->getMock();

apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCA\Files_Versions\Versions\IVersion;
1616
use OCP\Files\File;
1717
use OCP\Files\Folder;
18+
use OCP\Files\Storage\ISharedStorage;
1819
use OCP\Files\Storage\IStorage;
1920
use OCP\IUser;
2021
use OCP\Share\IAttributes;
@@ -65,7 +66,7 @@ public function testCanGetNonShared(): void {
6566

6667
$storage = $this->createMock(IStorage::class);
6768
$file->method('getStorage')->willReturn($storage);
68-
$storage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(false);
69+
$storage->method('instanceOfStorage')->with(ISharedStorage::class)->willReturn(false);
6970

7071
$this->assertTrue($this->plugin->checkViewOnly($this->request));
7172
}
@@ -140,7 +141,7 @@ public function testCanGet(bool $isVersion, ?bool $attrEnabled, bool $expectCanD
140141
$nodeInfo->expects($this->once())
141142
->method('getStorage')
142143
->willReturn($storage);
143-
$storage->method('instanceOfStorage')->with(SharedStorage::class)->willReturn(true);
144+
$storage->method('instanceOfStorage')->with(ISharedStorage::class)->willReturn(true);
144145
$storage->method('getShare')->willReturn($share);
145146

146147
$extAttr = $this->createMock(IAttributes::class);

apps/files_sharing/lib/ISharedStorage.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88

99
use OCP\Files\Storage\IStorage;
1010

11+
/**
12+
* @deprecated 30.0.0 use `\OCP\Files\Storage\ISharedStorage` instead
13+
*/
1114
interface ISharedStorage extends IStorage {
1215
}

apps/files_sharing/lib/SharedStorage.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
use OC\Files\Storage\Wrapper\Wrapper;
1919
use OC\User\NoUserException;
2020
use OCA\Files_External\Config\ConfigAdapter;
21+
use OCA\Files_Sharing\ISharedStorage as LegacyISharedStorage;
2122
use OCP\Constants;
2223
use OCP\Files\Cache\ICacheEntry;
2324
use OCP\Files\Config\IUserMountCache;
2425
use OCP\Files\Folder;
2526
use OCP\Files\IHomeStorage;
2627
use OCP\Files\IRootFolder;
27-
use OCP\Files\Node;
2828
use OCP\Files\NotFoundException;
2929
use OCP\Files\Storage\IDisableEncryptionStorage;
30+
use OCP\Files\Storage\ISharedStorage;
3031
use OCP\Files\Storage\IStorage;
3132
use OCP\Lock\ILockingProvider;
3233
use OCP\Share\IShare;
@@ -35,7 +36,7 @@
3536
/**
3637
* Convert target path to source path and pass the function call to the correct storage provider
3738
*/
38-
class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage, IDisableEncryptionStorage {
39+
class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISharedStorage, ISharedStorage, IDisableEncryptionStorage {
3940
/** @var \OCP\Share\IShare */
4041
private $superShare;
4142

apps/files_versions/lib/Versions/LegacyVersionsBackend.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
use Exception;
1313
use OC\Files\View;
1414
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
15-
use OCA\Files_Sharing\ISharedStorage;
16-
use OCA\Files_Sharing\SharedStorage;
1715
use OCA\Files_Versions\Db\VersionEntity;
1816
use OCA\Files_Versions\Db\VersionsMapper;
1917
use OCA\Files_Versions\Storage;
@@ -24,6 +22,7 @@
2422
use OCP\Files\IRootFolder;
2523
use OCP\Files\Node;
2624
use OCP\Files\NotFoundException;
25+
use OCP\Files\Storage\ISharedStorage;
2726
use OCP\Files\Storage\IStorage;
2827
use OCP\IUser;
2928
use OCP\IUserManager;
@@ -48,7 +47,7 @@ public function useBackendForStorage(IStorage $storage): bool {
4847
public function getVersionsForFile(IUser $user, FileInfo $file): array {
4948
$storage = $file->getStorage();
5049

51-
if ($storage->instanceOfStorage(SharedStorage::class)) {
50+
if ($storage->instanceOfStorage(ISharedStorage::class)) {
5251
$owner = $storage->getOwner('');
5352
$user = $this->userManager->get($owner);
5453

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

193192
// Shared files have their versions in the owners root folder so we need to obtain them from there
194193
if ($storage->instanceOfStorage(ISharedStorage::class) && $owner) {
195-
/** @var SharedStorage $storage */
194+
/** @var ISharedStorage $storage */
196195
$userFolder = $this->rootFolder->getUserFolder($owner->getUID());
197196
$user = $owner;
198197
$ownerPathInStorage = $sourceFile->getInternalPath();

build/integration/run-docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ cd "$(dirname $0)"
201201
# "--image XXX" option can be provided to set the Docker image to use to run
202202
# the integration tests (one of the "nextcloudci/phpX.Y:phpX.Y-Z" or
203203
# "ghcr.io/nextcloud/continuous-integration-integration-phpX.Y:latest" images).
204-
NEXTCLOUD_LOCAL_IMAGE="ghcr.io/nextcloud/continuous-integration-integration-php8.1:latest"
204+
NEXTCLOUD_LOCAL_IMAGE="ghcr.io/nextcloud/continuous-integration-integration-php8.2:latest"
205205
if [ "$1" = "--image" ]; then
206206
NEXTCLOUD_LOCAL_IMAGE=$2
207207

0 commit comments

Comments
 (0)