Merge pull request #26209 from nextcloud/backport/23718/stable20
[stable20] expand 'path is already shared' error message
This commit is contained in:
commit
019ccda25f
|
@ -563,9 +563,10 @@ class Manager implements IManager {
|
||||||
//Shares are not identical
|
//Shares are not identical
|
||||||
}
|
}
|
||||||
|
|
||||||
// Identical share already existst
|
// Identical share already exists
|
||||||
if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) {
|
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
|
// The share is already shared with this user via a group share
|
||||||
|
@ -575,7 +576,8 @@ class Manager implements IManager {
|
||||||
$user = $this->userManager->get($share->getSharedWith());
|
$user = $this->userManager->get($share->getSharedWith());
|
||||||
|
|
||||||
if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ use OCP\Mail\IMailer;
|
||||||
use OCP\Security\Events\ValidatePasswordPolicyEvent;
|
use OCP\Security\Events\ValidatePasswordPolicyEvent;
|
||||||
use OCP\Security\IHasher;
|
use OCP\Security\IHasher;
|
||||||
use OCP\Security\ISecureRandom;
|
use OCP\Security\ISecureRandom;
|
||||||
|
use OCP\Share\Exceptions\AlreadySharedException;
|
||||||
use OCP\Share\Exceptions\ShareNotFound;
|
use OCP\Share\Exceptions\ShareNotFound;
|
||||||
use OCP\Share\IProviderFactory;
|
use OCP\Share\IProviderFactory;
|
||||||
use OCP\Share\IShare;
|
use OCP\Share\IShare;
|
||||||
|
@ -1411,10 +1412,11 @@ class ManagerTest extends \Test\TestCase {
|
||||||
|
|
||||||
|
|
||||||
public function testUserCreateChecksIdenticalShareExists() {
|
public function testUserCreateChecksIdenticalShareExists() {
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(AlreadySharedException::class);
|
||||||
$this->expectExceptionMessage('Path is already shared with this user');
|
$this->expectExceptionMessage('Sharing name.txt failed, because this item is already shared with user user');
|
||||||
|
|
||||||
$share = $this->manager->newShare();
|
$share = $this->manager->newShare();
|
||||||
|
$share->setSharedWithDisplayName('user');
|
||||||
$share2 = $this->manager->newShare();
|
$share2 = $this->manager->newShare();
|
||||||
|
|
||||||
$sharedWith = $this->createMock(IUser::class);
|
$sharedWith = $this->createMock(IUser::class);
|
||||||
|
@ -1431,13 +1433,16 @@ class ManagerTest extends \Test\TestCase {
|
||||||
->with($path)
|
->with($path)
|
||||||
->willReturn([$share2]);
|
->willReturn([$share2]);
|
||||||
|
|
||||||
|
$path->method('getName')
|
||||||
|
->willReturn('name.txt');
|
||||||
|
|
||||||
self::invokePrivate($this->manager, 'userCreateChecks', [$share]);
|
self::invokePrivate($this->manager, 'userCreateChecks', [$share]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testUserCreateChecksIdenticalPathSharedViaGroup() {
|
public function testUserCreateChecksIdenticalPathSharedViaGroup() {
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(AlreadySharedException::class);
|
||||||
$this->expectExceptionMessage('Path is already shared with this user');
|
$this->expectExceptionMessage('Sharing name2.txt failed, because this item is already shared with user userName');
|
||||||
|
|
||||||
$share = $this->manager->newShare();
|
$share = $this->manager->newShare();
|
||||||
|
|
||||||
|
@ -1451,6 +1456,7 @@ class ManagerTest extends \Test\TestCase {
|
||||||
$share->setSharedWith('sharedWith')
|
$share->setSharedWith('sharedWith')
|
||||||
->setNode($path)
|
->setNode($path)
|
||||||
->setShareOwner('shareOwner')
|
->setShareOwner('shareOwner')
|
||||||
|
->setSharedWithDisplayName('userName')
|
||||||
->setProviderId('foo')
|
->setProviderId('foo')
|
||||||
->setId('bar');
|
->setId('bar');
|
||||||
|
|
||||||
|
@ -1473,6 +1479,9 @@ class ManagerTest extends \Test\TestCase {
|
||||||
->with($path)
|
->with($path)
|
||||||
->willReturn([$share2]);
|
->willReturn([$share2]);
|
||||||
|
|
||||||
|
$path->method('getName')
|
||||||
|
->willReturn('name2.txt');
|
||||||
|
|
||||||
self::invokePrivate($this->manager, 'userCreateChecks', [$share]);
|
self::invokePrivate($this->manager, 'userCreateChecks', [$share]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue