Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change share owner when moving share out of share
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Jul 26, 2022
commit 13e7ebbe4bfcf117c2d1ed7cc4758327c302bcab
26 changes: 14 additions & 12 deletions apps/files_sharing/lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Updater {
*/
public static function renameHook($params) {
self::renameChildren($params['oldpath'], $params['newpath']);
self::moveShareToShare($params['newpath']);
self::moveShareInOrOutOfShare($params['newpath']);
}

/**
Expand All @@ -51,7 +51,7 @@ public static function renameHook($params) {
*
* @param string $path
*/
private static function moveShareToShare($path) {
private static function moveShareInOrOutOfShare($path): void {
$userFolder = \OC::$server->getUserFolder();

// If the user folder can't be constructed (e.g. link share) just return.
Expand Down Expand Up @@ -85,11 +85,6 @@ private static function moveShareToShare($path) {
// Check if the destination is inside a share
$mountManager = \OC::$server->getMountManager();
$dstMount = $mountManager->find($src->getPath());
if (!($dstMount instanceof \OCA\Files_Sharing\SharedMount)) {
return;
}

$newOwner = $dstMount->getShare()->getShareOwner();

//Ownership is moved over
foreach ($shares as $share) {
Expand All @@ -101,13 +96,20 @@ private static function moveShareToShare($path) {
continue;
}

/** @var IShare $share */
if (!($dstMount->getShare()->getPermissions() & Constants::PERMISSION_SHARE)) {
$shareManager->deleteShare($share);
continue;
if ($dstMount instanceof \OCA\Files_Sharing\SharedMount) {
if (!($dstMount->getShare()->getPermissions() & Constants::PERMISSION_SHARE)) {
Copy link
Contributor

@artonge artonge Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if the destination is a share and does not have the SHARE permission, we delete the current share?

Not sure about the rational.

$shareManager->deleteShare($share);
continue;
}
$newOwner = $dstMount->getShare()->getShareOwner();
$newPermissions = $share->getPermissions() & $dstMount->getShare()->getPermissions();
} else {
$newOwner = $userFolder->getOwner()->getUID();
$newPermissions = $share->getPermissions();
}

$share->setShareOwner($newOwner);
$share->setPermissions($share->getPermissions() & $dstMount->getShare()->getPermissions());
$share->setPermissions($newPermissions);
$shareManager->updateShare($share);
}
}
Expand Down