Commit 31d09676 authored by Vincent Petry's avatar Vincent Petry Committed by GitHub

Merge pull request #27529 from owncloud/share-keep-name

Keep share link name if not specified in update call
parents 6ee78af7 7ae19811
......@@ -356,7 +356,10 @@ class Share20OCS {
$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', '');
......@@ -594,7 +597,7 @@ class Share20OCS {
* 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');
}
......@@ -641,7 +644,10 @@ class Share20OCS {
$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);
......
......@@ -1942,6 +1942,83 @@ class Share20OCSTest extends TestCase {
$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');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment