From 030d1f2a70a0b7680787d98dc9c11ef2d2b6066e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 14 Aug 2025 11:02:50 +0200 Subject: [PATCH 1/2] fix: use target path for unshare-from-self events Signed-off-by: Robin Appelman --- lib/FilesHooks.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/FilesHooks.php b/lib/FilesHooks.php index 8641dea56..68fe7c2df 100644 --- a/lib/FilesHooks.php +++ b/lib/FilesHooks.php @@ -827,7 +827,7 @@ public function unShareSelf(IShare $share) { if ($share->getShareType() === IShare::TYPE_GROUP) { $this->unshareFromSelfGroup($share); } else { - $this->unShare($share); + $this->unshareFromUser($share); } } } @@ -879,7 +879,7 @@ protected function unshareFromUser(IShare $share) { */ protected function selfUnshareFromUser(IShare $share) { // User performing the share - $this->shareNotificationForSharer('self_unshared', $share->getSharedWith(), $share->getNode()); + $this->shareNotificationForSharer('self_unshared', $share->getSharedWith(), $share->getNode(), $share->getTarget()); // Owner if ($this->currentUser->getUID() !== null) { @@ -936,7 +936,7 @@ protected function unshareFromGroup(IShare $share) { */ protected function unshareFromSelfGroup(IShare $share) { // User performing the unshare - $this->shareNotificationForSharer('self_unshared', $this->currentUser->getUID(), $share->getNode()); + $this->shareNotificationForSharer('self_unshared', $this->currentUser->getUID(), $share->getNode(), $share->getTarget()); // Owner if ($this->currentUser->getUID() !== null) { @@ -1056,12 +1056,14 @@ protected function fixPathsForShareExceptions(array $affectedUsers, $shareId) { * @param string $shareWith * @param Node $fileSource */ - protected function shareNotificationForSharer(string $subject, string $shareWith, Node $fileSource) { + protected function shareNotificationForSharer(string $subject, string $shareWith, Node $fileSource, ?string $path = null) { $sharer = $this->currentUser->getUID(); if ($sharer === null) { return; } - $path = $this->getUserRelativePath($sharer, $fileSource->getPath()); + if (!$path) { + $path = $this->getUserRelativePath($sharer, $fileSource->getPath()); + } $this->addNotificationsForUser( $sharer, $subject, [[$fileSource->getId() => $path], $shareWith], From cccf42bf9eb1e7e00534197ca1eb6c8bdfe022ae Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 14 Aug 2025 11:33:01 +0200 Subject: [PATCH 2/2] test: add test for leave share activity Signed-off-by: Robin Appelman --- tests/FilesHooksTest.php | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/FilesHooksTest.php b/tests/FilesHooksTest.php index 43d8b5640..302a95a75 100644 --- a/tests/FilesHooksTest.php +++ b/tests/FilesHooksTest.php @@ -1007,4 +1007,48 @@ public function testAddNotificationsForUser(string $user, string $subject, array self::invokePrivate($this->filesHooks, 'addNotificationsForUser', [$user, $subject, $parameter, $fileId, $path, $isFile, $email, $notification, $type]); } + + public function testLeaveShare(): void { + $filesHooks = $this->getFilesHooks([ + 'addNotificationsForUser', + 'shareNotificationForOriginalOwners', + ], 'with'); + + $node = $this->getNodeMock(42, '/user/files/path'); + $share = $this->createMock(IShare::class); + $share->method('getNode') + ->willReturn($node); + $share->method('getTarget') + ->willReturn('/target'); + $share->method('getNodeType') + ->willReturn('file'); + $share->method('getSharedWith') + ->willReturn('with'); + + $this->settings->expects($this->exactly(3)) + ->method('getUserSetting') + ->willReturnMap([ + ['with', 'notification', Files_Sharing::TYPE_SHARED, true], + ['with', 'email', Files_Sharing::TYPE_SHARED, true], + ['with', 'setting', 'batchtime', 21], + ]); + + $filesHooks->expects($this->once()) + ->method('addNotificationsForUser') + ->with( + 'with', + 'self_unshared', + [[42 => '/target'], 'with'], + 42, + '/target', + true, + true, + 21 + ); + $filesHooks->expects($this->once()) + ->method('shareNotificationForOriginalOwners') + ->with('with', 'self_unshared_by', 'with', $node); + + self::invokePrivate($filesHooks, 'unShareSelf', [$share]); + } }