Skip to content

Commit

Permalink
Merge pull request #540 from nextcloud/bugfix/noid/wrapper-return-type
Browse files Browse the repository at this point in the history
fix: Adapt return type for Nextcloud 26
  • Loading branch information
max-nextcloud authored Feb 10, 2023
2 parents 085446d + a40379b commit 81f76eb
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 18 deletions.
9 changes: 1 addition & 8 deletions lib/ACL/ACLStorageWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Constants;

class ACLStorageWrapper extends Wrapper {
abstract class ACLStorageWrapper extends Wrapper {
private int $permissions;
private bool $inShare;

Expand Down Expand Up @@ -177,13 +177,6 @@ public function filetype($path) {
return parent::filetype($path);
}

public function filesize($path) {
if (!$this->checkPermissions(Constants::PERMISSION_READ)) {
return false;
}
return parent::filesize($path);
}

public function file_exists($path): bool {
return $this->checkPermissions(Constants::PERMISSION_READ) && parent::file_exists($path);
}
Expand Down
16 changes: 16 additions & 0 deletions lib/ACL/ACLStorageWrapper25.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace OCA\Collectives\ACL;

use OCP\Constants;

class ACLStorageWrapper25 extends ACLStorageWrapper {
public function filesize($path) {
if (!$this->checkPermissions(Constants::PERMISSION_READ)) {
return false;
}
return parent::filesize($path);
}
}
17 changes: 17 additions & 0 deletions lib/ACL/ACLStorageWrapper26.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace OCA\Collectives\ACL;

use OCP\Constants;

class ACLStorageWrapper26 extends ACLStorageWrapper {
/** @psalm-suppress ParseError */
public function filesize($path): float|false|int {
if (!$this->checkPermissions(Constants::PERMISSION_READ)) {
return false;
}
return parent::filesize($path);
}
}
23 changes: 17 additions & 6 deletions lib/Mount/CollectiveFolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use OC\Files\Node\LazyFolder;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\Storage\Wrapper\PermissionsMask;
use OCA\Collectives\ACL\ACLStorageWrapper;
use OCA\Collectives\ACL\ACLStorageWrapper26;
use OCA\Collectives\ACL\ACLStorageWrapper25;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
Expand Down Expand Up @@ -140,11 +141,21 @@ public function getMount(int $id,
// apply acl before jail
if ($user) {
$inShare = $this->getCurrentUID() === null || $this->getCurrentUID() !== $user->getUID();
$storage = new ACLStorageWrapper([
'storage' => $storage,
'permissions' => $permissions,
'in_share' => $inShare
]);
[$major, $minor, $micro] = \OCP\Util::getVersion();
if ($major >= 26) {
/** @psalm-suppress UndefinedClass */
$storage = new ACLStorageWrapper26([
'storage' => $storage,
'permissions' => $permissions,
'in_share' => $inShare
]);
} else {
$storage = new ACLStorageWrapper25([
'storage' => $storage,
'permissions' => $permissions,
'in_share' => $inShare
]);
}
$cacheEntry['permissions'] &= $permissions;
}

Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<projectFiles>
<directory name="lib" />
<ignoreFiles>
<file name="lib/ACL/ACLStorageWrapper26.php" />
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
Expand Down
20 changes: 16 additions & 4 deletions tests/Unit/ACL/ACLStorageWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use OC\Files\Storage\Temporary;
use OCA\Collectives\ACL\ACLStorageWrapper;
use OCA\Collectives\ACL\ACLStorageWrapper25;
use OCA\Collectives\ACL\ACLStorageWrapper26;
use OCP\Constants;
use OCP\Files\Storage\IStorage;
use OCP\IDBConnection;
Expand All @@ -27,7 +29,7 @@ protected function setUp(): void {
public function testNoReadImpliesNothing(): void {
$this->source->mkdir('foo');

$storage = new ACLStorageWrapper([
$storage = $this->createStorage([
'storage' => $this->source,
'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_READ,
'in_share' => false,
Expand All @@ -42,7 +44,7 @@ public function testNoReadImpliesNothing(): void {
public function testInShareWithoutSharingPermissions(): void {
$this->source->mkdir('foo');

$storage = new ACLStorageWrapper([
$storage = $this->createStorage([
'storage' => $this->source,
'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
'in_share' => true,
Expand All @@ -56,7 +58,7 @@ public function testMove(): void {
$this->source->mkdir('foo');
$this->source->touch('file1');

$storage = new ACLStorageWrapper([
$storage = $this->createStorage([
'storage' => $this->source,
'permissions' => Constants::PERMISSION_READ,
'in_share' => false,
Expand All @@ -65,12 +67,22 @@ public function testMove(): void {
$this->assertFalse($storage->rename('file1', 'foo/file1'));


$storage = new ACLStorageWrapper([
$storage = $this->createStorage([
'storage' => $this->source,
'permissions' => Constants::PERMISSION_ALL,
'in_share' => false,
]);

$this->assertTrue($storage->rename('file1', 'foo/file1'));
}

private function createStorage($options): ACLStorageWrapper {
[$major, $minor, $micro] = \OCP\Util::getVersion();
if ($major >= 26) {
/** @psalm-suppress UndefinedClass */
return new ACLStorageWrapper26($options);
} else {
return new ACLStorageWrapper25($options);
}
}
}

0 comments on commit 81f76eb

Please sign in to comment.