Skip to content

Commit 35ef9b0

Browse files
authored
Merge pull request #57667 from nextcloud/bug/noid/avoid-error-when-updating-share
fix(sharing): do not notify remote if owner and sharee are local users
2 parents 9afbad3 + da7250f commit 35ef9b0

3 files changed

Lines changed: 436 additions & 13 deletions

File tree

apps/federatedfilesharing/lib/FederatedShareProvider.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,29 @@ public function update(IShare $share): IShare {
329329
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATETIME_MUTABLE))
330330
->executeStatement();
331331

332-
// send the updated permission to the owner/initiator, if they are not the same
333-
if ($share->getShareOwner() !== $share->getSharedBy()) {
332+
/*
333+
* If the share owner and share initiator are on the same instance,
334+
* then we're done here as the share was just updated above.
335+
*
336+
* However, if the share owner/sharee is on a remote instance (and thus we're dealing with a federated share),
337+
* then we are supposed to let the share owner/ sharee on the remote instance know.
338+
*/
339+
if ($this->shouldNotifyRemote($share)) {
334340
$this->sendPermissionUpdate($share);
335341
}
336342

337343
return $share;
338344
}
339345

346+
/**
347+
* Notify owner/sharee if they are not the same and ANY of them is a remote user.
348+
*/
349+
protected function shouldNotifyRemote(IShare $share): bool {
350+
$ownerOrSharerIsRemoteUser = !$this->userManager->userExists($share->getShareOwner())
351+
|| !$this->userManager->userExists($share->getSharedBy());
352+
return $ownerOrSharerIsRemoteUser && $share->getShareOwner() !== $share->getSharedBy();
353+
}
354+
340355
/**
341356
* Send the updated permission to the owner/initiator, if they are not the same.
342357
*
@@ -466,13 +481,8 @@ public function delete(IShare $share) {
466481
* @throws HintException
467482
*/
468483
protected function revokeShare($share, $isOwner) {
469-
if ($this->userManager->userExists($share->getShareOwner()) && $this->userManager->userExists($share->getSharedBy())) {
470-
// If both the owner and the initiator of the share are local users we don't have to notify anybody else
471-
return;
472-
}
473-
474484
// also send a unShare request to the initiator, if this is a different user than the owner
475-
if ($share->getShareOwner() !== $share->getSharedBy()) {
485+
if ($this->shouldNotifyRemote($share)) {
476486
if ($isOwner) {
477487
[, $remote] = $this->addressHandler->splitUserRemote($share->getSharedBy());
478488
} else {

0 commit comments

Comments
 (0)