Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,12 @@ protected function shareNotificationForSharer(string $subject, string $shareWith
return;
}
if (!$path) {
$path = $this->getUserRelativePath($sharer, $fileSource->getPath());
try {
$path = $this->getUserRelativePath($sharer, $fileSource->getPath());
} catch (NotFoundException $e) {
$this->logger->warning('Could not create unsharing notification for user ' . $sharer . ' :' . $e->getMessage(), ['exception' => $e]);
return;
}
}

$this->addNotificationsForUser(
Expand Down
22 changes: 18 additions & 4 deletions tests/FilesHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class FilesHooksTest extends TestCase {
* @var (OCA\Circles\CirclesManager&MockObject)|null
*/
protected $teamManager;
private LoggerInterface&MockObject $logger;

protected function setUp(): void {
parent::setUp();
Expand All @@ -98,6 +99,7 @@ protected function setUp(): void {
$this->tagManager->method('getUsersFavoritingObject')
->willReturn([]);
$this->teamManager = null;
$this->logger = $this->createMock(LoggerInterface::class);

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

if (!empty($mockedMethods)) {
return $this->getMockBuilder(FilesHooks::class)
Expand All @@ -133,7 +133,7 @@ protected function getFilesHooks(array $mockedMethods = [], string $user = 'user
$this->shareHelper,
\OCP\Server::get(IDBConnection::class),
$this->urlGenerator,
$logger,
$this->logger,
$currentUser,
$this->userMountCache,
$this->config,
Expand All @@ -155,7 +155,7 @@ protected function getFilesHooks(array $mockedMethods = [], string $user = 'user
$this->shareHelper,
\OCP\Server::get(IDBConnection::class),
$this->urlGenerator,
$logger,
$this->logger,
$currentUser,
$this->userMountCache,
$this->config,
Expand Down Expand Up @@ -917,6 +917,20 @@ public function testShareNotificationForSharer(): void {
self::invokePrivate($filesHooks, 'shareNotificationForSharer', ['subject', 'target', $node]);
}

public function testShareNotificationForSharerException(): void {
$filesHooks = $this->getFilesHooks(['addNotificationsForUser']);
$node = $this->getNodeMock(42, '/admin/files/path');

$this->settings->expects($this->never())
->method('getUserSetting');
$filesHooks->expects($this->never())
->method('addNotificationsForUser');
$this->logger->expects($this->once())
->method('warning');

self::invokePrivate($filesHooks, 'shareNotificationForSharer', ['subject', 'target', $node]);
}

public static function dataAddNotificationsForUser(): array {
return [
['user', 'subject', ['parameter'], 42, 'path/subpath', 'path', true, true, false, Files_Sharing::TYPE_SHARED, 'files_sharing', false],
Expand Down
Loading