Skip to content

Commit

Permalink
Merge pull request #24231 from nextcloud/backport/23757/stable20
Browse files Browse the repository at this point in the history
[stable20] use file name instead of path in 'not allowed to share' message
  • Loading branch information
rullzer authored Nov 20, 2020
2 parents 10086b3 + f65a89d commit 3839c84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ protected function generalCreateChecks(IShare $share) {

// Check if we actually have share permissions
if (!$share->getNode()->isShareable()) {
$path = $userFolder->getRelativePath($share->getNode()->getPath());
$message_t = $this->l->t('You are not allowed to share %s', [$path]);
$message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getName()]);
throw new GenericShareException($message_t, $message_t, 404);
}

Expand Down
9 changes: 6 additions & 3 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,20 +601,22 @@ public function dataGeneralChecks() {
$nonShareAble = $this->createMock(Folder::class);
$nonShareAble->method('isShareable')->willReturn(false);
$nonShareAble->method('getPath')->willReturn('path');
$nonShareAble->method('getName')->willReturn('name');
$nonShareAble->method('getOwner')
->willReturn($owner);
$nonShareAble->method('getStorage')
->willReturn($storage);

$data[] = [$this->createShare(null, IShare::TYPE_USER, $nonShareAble, $user2, $user0, $user0, 31, null, null), 'You are not allowed to share path', true];
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $nonShareAble, $group0, $user0, $user0, 31, null, null), 'You are not allowed to share path', true];
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $nonShareAble, null, $user0, $user0, 31, null, null), 'You are not allowed to share path', true];
$data[] = [$this->createShare(null, IShare::TYPE_USER, $nonShareAble, $user2, $user0, $user0, 31, null, null), 'You are not allowed to share name', true];
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $nonShareAble, $group0, $user0, $user0, 31, null, null), 'You are not allowed to share name', true];
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $nonShareAble, null, $user0, $user0, 31, null, null), 'You are not allowed to share name', true];

$limitedPermssions = $this->createMock(File::class);
$limitedPermssions->method('isShareable')->willReturn(true);
$limitedPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ);
$limitedPermssions->method('getId')->willReturn(108);
$limitedPermssions->method('getPath')->willReturn('path');
$limitedPermssions->method('getName')->willReturn('name');
$limitedPermssions->method('getOwner')
->willReturn($owner);
$limitedPermssions->method('getStorage')
Expand All @@ -637,6 +639,7 @@ public function dataGeneralChecks() {
$nonMoveableMountPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ);
$nonMoveableMountPermssions->method('getId')->willReturn(108);
$nonMoveableMountPermssions->method('getPath')->willReturn('path');
$nonMoveableMountPermssions->method('getName')->willReturn('name');
$nonMoveableMountPermssions->method('getOwner')
->willReturn($owner);
$nonMoveableMountPermssions->method('getStorage')
Expand Down

0 comments on commit 3839c84

Please sign in to comment.