aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Share20
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2024-05-02 16:54:34 +0200
committerRobin Appelman <robin@icewind.nl>2024-05-13 16:41:09 +0200
commitdd5d75d86f142bd22b5c7ac724dca2127a2094ab (patch)
treedf88b53e1a8fe10eb0fa242ce59fb4c6d2d87fe3 /lib/private/Share20
parent7101ae8eab3a23b2af1d201d2fd06e1e5a08a7f0 (diff)
downloadnextcloud-server-dd5d75d86f142bd22b5c7ac724dca2127a2094ab.tar.gz
nextcloud-server-dd5d75d86f142bd22b5c7ac724dca2127a2094ab.zip
fix: cleanup logic for getting the max reshare permissions
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Share20')
-rw-r--r--lib/private/Share20/Manager.php58
1 files changed, 8 insertions, 50 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index f9280d75887..76d696eb979 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -45,7 +45,6 @@ use OC\Files\Mount\MoveableMount;
use OC\KnownUser\KnownUserService;
use OC\Share20\Exception\ProviderException;
use OCA\Files_Sharing\AppInfo\Application;
-use OCA\Files_Sharing\ISharedStorage;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Files\Folder;
@@ -295,56 +294,15 @@ class Manager implements IManager {
throw new \InvalidArgumentException('A share requires permissions');
}
- $isFederatedShare = $share->getNode()->getStorage()->instanceOfStorage('\OCA\Files_Sharing\External\Storage');
$permissions = 0;
-
- $isReshare = $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy();
- if (!$isReshare && $isUpdate) {
- // in case of update on owner-less filesystem, we use share owner to improve reshare detection
- $isReshare = $share->getShareOwner() !== $share->getSharedBy();
- }
-
- if (!$isFederatedShare && $isReshare) {
- $userMounts = array_filter($userFolder->getById($share->getNode()->getId()), function ($mount) {
- // We need to filter since there might be other mountpoints that contain the file
- // e.g. if the user has access to the same external storage that the file is originating from
- return $mount->getStorage()->instanceOfStorage(ISharedStorage::class);
- });
- $userMount = array_shift($userMounts);
- if ($userMount === null) {
- throw new GenericShareException('Could not get proper share mount for ' . $share->getNode()->getId() . '. Failing since else the next calls are called with null');
- }
- $mount = $userMount->getMountPoint();
- // When it's a reshare use the parent share permissions as maximum
- $userMountPointId = $mount->getStorageRootId();
- $userMountPoints = $userFolder->getById($userMountPointId);
- $userMountPoint = array_shift($userMountPoints);
-
- if ($userMountPoint === null) {
- throw new GenericShareException('Could not get proper user mount for ' . $userMountPointId . '. Failing since else the next calls are called with null');
- }
-
- /* Check if this is an incoming share */
- $incomingShares = $this->getSharedWith($share->getSharedBy(), IShare::TYPE_USER, $userMountPoint, -1, 0);
- $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_GROUP, $userMountPoint, -1, 0));
- $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_CIRCLE, $userMountPoint, -1, 0));
- $incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_ROOM, $userMountPoint, -1, 0));
-
- /** @var IShare[] $incomingShares */
- if (!empty($incomingShares)) {
- foreach ($incomingShares as $incomingShare) {
- $permissions |= $incomingShare->getPermissions();
- }
- }
- } else {
- /*
- * Quick fix for #23536
- * Non moveable mount points do not have update and delete permissions
- * while we 'most likely' do have that on the storage.
- */
- $permissions = $share->getNode()->getPermissions();
- if (!($share->getNode()->getMountPoint() instanceof MoveableMount)) {
- $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
+ $nodesForUser = $userFolder->getById($share->getNodeId());
+ foreach ($nodesForUser as $node) {
+ if ($node->getInternalPath() === '' && !$node->getMountPoint() instanceof MoveableMount) {
+ // for the root of non-movable mount, the permissions we see if limited by the mount itself,
+ // so we instead use the "raw" permissions from the storage
+ $permissions |= $node->getStorage()->getPermissions('');
+ } else {
+ $permissions |= $node->getPermissions();
}
}