Skip to content

Commit

Permalink
Merge pull request nextcloud#44558 from nextcloud/backport/44339/stab…
Browse files Browse the repository at this point in the history
…le23

[stable23] fix(share): use share owner to get ownership
  • Loading branch information
blizzz authored Apr 24, 2024
2 parents a11eae4 + f9cf7d8 commit 309f618
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ protected function verifyPassword($password) {
*
* @suppress PhanUndeclaredClassMethod
*/
protected function generalCreateChecks(IShare $share) {
protected function generalCreateChecks(IShare $share, bool $isUpdate = false) {
if ($share->getShareType() === IShare::TYPE_USER) {
// We expect a valid user as sharedWith for user shares
if (!$this->userManager->userExists($share->getSharedWith())) {
Expand Down Expand Up @@ -295,8 +295,14 @@ protected function generalCreateChecks(IShare $share) {

$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 && $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $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
Expand Down Expand Up @@ -982,7 +988,7 @@ public function updateShare(IShare $share) {
throw new \InvalidArgumentException('Cannot share with the share owner');
}

$this->generalCreateChecks($share);
$this->generalCreateChecks($share, true);

if ($share->getShareType() === IShare::TYPE_USER) {
$this->userCreateChecks($share);
Expand Down

0 comments on commit 309f618

Please sign in to comment.