Skip to content

Commit e23b802

Browse files
CarlSchwanbackportbot[bot]
authored andcommitted
fix: Don't auto complete nor allow sharing to disabled users
Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Carl Schwan <carl@carlschwan.eu> [skip ci]
1 parent f1408cf commit e23b802

7 files changed

Lines changed: 34 additions & 10 deletions

File tree

‎apps/files_sharing/tests/Listener/RestrictInteractionListenerTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function testNodeResourceShareActionNoLinkEmailReceiverMissingReadPermiss
177177
new RemoteGroupReceiver(''),
178178
new RemoteUserReceiver(''),
179179
new RoomReceiver(''),
180-
new UserReceiver(''),
180+
new UserReceiver($this->user->getUID(), $this->user),
181181
] as $receiver) {
182182
$event = new RestrictInteractionEvent($this->user->getUID(), $this->user, [$resource], new ShareAction(Constants::PERMISSION_ALL & ~Constants::PERMISSION_READ), [$receiver]);
183183
$this->assertEquals('File share needs at least read permission.', $event->isInteractionRestricted());

‎core/Listener/RestrictInteractionListener.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public function handle(Event $event): void {
5555
}
5656

5757
foreach ($event->receivers as $receiver) {
58+
if ($receiver instanceof UserReceiver && !$receiver->getUser()->isEnabled()) {
59+
throw new InteractionRestrictedException('Sharing with a disabled account is not allowed.', $this->l10n->t('Cannot share with a disabled account.'));
60+
}
61+
5862
if ($this->manager->shareWithGroupMembersOnly()) {
5963
if ($receiver instanceof UserReceiver) {
6064
$groups = array_intersect(

‎lib/private/Collaboration/Collaborators/MailPlugin.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
127127

128128
if (isset($contact['isLocalSystemBook'])) {
129129
$contactUser = $this->userManager->get($contact['UID']);
130-
if ($contactUser === null) {
130+
if ($contactUser === null || !$contactUser->isEnabled()) {
131131
continue;
132132
}
133133

‎lib/private/Collaboration/Collaborators/RemotePlugin.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
7373
}
7474

7575
$localUser = $this->userManager->get($remoteUser);
76-
if ($localUser !== null && $remoteUser !== $this->userId && $cloudId === $localUser->getCloudId()) {
76+
if ($localUser !== null && $localUser->isEnabled() && $remoteUser !== $this->userId && $cloudId === $localUser->getCloudId()) {
7777
$result['wide'][] = [
7878
'label' => $contact['FN'],
7979
'uuid' => $contact['UID'],

‎tests/Core/Listener/RestrictInteractionListenerTest.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ public function testShareActionDisabledForUser(): void {
8686
$this->assertTrue($group->delete());
8787
}
8888

89+
public function testShareActionUserReceiverDisabled(): void {
90+
$user2 = Server::get(IUserManager::class)->createUser('user2', 'password');
91+
$this->assertNotFalse($user2);
92+
93+
$event = new RestrictInteractionEvent($this->user->getUID(), $this->user, [], new ShareAction(), [new UserReceiver($user2->getUID(), $user2)]);
94+
$this->assertFalse($event->isInteractionRestricted());
95+
96+
$user2->setEnabled(false);
97+
98+
$event = new RestrictInteractionEvent($this->user->getUID(), $this->user, [], new ShareAction(), [new UserReceiver($user2->getUID(), $user2)]);
99+
$this->assertEquals('Cannot share with a disabled account.', $event->isInteractionRestricted());
100+
101+
$this->assertTrue($user2->delete());
102+
}
103+
89104
/** @psalm-suppress DeprecatedMethod The configs are not migrated to IAppConfig, so using deprecated IConfig is required for now. */
90105
public function testShareActionUserReceiverGroupMembersOnly(): void {
91106
$user2 = Server::get(IUserManager::class)->createUser('user2', 'password');

‎tests/lib/Collaboration/Collaborators/MailPluginTest.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ protected function setUp(): void {
5858
$user
5959
->method('getUID')
6060
->willReturn($uid);
61+
$user
62+
->method('isEnabled')
63+
->willReturn(!str_starts_with($uid, 'disabled'));
6164

6265
return $user;
6366
});

‎tests/lib/Share20/ManagerTest.php‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,11 +2266,11 @@ public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup(): void
22662266
->setNode($node)
22672267
->setPermissions(Constants::PERMISSION_ALL);
22682268

2269-
$sharedBy = $this->createMock(IUser::class);
2269+
$sharedBy = $this->createEnabledUser(true);
22702270
$sharedBy
22712271
->method('getUID')
22722272
->willReturn('sharedBy');
2273-
$sharedWith = $this->createMock(IUser::class);
2273+
$sharedWith = $this->createEnabledUser(true);
22742274

22752275
$this->groupManager
22762276
->method('getUserGroupIds')
@@ -2456,8 +2456,8 @@ public function testUserCreateChecksIdenticalPathNotSharedWithUser(): void {
24562456
->setProviderId('foo')
24572457
->setId('bar');
24582458

2459-
$sharedWith = $this->createMock(IUser::class);
2460-
$sharedBy = $this->createMock(IUser::class);
2459+
$sharedWith = $this->createEnabledUser(true);
2460+
$sharedBy = $this->createEnabledUser(true);
24612461
$sharedBy
24622462
->method('getUID')
24632463
->willReturn('sharedBy');
@@ -3271,15 +3271,17 @@ public function testCanShare($expected, $sharingEnabled, $disabledForUser): void
32713271
->with('user1')
32723272
->willReturn($userFolder);
32733273

3274-
$user1 = $this->createMock(IUser::class);
3274+
$user1 = $this->createEnabledUser(true);
32753275
$user1
32763276
->method('getUID')
32773277
->willReturn('user1');
32783278

32793279
$this->userManager
32803280
->method('get')
3281-
->with('user1')
3282-
->willReturn($user1);
3281+
->willReturnMap([
3282+
['user1', $user1],
3283+
['user2', $this->createEnabledUser(true)],
3284+
]);
32833285

32843286
$share = $this->manager->newShare()
32853287
->setShareType(IShare::TYPE_USER)

0 commit comments

Comments
 (0)