Skip to content

Commit

Permalink
Merge pull request #27529 from owncloud/share-keep-name
Browse files Browse the repository at this point in the history
Keep share link name if not specified in update call
  • Loading branch information
Vincent Petry authored Mar 29, 2017
2 parents 6ee78af + 7ae1981 commit 31d0967
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 3 deletions.
12 changes: 9 additions & 3 deletions apps/files_sharing/lib/API/Share20OCS.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,10 @@ public function createShare() {
$share->setPermissions(\OCP\Constants::PERMISSION_READ);
}

$share->setName($name);
// set name only if passed as parameter, empty string is allowed
if ($name !== null) {
$share->setName($name);
}

// Set password
$password = $this->request->getParam('password', '');
Expand Down Expand Up @@ -594,7 +597,7 @@ public function updateShare($id) {
* expirationdate, password and publicUpload only make sense for link shares
*/
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) {
if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null && $name === null) {
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
return new \OC\OCS\Result(null, 400, 'Wrong or no update parameter given');
}
Expand Down Expand Up @@ -641,7 +644,10 @@ public function updateShare($id) {
$newPermissions = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
}

$share->setName($name);
// set name only if passed as parameter, empty string is allowed
if ($name !== null) {
$share->setName($name);
}

if ($newPermissions !== null) {
$share->setPermissions($newPermissions);
Expand Down
77 changes: 77 additions & 0 deletions apps/files_sharing/tests/API/Share20OCSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,83 @@ public function testUpdateShareCanIncreasePermissionsIfOwner() {
$this->assertEquals($expected->getMeta(), $result->getMeta());
$this->assertEquals($expected->getData(), $result->getData());
}

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

$date = new \DateTime('2000-01-01');

$folder = $this->createMock('\OCP\Files\Folder');

$share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_READ)
->setSharedBy($this->currentUser->getUID())
->setShareType(Share::SHARE_TYPE_LINK)
->setName('somename')
->setNode($folder);

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

$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);

$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (\OCP\Share\IShare $share) use ($date) {
return $share->getName() === 'another';
})
)->will($this->returnArgument(0));

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

$expected = new \OC\OCS\Result(null);
$result = $ocs->updateShare(42);

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

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

$date = new \DateTime('2000-01-01');

$folder = $this->createMock('\OCP\Files\Folder');

$share = \OC::$server->getShareManager()->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_READ)
->setSharedBy($this->currentUser->getUID())
->setShareType(Share::SHARE_TYPE_LINK)
->setName('somename')
->setNode($folder);

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

$this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share);

$this->shareManager->expects($this->once())->method('updateShare')->with(
$this->callback(function (\OCP\Share\IShare $share) use ($date) {
return $share->getPermissions() === (\OCP\Constants::PERMISSION_READ) &&
$share->getPassword() === 'test' &&
$share->getName() === 'somename';
})
)->will($this->returnArgument(0));

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

$expected = new \OC\OCS\Result(null);
$result = $ocs->updateShare(42);

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

public function dataFormatShare() {
$file = $this->createMock('\OCP\Files\File');
$folder = $this->createMock('\OCP\Files\Folder');
Expand Down

0 comments on commit 31d0967

Please sign in to comment.