Skip to content

Commit

Permalink
Merge pull request #26211 from nextcloud/backport/23718/stable21
Browse files Browse the repository at this point in the history
[stable21] expand 'path is already shared' error message
  • Loading branch information
MorrisJobke authored Mar 19, 2021
2 parents 06a9463 + def56ca commit eaae526
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
8 changes: 5 additions & 3 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,10 @@ protected function userCreateChecks(IShare $share) {
//Shares are not identical
}

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

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

if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) {
throw new AlreadySharedException('Path is already shared with this user', $existingShare);
$message = $this->l->t('Sharing %s failed, because this item is already shared with user %s', [$share->getNode()->getName(), $share->getSharedWithDisplayName()]);
throw new AlreadySharedException($message, $existingShare);
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use OCP\Security\Events\ValidatePasswordPolicyEvent;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
use OCP\Share\Exceptions\AlreadySharedException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
Expand Down Expand Up @@ -1415,10 +1416,11 @@ public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup() {


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

$share = $this->manager->newShare();
$share->setSharedWithDisplayName('user');
$share2 = $this->manager->newShare();

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

$path->method('getName')
->willReturn('name.txt');

self::invokePrivate($this->manager, 'userCreateChecks', [$share]);
}


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

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

Expand All @@ -1455,6 +1460,7 @@ public function testUserCreateChecksIdenticalPathSharedViaGroup() {
$share->setSharedWith('sharedWith')
->setNode($path)
->setShareOwner('shareOwner')
->setSharedWithDisplayName('userName')
->setProviderId('foo')
->setId('bar');

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

$path->method('getName')
->willReturn('name2.txt');

self::invokePrivate($this->manager, 'userCreateChecks', [$share]);
}

Expand Down

0 comments on commit eaae526

Please sign in to comment.