Skip to content

Commit eaae526

Browse files
authored
Merge pull request #26211 from nextcloud/backport/23718/stable21
[stable21] expand 'path is already shared' error message
2 parents 06a9463 + def56ca commit eaae526

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lib/private/Share20/Manager.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,10 @@ protected function userCreateChecks(IShare $share) {
564564
//Shares are not identical
565565
}
566566

567-
// Identical share already existst
567+
// Identical share already exists
568568
if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) {
569-
throw new AlreadySharedException('Path is already shared with this user', $existingShare);
569+
$message = $this->l->t('Sharing %s failed, because this item is already shared with user %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]);
570+
throw new AlreadySharedException($message, $existingShare);
570571
}
571572

572573
// The share is already shared with this user via a group share
@@ -576,7 +577,8 @@ protected function userCreateChecks(IShare $share) {
576577
$user = $this->userManager->get($share->getSharedWith());
577578

578579
if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) {
579-
throw new AlreadySharedException('Path is already shared with this user', $existingShare);
580+
$message = $this->l->t('Sharing %s failed, because this item is already shared with user %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]);
581+
throw new AlreadySharedException($message, $existingShare);
580582
}
581583
}
582584
}

tests/lib/Share20/ManagerTest.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use OCP\Security\Events\ValidatePasswordPolicyEvent;
5151
use OCP\Security\IHasher;
5252
use OCP\Security\ISecureRandom;
53+
use OCP\Share\Exceptions\AlreadySharedException;
5354
use OCP\Share\Exceptions\ShareNotFound;
5455
use OCP\Share\IProviderFactory;
5556
use OCP\Share\IShare;
@@ -1415,10 +1416,11 @@ public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup() {
14151416

14161417

14171418
public function testUserCreateChecksIdenticalShareExists() {
1418-
$this->expectException(\Exception::class);
1419-
$this->expectExceptionMessage('Path is already shared with this user');
1419+
$this->expectException(AlreadySharedException::class);
1420+
$this->expectExceptionMessage('Sharing name.txt failed, because this item is already shared with user user');
14201421

14211422
$share = $this->manager->newShare();
1423+
$share->setSharedWithDisplayName('user');
14221424
$share2 = $this->manager->newShare();
14231425

14241426
$sharedWith = $this->createMock(IUser::class);
@@ -1435,13 +1437,16 @@ public function testUserCreateChecksIdenticalShareExists() {
14351437
->with($path)
14361438
->willReturn([$share2]);
14371439

1440+
$path->method('getName')
1441+
->willReturn('name.txt');
1442+
14381443
self::invokePrivate($this->manager, 'userCreateChecks', [$share]);
14391444
}
14401445

14411446

14421447
public function testUserCreateChecksIdenticalPathSharedViaGroup() {
1443-
$this->expectException(\Exception::class);
1444-
$this->expectExceptionMessage('Path is already shared with this user');
1448+
$this->expectException(AlreadySharedException::class);
1449+
$this->expectExceptionMessage('Sharing name2.txt failed, because this item is already shared with user userName');
14451450

14461451
$share = $this->manager->newShare();
14471452

@@ -1455,6 +1460,7 @@ public function testUserCreateChecksIdenticalPathSharedViaGroup() {
14551460
$share->setSharedWith('sharedWith')
14561461
->setNode($path)
14571462
->setShareOwner('shareOwner')
1463+
->setSharedWithDisplayName('userName')
14581464
->setProviderId('foo')
14591465
->setId('bar');
14601466

@@ -1477,6 +1483,9 @@ public function testUserCreateChecksIdenticalPathSharedViaGroup() {
14771483
->with($path)
14781484
->willReturn([$share2]);
14791485

1486+
$path->method('getName')
1487+
->willReturn('name2.txt');
1488+
14801489
self::invokePrivate($this->manager, 'userCreateChecks', [$share]);
14811490
}
14821491

0 commit comments

Comments
 (0)