Skip to content

Commit bcfc3f2

Browse files
Antreesybackportbot[bot]
authored andcommitted
fix(files_sharing): skip unresolvable share recipients
fix(files_sharing): skip unresolvable share recipients Assisted-by: ClaudeCode:claude-opus-4-8 Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com> [skip ci]
1 parent 00ea746 commit bcfc3f2

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

apps/files_sharing/lib/Listener/SharesUpdatedListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use OCP\Share\Events\ShareMovedEvent;
2727
use OCP\Share\Events\ShareTransferredEvent;
2828
use OCP\Share\IManager;
29+
use OCP\User\Exceptions\UserNotFoundException;
2930
use Psr\Clock\ClockInterface;
3031
use Psr\Log\LoggerInterface;
3132

apps/files_sharing/tests/SharesUpdatedListenerTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use OCP\Share\Events\ShareCreatedEvent;
2020
use OCP\Share\IManager;
2121
use OCP\Share\IShare;
22+
use OCP\User\Exceptions\UserNotFoundException;
2223
use PHPUnit\Framework\Attributes\DataProvider;
2324
use PHPUnit\Framework\MockObject\MockObject;
2425
use Psr\Clock\ClockInterface;
@@ -115,6 +116,33 @@ public function testShareAddedFilterOwner() {
115116
$this->sharesUpdatedListener->handle($event);
116117
}
117118

119+
public function testShareAddedSkipsUnresolvableUser(): void {
120+
$share = $this->createMock(IShare::class);
121+
$user1 = $this->createUser('user1', '');
122+
$user2 = $this->createUser('user2', '');
123+
124+
$this->manager->method('getUsersForShare')
125+
->willReturn([$user1, $user2]);
126+
127+
$event = new ShareCreatedEvent($share);
128+
129+
// user1 is an orphaned recipient that no backend can resolve
130+
$this->shareRecipientUpdater
131+
->expects($this->exactly(2))
132+
->method('updateForAddedShare')
133+
->willReturnCallback(function (IUser $user) use ($user1): void {
134+
if ($user === $user1) {
135+
throw new UserNotFoundException('Backends provided no user object');
136+
}
137+
});
138+
139+
// the failure is logged, not thrown
140+
$this->logger->expects($this->once())->method('debug');
141+
142+
// must not throw: user2 is still processed
143+
$this->sharesUpdatedListener->handle($event);
144+
}
145+
118146
public function testShareAccessUpdated() {
119147
$user1 = $this->createUser('user1', '');
120148
$user2 = $this->createUser('user2', '');

0 commit comments

Comments
 (0)