Skip to content

Commit 7ae7ce6

Browse files
committed
Change share owner when moving share out of share
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent ab7771b commit 7ae7ce6

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

apps/files_sharing/lib/Updater.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Updater {
3838
*/
3939
public static function renameHook($params) {
4040
self::renameChildren($params['oldpath'], $params['newpath']);
41-
self::moveShareToShare($params['newpath']);
41+
self::moveShareInOrOutOfShare($params['newpath']);
4242
}
4343

4444
/**
@@ -51,7 +51,7 @@ public static function renameHook($params) {
5151
*
5252
* @param string $path
5353
*/
54-
private static function moveShareToShare($path) {
54+
private static function moveShareInOrOutOfShare($path) {
5555
$userFolder = \OC::$server->getUserFolder();
5656

5757
// If the user folder can't be constructed (e.g. link share) just return.
@@ -85,11 +85,12 @@ private static function moveShareToShare($path) {
8585
// Check if the destination is inside a share
8686
$mountManager = \OC::$server->getMountManager();
8787
$dstMount = $mountManager->find($src->getPath());
88-
if (!($dstMount instanceof \OCA\Files_Sharing\SharedMount)) {
89-
return;
88+
if ($dstMount instanceof \OCA\Files_Sharing\SharedMount) {
89+
$newOwner = $dstMount->getShare()->getShareOwner();
90+
} else {
91+
$newOwner = $userFolder->getOwner()->getUID();
9092
}
9193

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

9495
//Ownership is moved over
9596
foreach ($shares as $share) {
@@ -101,13 +102,18 @@ private static function moveShareToShare($path) {
101102
continue;
102103
}
103104

104-
/** @var IShare $share */
105-
if (!($dstMount->getShare()->getPermissions() & Constants::PERMISSION_SHARE)) {
106-
$shareManager->deleteShare($share);
107-
continue;
105+
if ($dstMount instanceof \OCA\Files_Sharing\SharedMount) {
106+
if (!($dstMount->getShare()->getPermissions() & Constants::PERMISSION_SHARE)) {
107+
$shareManager->deleteShare($share);
108+
continue;
109+
}
110+
$newPermissions = $share->getPermissions() & $dstMount->getShare()->getPermissions();
111+
} else {
112+
$newPermissions = $share->getPermissions();
108113
}
114+
109115
$share->setShareOwner($newOwner);
110-
$share->setPermissions($share->getPermissions() & $dstMount->getShare()->getPermissions());
116+
$share->setPermissions($newPermissions);
111117
$shareManager->updateShare($share);
112118
}
113119
}

0 commit comments

Comments
 (0)