Skip to content

Commit 8ce01e1

Browse files
committed
fix: cleanup logic for getting the max reshare permissions
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 19602a0 commit 8ce01e1

File tree

1 file changed

+9
-49
lines changed

1 file changed

+9
-49
lines changed

lib/private/Share20/Manager.php

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
use OC\KnownUser\KnownUserService;
4646
use OC\Share20\Exception\ProviderException;
4747
use OCA\Files_Sharing\AppInfo\Application;
48-
use OCA\Files_Sharing\ISharedStorage;
48+
use OCA\Files_Sharing\SharedMount;
4949
use OCP\EventDispatcher\IEventDispatcher;
5050
use OCP\Files\File;
5151
use OCP\Files\Folder;
@@ -294,55 +294,15 @@ protected function generalCreateChecks(IShare $share, bool $isUpdate = false) {
294294
throw new \InvalidArgumentException('A share requires permissions');
295295
}
296296

297-
$isFederatedShare = $share->getNode()->getStorage()->instanceOfStorage('\OCA\Files_Sharing\External\Storage');
298297
$permissions = 0;
299-
300-
$isReshare = $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy();
301-
if (!$isReshare && $isUpdate) {
302-
// in case of update on owner-less filesystem, we use share owner to improve reshare detection
303-
$isReshare = $share->getShareOwner() !== $share->getSharedBy();
304-
}
305-
306-
if (!$isFederatedShare && $isReshare) {
307-
$userMounts = array_filter($userFolder->getById($share->getNode()->getId()), function ($mount) {
308-
// We need to filter since there might be other mountpoints that contain the file
309-
// e.g. if the user has access to the same external storage that the file is originating from
310-
return $mount->getStorage()->instanceOfStorage(ISharedStorage::class);
311-
});
312-
$userMount = array_shift($userMounts);
313-
if ($userMount === null) {
314-
throw new GenericShareException('Could not get proper share mount for ' . $share->getNode()->getId() . '. Failing since else the next calls are called with null');
315-
}
316-
$mount = $userMount->getMountPoint();
317-
// When it's a reshare use the parent share permissions as maximum
318-
$userMountPointId = $mount->getStorageRootId();
319-
$userMountPoint = $userFolder->getFirstNodeById($userMountPointId);
320-
321-
if ($userMountPoint === null) {
322-
throw new GenericShareException('Could not get proper user mount for ' . $userMountPointId . '. Failing since else the next calls are called with null');
323-
}
324-
325-
/* Check if this is an incoming share */
326-
$incomingShares = $this->getSharedWith($share->getSharedBy(), IShare::TYPE_USER, $userMountPoint, -1, 0);
327-
$incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_GROUP, $userMountPoint, -1, 0));
328-
$incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_CIRCLE, $userMountPoint, -1, 0));
329-
$incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_ROOM, $userMountPoint, -1, 0));
330-
331-
/** @var IShare[] $incomingShares */
332-
if (!empty($incomingShares)) {
333-
foreach ($incomingShares as $incomingShare) {
334-
$permissions |= $incomingShare->getPermissions();
335-
}
336-
}
337-
} else {
338-
/*
339-
* Quick fix for #23536
340-
* Non moveable mount points do not have update and delete permissions
341-
* while we 'most likely' do have that on the storage.
342-
*/
343-
$permissions = $share->getNode()->getPermissions();
344-
if (!($share->getNode()->getMountPoint() instanceof MoveableMount)) {
345-
$permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
298+
$nodesForUser = $userFolder->getById($share->getNodeId());
299+
foreach ($nodesForUser as $node) {
300+
if ($node->getInternalPath() === '' && !$node->getMountPoint() instanceof MoveableMount) {
301+
// for the root of non-movable mount, the permissions we see if limited by the mount itself,
302+
// so we instead use the "raw" permissions from the storage
303+
$permissions |= $node->getStorage()->getPermissions('');
304+
} else {
305+
$permissions |= $node->getPermissions();
346306
}
347307
}
348308

0 commit comments

Comments
 (0)