Skip to content

Commit 271a20d

Browse files
authored
Merge pull request #2217 from nextcloud/fix/2148/catch-path-exception
[stable31] fix: catch NotFoundException when user is resharer
2 parents b45c12d + ff88d8c commit 271a20d

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

lib/FilesHooks.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,12 @@ protected function shareNotificationForSharer(string $subject, string $shareWith
10611061
return;
10621062
}
10631063
if (!$path) {
1064-
$path = $this->getUserRelativePath($sharer, $fileSource->getPath());
1064+
try {
1065+
$path = $this->getUserRelativePath($sharer, $fileSource->getPath());
1066+
} catch (NotFoundException $e) {
1067+
$this->logger->warning('Could not create unsharing notification for user ' . $sharer . ' :' . $e->getMessage(), ['exception' => $e]);
1068+
return;
1069+
}
10651070
}
10661071

10671072
$this->addNotificationsForUser(

tests/FilesHooksTest.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class FilesHooksTest extends TestCase {
7878
* @var (OCA\Circles\CirclesManager&MockObject)|null
7979
*/
8080
protected $teamManager;
81+
private LoggerInterface&MockObject $logger;
8182

8283
protected function setUp(): void {
8384
parent::setUp();
@@ -98,6 +99,7 @@ protected function setUp(): void {
9899
$this->tagManager->method('getUsersFavoritingObject')
99100
->willReturn([]);
100101
$this->teamManager = null;
102+
$this->logger = $this->createMock(LoggerInterface::class);
101103

102104
$this->tagManager->method('load')
103105
->willReturn($this->tags);
@@ -118,8 +120,6 @@ protected function getFilesHooks(array $mockedMethods = [], string $user = 'user
118120
$currentUser->expects($this->any())
119121
->method('getUserIdentifier')
120122
->willReturn($user);
121-
/** @var LoggerInterface $logger */
122-
$logger = $this->createMock(LoggerInterface::class);
123123

124124
if (!empty($mockedMethods)) {
125125
return $this->getMockBuilder(FilesHooks::class)
@@ -133,7 +133,7 @@ protected function getFilesHooks(array $mockedMethods = [], string $user = 'user
133133
$this->shareHelper,
134134
\OCP\Server::get(IDBConnection::class),
135135
$this->urlGenerator,
136-
$logger,
136+
$this->logger,
137137
$currentUser,
138138
$this->userMountCache,
139139
$this->config,
@@ -155,7 +155,7 @@ protected function getFilesHooks(array $mockedMethods = [], string $user = 'user
155155
$this->shareHelper,
156156
\OCP\Server::get(IDBConnection::class),
157157
$this->urlGenerator,
158-
$logger,
158+
$this->logger,
159159
$currentUser,
160160
$this->userMountCache,
161161
$this->config,
@@ -917,6 +917,20 @@ public function testShareNotificationForSharer(): void {
917917
self::invokePrivate($filesHooks, 'shareNotificationForSharer', ['subject', 'target', $node]);
918918
}
919919

920+
public function testShareNotificationForSharerException(): void {
921+
$filesHooks = $this->getFilesHooks(['addNotificationsForUser']);
922+
$node = $this->getNodeMock(42, '/admin/files/path');
923+
924+
$this->settings->expects($this->never())
925+
->method('getUserSetting');
926+
$filesHooks->expects($this->never())
927+
->method('addNotificationsForUser');
928+
$this->logger->expects($this->once())
929+
->method('warning');
930+
931+
self::invokePrivate($filesHooks, 'shareNotificationForSharer', ['subject', 'target', $node]);
932+
}
933+
920934
public static function dataAddNotificationsForUser(): array {
921935
return [
922936
['user', 'subject', ['parameter'], 42, 'path/subpath', 'path', true, true, false, Files_Sharing::TYPE_SHARED, 'files_sharing', false],

0 commit comments

Comments
 (0)