diff --git a/apps/files_sharing/lib/ShareRecipientUpdater.php b/apps/files_sharing/lib/ShareRecipientUpdater.php index fe1e74c770b..2d8f3bddeab 100644 --- a/apps/files_sharing/lib/ShareRecipientUpdater.php +++ b/apps/files_sharing/lib/ShareRecipientUpdater.php @@ -12,6 +12,8 @@ use OCP\Files\Config\ICachedMountInfo; use OCP\Files\Config\IUserMountCache; use OCP\Files\Storage\IStorageFactory; use OCP\IUser; +use OCP\Share\Exceptions\ShareNotFound; +use OCP\Share\IManager; use OCP\Share\IShare; class ShareRecipientUpdater { @@ -22,6 +24,7 @@ class ShareRecipientUpdater { private readonly MountProvider $shareMountProvider, private readonly ShareTargetValidator $shareTargetValidator, private readonly IStorageFactory $storageFactory, + private readonly IManager $shareManager, ) { } @@ -85,7 +88,12 @@ class ShareRecipientUpdater { * Process a single deleted share for a user */ public function updateForDeletedShare(IUser $user, IShare $share): void { - $this->userMountCache->removeMount($this->getMountPointFromTarget($user, $share->getTarget()), $user); + try { + $userShare = $this->shareManager->getShareById($share->getFullId(), $user->getUID()); + $this->userMountCache->removeMount($this->getMountPointFromTarget($user, $userShare->getTarget()), $user); + } catch (ShareNotFound) { + // user doesn't actually have access to the share + } } /** diff --git a/apps/files_sharing/tests/ShareRecipientUpdaterTest.php b/apps/files_sharing/tests/ShareRecipientUpdaterTest.php index 91c449f5843..ed365385d8d 100644 --- a/apps/files_sharing/tests/ShareRecipientUpdaterTest.php +++ b/apps/files_sharing/tests/ShareRecipientUpdaterTest.php @@ -17,6 +17,7 @@ use OCP\Files\Mount\IMountPoint; use OCP\Files\Node; use OCP\Files\Storage\IStorageFactory; use OCP\IUser; +use OCP\Share\IManager; use OCP\Share\IShare; use PHPUnit\Framework\MockObject\MockObject; use Test\Traits\UserTrait; @@ -29,6 +30,7 @@ class ShareRecipientUpdaterTest extends \Test\TestCase { private ShareTargetValidator&MockObject $shareTargetValidator; private IStorageFactory&MockObject $storageFactory; private ShareRecipientUpdater $updater; + private IManager $shareManager; protected function setUp(): void { parent::setUp(); @@ -37,12 +39,14 @@ class ShareRecipientUpdaterTest extends \Test\TestCase { $this->shareMountProvider = $this->createMock(MountProvider::class); $this->shareTargetValidator = $this->createMock(ShareTargetValidator::class); $this->storageFactory = $this->createMock(IStorageFactory::class); + $this->shareManager = $this->createMock(IManager::class); $this->updater = new ShareRecipientUpdater( $this->userMountCache, $this->shareMountProvider, $this->shareTargetValidator, $this->storageFactory, + $this->shareManager, ); } @@ -192,8 +196,14 @@ class ShareRecipientUpdaterTest extends \Test\TestCase { ->willReturn('/target'); $share->method('getNodeId') ->willReturn(111); + $share->method('getFullId') + ->willReturn('id'); $user1 = $this->createUser('user1', ''); + $this->shareManager->method('getShareById') + ->with('id') + ->willReturn($share); + $this->shareTargetValidator->expects($this->never()) ->method('verifyMountPoint');