Skip to content

Commit 604420b

Browse files
committed
fix(SecureView): node cannot be found when within groupfolder
Signed-off-by: Arthur Schiwon <[email protected]>
1 parent 582c02b commit 604420b

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

lib/PermissionManager.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace OCA\Richdocuments;
1010

1111
use OCP\Constants;
12+
use OCP\Files\Cache\ICacheEntry;
1213
use OCP\Files\Node;
1314
use OCP\IConfig;
1415
use OCP\IGroupManager;
@@ -112,18 +113,19 @@ public function userIsFeatureLocked(?string $userId = null): bool {
112113
return false;
113114
}
114115

115-
public function shouldWatermark(Node $node, ?string $userId = null, ?IShare $share = null): bool {
116+
public function shouldWatermark(Node|ICacheEntry $nodeOrCacheEntry, ?string $userId = null, ?IShare $share = null, ?string $ownerId = null): bool {
116117
if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_enabled', 'no') === 'no') {
117118
return false;
118119
}
119120

120-
if (!in_array($node->getMimetype(), $this->appConfig->getMimeTypes(), true)) {
121+
if (!in_array($nodeOrCacheEntry->getMimetype(), $this->appConfig->getMimeTypes(), true)) {
121122
return false;
122123
}
123124

124-
$fileId = $node->getId();
125-
126-
$isUpdatable = $node->isUpdateable() && (!$share || $share->getPermissions() & Constants::PERMISSION_UPDATE);
125+
$isUpdatable = $nodeOrCacheEntry instanceof Node
126+
? $nodeOrCacheEntry->isUpdateable()
127+
: $nodeOrCacheEntry->getPermissions() & Constants::PERMISSION_UPDATE;
128+
$isUpdatable = $isUpdatable && (!$share || $share->getPermissions() & Constants::PERMISSION_UPDATE);
127129

128130
$hasShareAttributes = $share && method_exists($share, 'getAttributes') && $share->getAttributes() instanceof IAttributes;
129131
$isDisabledDownload = $hasShareAttributes && $share->getAttributes()->getAttribute('permissions', 'download') === false;
@@ -153,7 +155,10 @@ public function shouldWatermark(Node $node, ?string $userId = null, ?IShare $sha
153155
}
154156

155157
if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_shareAll', 'no') === 'yes') {
156-
if ($userId === null || $node->getOwner()?->getUID() !== $userId) {
158+
if (!$ownerId && $nodeOrCacheEntry instanceof Node) {
159+
$ownerId = $nodeOrCacheEntry->getOwner()?->getUID();
160+
}
161+
if ($userId === null || $ownerId !== $userId) {
157162
return true;
158163
}
159164
}

lib/Storage/SecureViewWrapper.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,25 @@ private function shouldSecure(string $path, ?IStorage $sourceStorage = null): bo
8989
fclose($fp);
9090
}
9191

92-
try {
93-
$node = $this->rootFolder->get($this->mountPoint . $path);
94-
} catch (NotFoundException) {
95-
// If the file is just created we may need to check the parent as this is only just about figuring out if it is a share
96-
$node = $this->rootFolder->get(dirname($this->mountPoint . $path));
92+
$storage = $sourceStorage ?? $this;
93+
$cacheEntry = $storage->getCache()->get($path);
94+
if (!$cacheEntry) {
95+
$parent = dirname($path);
96+
if ($parent === '.') {
97+
$parent = '';
98+
}
99+
$cacheEntry = $storage->getCache()->get($parent);
100+
if (!$cacheEntry) {
101+
throw new NotFoundException(sprintf('Could not find cache entry for path and parent of %s within storage %s ', $path, $storage->getId()));
102+
}
97103
}
98104

99-
$isSharedStorage = $node->getStorage()->instanceOfStorage(ISharedStorage::class);
105+
$isSharedStorage = $storage->instanceOfStorage(ISharedStorage::class);
100106

101-
$share = $isSharedStorage ? $node->getStorage()->getShare() : null;
107+
$share = $isSharedStorage ? $storage->getShare() : null;
102108
$userId = $this->userSession->getUser()?->getUID();
103109

104-
return $this->permissionManager->shouldWatermark($node, $userId, $share);
110+
return $this->permissionManager->shouldWatermark($cacheEntry, $userId, $share, $storage->getOwner($path) ?: null);
105111
}
106112

107113

0 commit comments

Comments
 (0)