mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
Honor permissions of new link share via OCS API
The API currently overrides the supplied permissions with "read only" when a file is shared via link. It allows to update the permissions later, however. This keeps the default to "read only" but honors the permissions supplied by API call if any. Signed-off-by: Jan-Philipp Litza <jpl@plutex.de>
This commit is contained in:
parent
b62d3c4f39
commit
a7abe2c35a
3 changed files with 13 additions and 9 deletions
|
|
@ -478,7 +478,14 @@ class ShareAPIController extends OCSController {
|
|||
$share = $this->shareManager->newShare();
|
||||
|
||||
if ($permissions === null) {
|
||||
$permissions = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL);
|
||||
if ($shareType === IShare::TYPE_LINK
|
||||
|| $shareType === IShare::TYPE_EMAIL) {
|
||||
|
||||
// to keep legacy default behaviour, we ignore the setting below for link shares
|
||||
$permissions = Constants::PERMISSION_READ;
|
||||
} else {
|
||||
$permissions = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
// Verify path
|
||||
|
|
@ -581,8 +588,6 @@ class ShareAPIController extends OCSController {
|
|||
Constants::PERMISSION_CREATE |
|
||||
Constants::PERMISSION_UPDATE |
|
||||
Constants::PERMISSION_DELETE;
|
||||
} else {
|
||||
$permissions = Constants::PERMISSION_READ;
|
||||
}
|
||||
|
||||
// TODO: It might make sense to have a dedicated setting to allow/deny converting link shares into federated ones
|
||||
|
|
|
|||
|
|
@ -211,8 +211,7 @@ class ApiTest extends TestCase {
|
|||
$ocs->cleanup();
|
||||
|
||||
$data = $result->getData();
|
||||
$this->assertEquals(\OCP\Constants::PERMISSION_READ |
|
||||
\OCP\Constants::PERMISSION_SHARE,
|
||||
$this->assertEquals(\OCP\Constants::PERMISSION_ALL,
|
||||
$data['permissions']);
|
||||
$this->assertEmpty($data['expiration']);
|
||||
$this->assertTrue(is_string($data['token']));
|
||||
|
|
|
|||
|
|
@ -2055,7 +2055,7 @@ class ShareAPIControllerTest extends TestCase {
|
|||
$this->callback(function (\OCP\Share\IShare $share) use ($path) {
|
||||
return $share->getNode() === $path &&
|
||||
$share->getShareType() === IShare::TYPE_LINK &&
|
||||
$share->getPermissions() === \OCP\Constants::PERMISSION_READ &&
|
||||
$share->getPermissions() === \OCP\Constants::PERMISSION_ALL &&
|
||||
$share->getSharedBy() === 'currentUser' &&
|
||||
$share->getPassword() === 'password' &&
|
||||
$share->getExpirationDate() === null;
|
||||
|
|
@ -2095,7 +2095,7 @@ class ShareAPIControllerTest extends TestCase {
|
|||
$this->callback(function (\OCP\Share\IShare $share) use ($path) {
|
||||
return $share->getNode() === $path &&
|
||||
$share->getShareType() === IShare::TYPE_LINK &&
|
||||
$share->getPermissions() === \OCP\Constants::PERMISSION_READ &&
|
||||
$share->getPermissions() === \OCP\Constants::PERMISSION_ALL &&
|
||||
$share->getSharedBy() === 'currentUser' &&
|
||||
$share->getPassword() === 'password' &&
|
||||
$share->getSendPasswordByTalk() === true &&
|
||||
|
|
@ -2179,7 +2179,7 @@ class ShareAPIControllerTest extends TestCase {
|
|||
|
||||
return $share->getNode() === $path &&
|
||||
$share->getShareType() === IShare::TYPE_LINK &&
|
||||
$share->getPermissions() === \OCP\Constants::PERMISSION_READ &&
|
||||
$share->getPermissions() === \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE &&
|
||||
$share->getSharedBy() === 'currentUser' &&
|
||||
$share->getPassword() === null &&
|
||||
$share->getExpirationDate() == $date;
|
||||
|
|
@ -2187,7 +2187,7 @@ class ShareAPIControllerTest extends TestCase {
|
|||
)->willReturnArgument(0);
|
||||
|
||||
$expected = new DataResponse([]);
|
||||
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', '', null, '2000-01-01');
|
||||
$result = $ocs->createShare('valid-path', null, IShare::TYPE_LINK, null, 'false', '', null, '2000-01-01');
|
||||
|
||||
$this->assertInstanceOf(get_class($expected), $result);
|
||||
$this->assertEquals($expected->getData(), $result->getData());
|
||||
|
|
|
|||
Loading…
Reference in a new issue