mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #47782 from nextcloud/reworkShareExceptions
fix(l10n): Rephrasing some exceptions to be translated
This commit is contained in:
commit
2ba3f7ed5c
2 changed files with 36 additions and 37 deletions
|
|
@ -130,34 +130,34 @@ class Manager implements IManager {
|
|||
if ($share->getShareType() === IShare::TYPE_USER) {
|
||||
// We expect a valid user as sharedWith for user shares
|
||||
if (!$this->userManager->userExists($share->getSharedWith())) {
|
||||
throw new \InvalidArgumentException($this->l->t('SharedWith is not a valid user'));
|
||||
throw new \InvalidArgumentException($this->l->t('Share recipient is not a valid user'));
|
||||
}
|
||||
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
|
||||
// We expect a valid group as sharedWith for group shares
|
||||
if (!$this->groupManager->groupExists($share->getSharedWith())) {
|
||||
throw new \InvalidArgumentException($this->l->t('SharedWith is not a valid group'));
|
||||
throw new \InvalidArgumentException($this->l->t('Share recipient is not a valid group'));
|
||||
}
|
||||
} elseif ($share->getShareType() === IShare::TYPE_LINK) {
|
||||
// No check for TYPE_EMAIL here as we have a recipient for them
|
||||
if ($share->getSharedWith() !== null) {
|
||||
throw new \InvalidArgumentException($this->l->t('SharedWith should be empty'));
|
||||
throw new \InvalidArgumentException($this->l->t('Share recipient should be empty'));
|
||||
}
|
||||
} elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
|
||||
if ($share->getSharedWith() === null) {
|
||||
throw new \InvalidArgumentException($this->l->t('SharedWith should not be empty'));
|
||||
throw new \InvalidArgumentException($this->l->t('Share recipient should not be empty'));
|
||||
}
|
||||
} elseif ($share->getShareType() === IShare::TYPE_REMOTE) {
|
||||
if ($share->getSharedWith() === null) {
|
||||
throw new \InvalidArgumentException($this->l->t('SharedWith should not be empty'));
|
||||
throw new \InvalidArgumentException($this->l->t('Share recipient should not be empty'));
|
||||
}
|
||||
} elseif ($share->getShareType() === IShare::TYPE_REMOTE_GROUP) {
|
||||
if ($share->getSharedWith() === null) {
|
||||
throw new \InvalidArgumentException($this->l->t('SharedWith should not be empty'));
|
||||
throw new \InvalidArgumentException($this->l->t('Share recipient should not be empty'));
|
||||
}
|
||||
} elseif ($share->getShareType() === IShare::TYPE_CIRCLE) {
|
||||
$circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith());
|
||||
if ($circle === null) {
|
||||
throw new \InvalidArgumentException($this->l->t('SharedWith is not a valid circle'));
|
||||
throw new \InvalidArgumentException($this->l->t('Share recipient is not a valid circle'));
|
||||
}
|
||||
} elseif ($share->getShareType() === IShare::TYPE_ROOM) {
|
||||
} elseif ($share->getShareType() === IShare::TYPE_DECK) {
|
||||
|
|
@ -169,7 +169,7 @@ class Manager implements IManager {
|
|||
|
||||
// Verify the initiator of the share is set
|
||||
if ($share->getSharedBy() === null) {
|
||||
throw new \InvalidArgumentException($this->l->t('SharedBy should be set'));
|
||||
throw new \InvalidArgumentException($this->l->t('Share initiator must be set'));
|
||||
}
|
||||
|
||||
// Cannot share with yourself
|
||||
|
|
@ -180,13 +180,13 @@ class Manager implements IManager {
|
|||
|
||||
// The path should be set
|
||||
if ($share->getNode() === null) {
|
||||
throw new \InvalidArgumentException($this->l->t('Path should be set'));
|
||||
throw new \InvalidArgumentException($this->l->t('Shared path must be set'));
|
||||
}
|
||||
|
||||
// And it should be a file or a folder
|
||||
if (!($share->getNode() instanceof \OCP\Files\File) &&
|
||||
!($share->getNode() instanceof \OCP\Files\Folder)) {
|
||||
throw new \InvalidArgumentException($this->l->t('Path should be either a file or a folder'));
|
||||
throw new \InvalidArgumentException($this->l->t('Shared path must be either a file or a folder'));
|
||||
}
|
||||
|
||||
// And you cannot share your rootfolder
|
||||
|
|
@ -206,7 +206,7 @@ class Manager implements IManager {
|
|||
|
||||
// Permissions should be set
|
||||
if ($share->getPermissions() === null) {
|
||||
throw new \InvalidArgumentException($this->l->t('A share requires permissions'));
|
||||
throw new \InvalidArgumentException($this->l->t('Valid permissions are required for sharing'));
|
||||
}
|
||||
|
||||
$permissions = 0;
|
||||
|
|
@ -227,7 +227,6 @@ class Manager implements IManager {
|
|||
throw new GenericShareException($this->l->t('Cannot increase permissions of %s', [$path]), code: 404);
|
||||
}
|
||||
|
||||
|
||||
// Check that read permissions are always set
|
||||
// Link shares are allowed to have no read permissions to allow upload to hidden folders
|
||||
$noReadPermissionRequired = $share->getShareType() === IShare::TYPE_LINK
|
||||
|
|
@ -1072,7 +1071,7 @@ class Manager implements IManager {
|
|||
}
|
||||
|
||||
if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() !== $recipientId) {
|
||||
throw new \InvalidArgumentException($this->l->t('Invalid recipient'));
|
||||
throw new \InvalidArgumentException($this->l->t('Invalid share recipient'));
|
||||
}
|
||||
|
||||
if ($share->getShareType() === IShare::TYPE_GROUP) {
|
||||
|
|
@ -1082,7 +1081,7 @@ class Manager implements IManager {
|
|||
}
|
||||
$recipient = $this->userManager->get($recipientId);
|
||||
if (!$sharedWith->inGroup($recipient)) {
|
||||
throw new \InvalidArgumentException($this->l->t('Invalid recipient'));
|
||||
throw new \InvalidArgumentException($this->l->t('Invalid share recipient'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -643,30 +643,30 @@ class ManagerTest extends \Test\TestCase {
|
|||
$node->method('getId')->willReturn(108);
|
||||
|
||||
$data = [
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, null, $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, $group0, $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $file, null, $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $file, $user2, $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $file, $user2, $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $file, $group0, $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, null, $user0, $user0, 31, null, null), 'Share recipient is not a valid user', true],
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, $group0, $user0, $user0, 31, null, null), 'Share recipient is not a valid user', true],
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'Share recipient is not a valid user', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $file, null, $user0, $user0, 31, null, null), 'Share recipient is not a valid group', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $file, $user2, $user0, $user0, 31, null, null), 'Share recipient is not a valid group', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'Share recipient is not a valid group', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $file, $user2, $user0, $user0, 31, null, null), 'Share recipient should be empty', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $file, $group0, $user0, $user0, 31, null, null), 'Share recipient should be empty', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'Share recipient should be empty', true],
|
||||
[$this->createShare(null, -1, $file, null, $user0, $user0, 31, null, null), 'Unknown share type', true],
|
||||
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, $user2, null, $user0, 31, null, null), 'SharedBy should be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $file, $group0, null, $user0, 31, null, null), 'SharedBy should be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $file, null, null, $user0, 31, null, null), 'SharedBy should be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, $user2, null, $user0, 31, null, null), 'Share initiator must be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $file, $group0, null, $user0, 31, null, null), 'Share initiator must be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $file, null, null, $user0, 31, null, null), 'Share initiator must be set', true],
|
||||
|
||||
[$this->createShare(null, IShare::TYPE_USER, $file, $user0, $user0, $user0, 31, null, null), 'Cannot share with yourself', true],
|
||||
|
||||
[$this->createShare(null, IShare::TYPE_USER, null, $user2, $user0, $user0, 31, null, null), 'Path should be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, null, $group0, $user0, $user0, 31, null, null), 'Path should be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, null, null, $user0, $user0, 31, null, null), 'Path should be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_USER, null, $user2, $user0, $user0, 31, null, null), 'Shared path must be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, null, $group0, $user0, $user0, 31, null, null), 'Shared path must be set', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, null, null, $user0, $user0, 31, null, null), 'Shared path must be set', true],
|
||||
|
||||
[$this->createShare(null, IShare::TYPE_USER, $node, $user2, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $node, $group0, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $node, null, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
|
||||
[$this->createShare(null, IShare::TYPE_USER, $node, $user2, $user0, $user0, 31, null, null), 'Shared path must be either a file or a folder', true],
|
||||
[$this->createShare(null, IShare::TYPE_GROUP, $node, $group0, $user0, $user0, 31, null, null), 'Shared path must be either a file or a folder', true],
|
||||
[$this->createShare(null, IShare::TYPE_LINK, $node, null, $user0, $user0, 31, null, null), 'Shared path must be either a file or a folder', true],
|
||||
];
|
||||
|
||||
$nonShareAble = $this->createMock(Folder::class);
|
||||
|
|
@ -694,9 +694,9 @@ class ManagerTest extends \Test\TestCase {
|
|||
$limitedPermssions->method('getStorage')
|
||||
->willReturn($storage);
|
||||
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_USER, $limitedPermssions, $user2, $user0, $user0, null, null, null), 'A share requires permissions', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, null, null, null), 'A share requires permissions', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $limitedPermssions, null, $user0, $user0, null, null, null), 'A share requires permissions', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_USER, $limitedPermssions, $user2, $user0, $user0, null, null, null), 'Valid permissions are required for sharing', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, null, null, null), 'Valid permissions are required for sharing', true];
|
||||
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $limitedPermssions, null, $user0, $user0, null, null, null), 'Valid permissions are required for sharing', true];
|
||||
|
||||
$mount = $this->createMock(MoveableMount::class);
|
||||
$limitedPermssions->method('getMountPoint')->willReturn($mount);
|
||||
|
|
@ -4154,7 +4154,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
public function testMoveShareUserNotRecipient(): void {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Invalid recipient');
|
||||
$this->expectExceptionMessage('Invalid share recipient');
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
$share->setShareType(IShare::TYPE_USER);
|
||||
|
|
@ -4181,7 +4181,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
public function testMoveShareGroupNotRecipient(): void {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Invalid recipient');
|
||||
$this->expectExceptionMessage('Invalid share recipient');
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
$share->setShareType(IShare::TYPE_GROUP);
|
||||
|
|
|
|||
Loading…
Reference in a new issue