Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable21] expand 'path is already shared' error message #26211

Merged
merged 1 commit into from
Mar 19, 2021
Merged
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
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