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

Fix create share API permissions for links #29143

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 5 additions & 1 deletion apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ public function createShare(
): DataResponse {
$share = $this->shareManager->newShare();

$requestPermissions = $permissions;
if ($permissions === null) {
$permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL);
}
Expand Down Expand Up @@ -558,7 +559,10 @@ public function createShare(
Constants::PERMISSION_UPDATE |
Constants::PERMISSION_DELETE;
} else {
$permissions = Constants::PERMISSION_READ;
// do not ignore permissions request param if provided
if ($requestPermissions === null) {
$permissions = Constants::PERMISSION_READ;
}
}

// TODO: It might make sense to have a dedicated setting to allow/deny converting link shares into federated ones
Expand Down
10 changes: 5 additions & 5 deletions apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,7 @@ public function testCreateShareLinkPassword() {
)->willReturnArgument(0);

$expected = new DataResponse([]);
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', 'password', null, '');
$result = $ocs->createShare('valid-path', null, IShare::TYPE_LINK, null, 'false', 'password', null, '');

$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
Expand Down Expand Up @@ -2098,7 +2098,7 @@ public function testCreateShareLinkSendPasswordByTalk() {
)->willReturnArgument(0);

$expected = new DataResponse([]);
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', 'password', 'true', '');
$result = $ocs->createShare('valid-path', null, IShare::TYPE_LINK, null, 'false', 'password', 'true', '');

$this->assertInstanceOf(get_class($expected), $result);
$this->assertEquals($expected->getData(), $result->getData());
Expand Down Expand Up @@ -2131,7 +2131,7 @@ public function testCreateShareLinkSendPasswordByTalkWithTalkDisabled() {

$this->shareManager->expects($this->never())->method('createShare');

$ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', 'password', 'true', '');
$ocs->createShare('valid-path', null, IShare::TYPE_LINK, null, 'false', 'password', 'true', '');
}

public function testCreateShareValidExpireDate() {
Expand Down Expand Up @@ -2177,7 +2177,7 @@ public function testCreateShareValidExpireDate() {
)->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());
Expand Down Expand Up @@ -2205,7 +2205,7 @@ public function testCreateShareInvalidExpireDate() {
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);

$ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', '', null, 'a1b2d3');
$ocs->createShare('valid-path', null, IShare::TYPE_LINK, null, 'false', '', null, 'a1b2d3');
}

public function testCreateShareRemote() {
Expand Down