Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions core/Listener/RestrictInteractionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Collaboration/Collaborators/MailPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Collaboration/Collaborators/RemotePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
15 changes: 15 additions & 0 deletions tests/Core/Listener/RestrictInteractionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/Collaboration/Collaborators/MailPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ protected function setUp(): void {
$user
->method('getUID')
->willReturn($uid);
$user
->method('isEnabled')
->willReturn(!str_starts_with($uid, 'disabled'));

return $user;
});
Expand Down
28 changes: 15 additions & 13 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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)
Expand Down
Loading