Permalink
Browse files

Merge pull request #1391 from nextcloud/stable10-backport-1376

[stable10] Allow increasing permissions for share owner
  • Loading branch information...
rullzer committed Sep 13, 2016
2 parents d7faff0 + 4c177ce commit 14ea159670aa7272b409a6422f1e9e3856e38056
Showing with 109 additions and 1 deletion.
  1. +1 −1 apps/files_sharing/lib/API/Share20OCS.php
  2. +108 −0 apps/files_sharing/tests/API/Share20OCSTest.php
@@ -668,7 +668,7 @@ public function updateShare($id) {
}
}
if ($permissions !== null) {
if ($permissions !== null && $share->getShareOwner() !== $this->currentUser->getUID()) {
/* Check if this is an incomming share */
$incomingShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0);
$incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0));
@@ -1766,6 +1766,114 @@ public function testUpdateOtherPermissions() {
$this->assertEquals($expected->getData(), $result->getData());
}
public function testUpdateShareCannotIncreasePermissions() {
$ocs = $this->mockFormatShare();
$date = new \DateTime('2000-01-01');
$folder = $this->getMock('\OCP\Files\Folder');
$share = \OC::$server->getShareManager()->newShare();
$share
->setId(42)
->setSharedBy($this->currentUser->getUID())
->setShareOwner('anotheruser')
->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
->setSharedWith('group1')
->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_GROUP)
->setSharedWith('group1')
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setNode($folder);
$this->request
->method('getParam')
->will($this->returnValueMap([
['permissions', null, '31'],
]));
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
$this->shareManager->expects($this->any(0))
->method('getSharedWith')
->will($this->returnValueMap([
['currentUser', \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0, []],
['currentUser', \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0, [$incomingShare]]
]));
$this->shareManager->expects($this->never())->method('updateShare');
$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();
$date = new \DateTime('2000-01-01');
$folder = $this->getMock('\OCP\Files\Folder');
$share = \OC::$server->getShareManager()->newShare();
$share
->setId(42)
->setSharedBy($this->currentUser->getUID())
->setShareOwner($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
->setSharedWith('group1')
->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($this->currentUser->getUID())
->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
->setSharedWith('group1')
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setNode($folder);
$this->request
->method('getParam')
->will($this->returnValueMap([
['permissions', null, '31'],
]));
$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);
$this->shareManager->expects($this->any(0))
->method('getSharedWith')
->will($this->returnValueMap([
['currentUser', \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0, []],
['currentUser', \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0, [$incomingShare]]
]));
$this->shareManager->expects($this->once())
->method('updateShare')
->with($share)
->willReturn($share);
$expected = new \OC_OCS_Result();
$result = $ocs->updateShare(42);
$this->assertEquals($expected->getMeta(), $result->getMeta());
$this->assertEquals($expected->getData(), $result->getData());
}
public function dataFormatShare() {
$file = $this->getMockBuilder('\OCP\Files\File')->getMock();
$folder = $this->getMockBuilder('\OCP\Files\Folder')->getMock();

0 comments on commit 14ea159

Please sign in to comment.