diff --git a/apps/files_sharing/tests/Listener/RestrictInteractionListenerTest.php b/apps/files_sharing/tests/Listener/RestrictInteractionListenerTest.php index a1503240deccf..ddadb7650cc56 100644 --- a/apps/files_sharing/tests/Listener/RestrictInteractionListenerTest.php +++ b/apps/files_sharing/tests/Listener/RestrictInteractionListenerTest.php @@ -197,7 +197,7 @@ public function testNodeResourceShareActionNoLinkEmailReceiverMissingReadPermiss new RemoteGroupReceiver(''), new RemoteUserReceiver(''), new RoomReceiver(''), - new UserReceiver(''), + new UserReceiver($this->user->getUID(), $this->user), ] as $receiver) { foreach ([ new ShareAction(Constants::PERMISSION_ALL & ~Constants::PERMISSION_READ), diff --git a/core/Listener/RestrictInteractionListener.php b/core/Listener/RestrictInteractionListener.php index e7441d3148db6..ef6fea7703932 100644 --- a/core/Listener/RestrictInteractionListener.php +++ b/core/Listener/RestrictInteractionListener.php @@ -55,6 +55,10 @@ public function handle(Event $event): void { } foreach ($event->receivers as $receiver) { + if ($receiver instanceof UserReceiver && !$receiver->getUser()->isEnabled()) { + throw new InteractionRestrictedException('Sharing with a disabled account is not allowed.', $this->l10n->t('Cannot share with a disabled account.')); + } + if ($this->manager->shareWithGroupMembersOnly()) { if ($receiver instanceof UserReceiver) { $groups = array_intersect( diff --git a/lib/private/Collaboration/Collaborators/MailPlugin.php b/lib/private/Collaboration/Collaborators/MailPlugin.php index fa6b6b586ecba..965c9823b6006 100644 --- a/lib/private/Collaboration/Collaborators/MailPlugin.php +++ b/lib/private/Collaboration/Collaborators/MailPlugin.php @@ -125,7 +125,7 @@ public function search(string $search, int $limit, int $offset, ISearchResult $s if (isset($contact['isLocalSystemBook'])) { $contactUser = $this->userManager->get($contact['UID']); - if ($contactUser === null) { + if ($contactUser === null || !$contactUser->isEnabled()) { continue; } diff --git a/lib/private/Collaboration/Collaborators/RemotePlugin.php b/lib/private/Collaboration/Collaborators/RemotePlugin.php index ece27a2f57fa6..ae0e32d1bb3f2 100644 --- a/lib/private/Collaboration/Collaborators/RemotePlugin.php +++ b/lib/private/Collaboration/Collaborators/RemotePlugin.php @@ -73,7 +73,7 @@ public function search(string $search, int $limit, int $offset, ISearchResult $s } $localUser = $this->userManager->get($remoteUser); - if ($localUser !== null && $remoteUser !== $this->userId && $cloudId === $localUser->getCloudId()) { + if ($localUser !== null && $localUser->isEnabled() && $remoteUser !== $this->userId && $cloudId === $localUser->getCloudId()) { $result['wide'][] = [ 'label' => $contact['FN'], 'uuid' => $contact['UID'], diff --git a/tests/Core/Listener/RestrictInteractionListenerTest.php b/tests/Core/Listener/RestrictInteractionListenerTest.php index dac9c4ae26e27..6d2e9d97bbd93 100644 --- a/tests/Core/Listener/RestrictInteractionListenerTest.php +++ b/tests/Core/Listener/RestrictInteractionListenerTest.php @@ -86,6 +86,21 @@ public function testShareActionDisabledForUser(): void { $this->assertTrue($group->delete()); } + public function testShareActionUserReceiverDisabled(): void { + $user2 = Server::get(IUserManager::class)->createUser('user2', 'password'); + $this->assertNotFalse($user2); + + $event = new RestrictInteractionEvent($this->user->getUID(), $this->user, [], new ShareAction(), [new UserReceiver($user2->getUID(), $user2)]); + $this->assertFalse($event->isInteractionRestricted()); + + $user2->setEnabled(false); + + $event = new RestrictInteractionEvent($this->user->getUID(), $this->user, [], new ShareAction(), [new UserReceiver($user2->getUID(), $user2)]); + $this->assertEquals('Cannot share with a disabled account.', $event->isInteractionRestricted()); + + $this->assertTrue($user2->delete()); + } + /** @psalm-suppress DeprecatedMethod The configs are not migrated to IAppConfig, so using deprecated IConfig is required for now. */ public function testShareActionUserReceiverGroupMembersOnly(): void { $user2 = Server::get(IUserManager::class)->createUser('user2', 'password'); diff --git a/tests/lib/Collaboration/Collaborators/MailPluginTest.php b/tests/lib/Collaboration/Collaborators/MailPluginTest.php index a50fc251c25b6..ac0848b319bb5 100644 --- a/tests/lib/Collaboration/Collaborators/MailPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/MailPluginTest.php @@ -58,6 +58,9 @@ protected function setUp(): void { $user ->method('getUID') ->willReturn($uid); + $user + ->method('isEnabled') + ->willReturn(!str_starts_with($uid, 'disabled')); return $user; }); diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index a706eff66d1f3..6c9ca2c15515d 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -1284,8 +1284,8 @@ public function testGeneralChecks(array $shareParams, ?string $exceptionMessage, $this->userManager->method('userExists')->willReturnCallBack(fn (string $userId) => $userId === 'user0' || $userId === 'user1'); $this->userManager->method('get')->willReturnMap([ - ['user0', $this->createMock(IUser::class)], - ['user1', $this->createMock(IUser::class)], + ['user0', $this->createEnabledUser(true)], + ['user1', $this->createEnabledUser(true)], ]); $this->groupManager->method('groupExists')->willReturnMap([ @@ -1365,8 +1365,8 @@ public function testGeneralCheckShareRoot(): void { ]); $this->userManager->method('get')->willReturnMap([ - ['user0', $this->createMock(IUser::class)], - ['user1', $this->createMock(IUser::class)], + ['user0', $this->createEnabledUser(true)], + ['user1', $this->createEnabledUser(true)], ]); $userFolder = $this->createMock(IUserFolder::class); @@ -2044,8 +2044,8 @@ public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups(): ->setNode($node) ->setPermissions(Constants::PERMISSION_ALL); - $sharedBy = $this->createMock(IUser::class); - $sharedWith = $this->createMock(IUser::class); + $sharedBy = $this->createEnabledUser(true); + $sharedWith = $this->createEnabledUser(true); $this->groupManager ->method('getUserGroupIds') @@ -2111,11 +2111,11 @@ public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup(): void ->setNode($node) ->setPermissions(Constants::PERMISSION_ALL); - $sharedBy = $this->createMock(IUser::class); + $sharedBy = $this->createEnabledUser(true); $sharedBy ->method('getUID') ->willReturn('sharedBy'); - $sharedWith = $this->createMock(IUser::class); + $sharedWith = $this->createEnabledUser(true); $this->groupManager ->method('getUserGroupIds') @@ -2299,8 +2299,8 @@ public function testUserCreateChecksIdenticalPathNotSharedWithUser(): void { ->setProviderId('foo') ->setId('bar'); - $sharedWith = $this->createMock(IUser::class); - $sharedBy = $this->createMock(IUser::class); + $sharedWith = $this->createEnabledUser(true); + $sharedBy = $this->createEnabledUser(true); $sharedBy ->method('getUID') ->willReturn('sharedBy'); @@ -3101,15 +3101,17 @@ public function testCanShare($expected, $sharingEnabled, $disabledForUser): void ->with('user1') ->willReturn($userFolder); - $user1 = $this->createMock(IUser::class); + $user1 = $this->createEnabledUser(true); $user1 ->method('getUID') ->willReturn('user1'); $this->userManager ->method('get') - ->with('user1') - ->willReturn($user1); + ->willReturnMap([ + ['user1', $user1], + ['user2', $this->createEnabledUser(true)], + ]); $share = $this->manager->newShare() ->setShareType(IShare::TYPE_USER)