Skip to content

Commit 6732738

Browse files
committed
fix(files_sharing): skip unresolvable share recipients
Assisted-by: ClaudeCode:claude-opus-4-8 Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent 5b11d78 commit 6732738

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

apps/files_sharing/lib/Listener/SharesUpdatedListener.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace OCA\Files_Sharing\Listener;
1010

11+
use OC\User\NoUserException;
1112
use OCA\Files_Sharing\AppInfo\Application;
1213
use OCA\Files_Sharing\Config\ConfigLexicon;
1314
use OCA\Files_Sharing\Event\UserShareAccessUpdatedEvent;
@@ -135,7 +136,14 @@ private function markOrRun(IUser $user, callable $callback): void {
135136
$elapsed = $now - $this->firstRun;
136137

137138
if ($this->cutOffMarkTime === -1.0 || $elapsed < $this->cutOffMarkTime) {
138-
$callback();
139+
try {
140+
$callback();
141+
} catch (NoUserException $e) {
142+
// A share recipient may reference a user id that no backend can resolve anymore
143+
// (e.g. with LazyUser::getUID()) - like remnant / incorrectly removed user.
144+
// Skip this recipient instead of aborting the share operation.
145+
$this->logger->debug('Skipping share mount update for unresolvable user ' . $user->getUID(), ['exception' => $e]);
146+
}
139147
} else {
140148
$this->markUserForRefresh($user);
141149
}

apps/files_sharing/tests/SharesUpdatedListenerTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace OCA\Files_Sharing\Tests;
99

10+
use OC\User\NoUserException;
1011
use OCA\Files_Sharing\Config\ConfigLexicon;
1112
use OCA\Files_Sharing\Event\UserShareAccessUpdatedEvent;
1213
use OCA\Files_Sharing\Listener\SharesUpdatedListener;
@@ -117,6 +118,33 @@ public function testShareAddedFilterOwner() {
117118
$this->sharesUpdatedListener->handle($event);
118119
}
119120

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

0 commit comments

Comments
 (0)