Skip to content
Merged
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
1 change: 1 addition & 0 deletions apps/files_sharing/lib/API/Share20OCS.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -637,6 +637,7 @@ public function updateShare($id) {

if ($newPermissions !== null) {
$share->setPermissions($newPermissions);
$permissions = $newPermissions;
}

if ($expireDate === '') {
Expand Down
55 changes: 55 additions & 0 deletions apps/files_sharing/tests/API/Share20OCSTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1334,6 +1334,9 @@ public function testUpdateLinkShareClear() {
})
)->will($this->returnArgument(0));

$this->shareManager->method('getSharedWith')
->willReturn([]);

$expected = new \OC_OCS_Result(null);
$result = $ocs->updateShare(42);

Expand DownExpand Up@@ -1374,6 +1377,9 @@ public function testUpdateLinkShareSet() {
})
)->will($this->returnArgument(0));

$this->shareManager->method('getSharedWith')
->willReturn([]);

$expected = new \OC_OCS_Result(null);
$result = $ocs->updateShare(42);

Expand DownExpand Up@@ -1650,6 +1656,9 @@ public function testUpdateLinkSharePublicUploadDoesNotChangeOther() {
})
)->will($this->returnArgument(0));

$this->shareManager->method('getSharedWith')
->willReturn([]);

$expected = new \OC_OCS_Result(null);
$result = $ocs->updateShare(42);

Expand DownExpand Up@@ -1819,6 +1828,52 @@ public function testUpdateShareCannotIncreasePermissions() {
$this->assertEquals($expected->getData(), $result->getData());
}

public function testUpdateShareCannotIncreasePermissionsLinkShare() {
$ocs = $this->mockFormatShare();
$folder = $this->getMockBuilder('OCP\Files\Folder')
->getMock();
$share = \OC::$server->getShareManager()->newShare();
$share
->setId(42)
->setSharedBy($this->currentUser->getUID())
->setShareOwner('anotheruser')
->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setNode($folder);
// note: updateShare will modify the received instance but getSharedWith will reread from the database,
// so their values will be different
$incomingShare = \OC::$server->getShareManager()->newShare();
$incomingShare
->setId(42)
->setSharedBy($this->currentUser->getUID())
->setShareOwner('anotheruser')
->setShareType(\OCP\Share::SHARE_TYPE_USER)
->setSharedWith('currentUser')
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setNode($folder);
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
$this->shareManager->expects($this->any())
->method('getSharedWith')
->will($this->returnValueMap([
['currentUser', \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0, [$incomingShare]],
['currentUser', \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0, []]
]));
$this->shareManager->expects($this->never())->method('updateShare');
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);

$this->request
->method('getParam')
->will($this->returnValueMap([
['publicUpload', null, 'true'],
]));

$expected = new \OC_OCS_Result(null, 404, 'Cannot increase permissions');
$result = $ocs->updateShare(42);

$this->assertEquals($expected->getMeta(), $result->getMeta());
$this->assertEquals($expected->getData(), $result->getData());
}

public function testUpdateShareCanIncreasePermissionsIfOwner() {
$ocs = $this->mockFormatShare();

Expand Down