Skip to content

Commit 715e714

Browse files
committed
fix(files_sharing,files): Do not validate shares before adjusting the owner
Signed-off-by: provokateurin <[email protected]>
1 parent c2ca99e commit 715e714

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

apps/files/lib/Service/OwnershipTransferService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ private function collectUsersShares(
310310
foreach ($supportedShareTypes as $shareType) {
311311
$offset = 0;
312312
while (true) {
313-
$sharePage = $this->shareManager->getSharesBy($sourceUid, $shareType, null, true, 50, $offset);
313+
$sharePage = $this->shareManager->getSharesBy($sourceUid, $shareType, null, true, 50, $offset, onlyValid: false);
314314
$progress->advance(count($sharePage));
315315
if (empty($sharePage)) {
316316
break;
@@ -464,7 +464,7 @@ private function restoreShares(
464464
}
465465
$share->setNodeId($newNodeId);
466466

467-
$this->shareManager->updateShare($share);
467+
$this->shareManager->updateShare($share, onlyValid: false);
468468
}
469469
}
470470
} catch (NotFoundException $e) {

apps/files_sharing/lib/Updater.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,24 @@ private static function moveShareInOrOutOfShare($path): void {
5050

5151
$shareManager = \OC::$server->getShareManager();
5252

53+
// We intentionally include invalid shares, as they have been automatically invalidated due to the node no longer
54+
// being accessible for the user. Only in this case where we adjust the share after it was moved we want to ignore
55+
// this to be able to still adjust it.
56+
5357
// FIXME: should CIRCLES be included here ??
54-
$shares = $shareManager->getSharesBy($user->getUID(), IShare::TYPE_USER, $src, false, -1);
55-
$shares = array_merge($shares, $shareManager->getSharesBy($user->getUID(), IShare::TYPE_GROUP, $src, false, -1));
56-
$shares = array_merge($shares, $shareManager->getSharesBy($user->getUID(), IShare::TYPE_ROOM, $src, false, -1));
58+
$shares = $shareManager->getSharesBy($user->getUID(), IShare::TYPE_USER, $src, false, -1, onlyValid: false);
59+
$shares = array_merge($shares, $shareManager->getSharesBy($user->getUID(), IShare::TYPE_GROUP, $src, false, -1, onlyValid: false));
60+
$shares = array_merge($shares, $shareManager->getSharesBy($user->getUID(), IShare::TYPE_ROOM, $src, false, -1, onlyValid: false));
5761

5862
if ($src instanceof Folder) {
5963
$cacheAccess = Server::get(FileAccess::class);
6064

6165
$sourceStorageId = $src->getStorage()->getCache()->getNumericStorageId();
6266
$sourceInternalPath = $src->getInternalPath();
6367
$subShares = array_merge(
64-
$shareManager->getSharesBy($user->getUID(), IShare::TYPE_USER),
65-
$shareManager->getSharesBy($user->getUID(), IShare::TYPE_GROUP),
66-
$shareManager->getSharesBy($user->getUID(), IShare::TYPE_ROOM),
68+
$shareManager->getSharesBy($user->getUID(), IShare::TYPE_USER, onlyValid: false),
69+
$shareManager->getSharesBy($user->getUID(), IShare::TYPE_GROUP, onlyValid: false),
70+
$shareManager->getSharesBy($user->getUID(), IShare::TYPE_ROOM, onlyValid: false),
6771
);
6872
$shareSourceIds = array_map(fn (IShare $share) => $share->getNodeId(), $subShares);
6973
$shareSources = $cacheAccess->getByFileIdsInStorage($shareSourceIds, $sourceStorageId);
@@ -111,7 +115,7 @@ private static function moveShareInOrOutOfShare($path): void {
111115

112116
$share->setShareOwner($newOwner);
113117
$share->setPermissions($newPermissions);
114-
$shareManager->updateShare($share);
118+
$shareManager->updateShare($share, onlyValid: false);
115119
}
116120
}
117121

lib/private/Share20/Manager.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -786,13 +786,13 @@ public function createShare(IShare $share) {
786786
* @throws \InvalidArgumentException
787787
* @throws GenericShareException
788788
*/
789-
public function updateShare(IShare $share) {
789+
public function updateShare(IShare $share, bool $onlyValid = true) {
790790
$expirationDateUpdated = false;
791791

792792
$this->canShare($share);
793793

794794
try {
795-
$originalShare = $this->getShareById($share->getFullId());
795+
$originalShare = $this->getShareById($share->getFullId(), onlyValid: $onlyValid);
796796
} catch (\UnexpectedValueException $e) {
797797
throw new \InvalidArgumentException($this->l->t('Share does not have a full ID'));
798798
}
@@ -1241,7 +1241,7 @@ public function getSharesInFolder($userId, Folder $node, $reshares = false, $sha
12411241
/**
12421242
* @inheritdoc
12431243
*/
1244-
public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) {
1244+
public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0, bool $onlyValid = true) {
12451245
if ($path !== null &&
12461246
!($path instanceof \OCP\Files\File) &&
12471247
!($path instanceof \OCP\Files\Folder)) {
@@ -1270,11 +1270,13 @@ public function getSharesBy($userId, $shareType, $path = null, $reshares = false
12701270
while (true) {
12711271
$added = 0;
12721272
foreach ($shares as $share) {
1273-
try {
1274-
$this->checkShare($share);
1275-
} catch (ShareNotFound $e) {
1276-
// Ignore since this basically means the share is deleted
1277-
continue;
1273+
if ($onlyValid) {
1274+
try {
1275+
$this->checkShare($share);
1276+
} catch (ShareNotFound $e) {
1277+
// Ignore since this basically means the share is deleted
1278+
continue;
1279+
}
12781280
}
12791281

12801282
$added++;
@@ -1366,7 +1368,7 @@ public function getDeletedSharedWith($userId, $shareType, $node = null, $limit =
13661368
/**
13671369
* @inheritdoc
13681370
*/
1369-
public function getShareById($id, $recipient = null) {
1371+
public function getShareById($id, $recipient = null, bool $onlyValid = true) {
13701372
if ($id === null) {
13711373
throw new ShareNotFound();
13721374
}
@@ -1381,7 +1383,9 @@ public function getShareById($id, $recipient = null) {
13811383

13821384
$share = $provider->getShareById($id, $recipient);
13831385

1384-
$this->checkShare($share);
1386+
if ($onlyValid) {
1387+
$this->checkShare($share);
1388+
}
13851389

13861390
return $share;
13871391
}

lib/public/Share/IManager.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ public function createShare(IShare $share);
4141
* The state can't be changed this way: use acceptShare
4242
*
4343
* @param IShare $share
44+
* @param bool $onlyValid Only updates valid shares, invalid shares will be deleted automatically and are not updated
4445
* @return IShare The share object
4546
* @throws \InvalidArgumentException
4647
* @since 9.0.0
4748
*/
48-
public function updateShare(IShare $share);
49+
public function updateShare(IShare $share, bool $onlyValid = true);
4950

5051
/**
5152
* Accept a share.
@@ -127,10 +128,11 @@ public function getSharesInFolder($userId, Folder $node, $reshares = false, $sha
127128
* @param bool $reshares
128129
* @param int $limit The maximum number of returned results, -1 for all results
129130
* @param int $offset
131+
* @param bool $onlyValid Only returns valid shares, invalid shares will be deleted automatically and are not returned
130132
* @return IShare[]
131133
* @since 9.0.0
132134
*/
133-
public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0);
135+
public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0, bool $onlyValid = true);
134136

135137
/**
136138
* Get shares shared with $user.
@@ -168,11 +170,12 @@ public function getDeletedSharedWith($userId, $shareType, $node = null, $limit =
168170
*
169171
* @param string $id
170172
* @param string|null $recipient userID of the recipient
173+
* @param bool $onlyValid Only returns valid shares, invalid shares will be deleted automatically and are not returned
171174
* @return IShare
172175
* @throws ShareNotFound
173176
* @since 9.0.0
174177
*/
175-
public function getShareById($id, $recipient = null);
178+
public function getShareById($id, $recipient = null, bool $onlyValid = true);
176179

177180
/**
178181
* Get the share by token possible with password

0 commit comments

Comments
 (0)