From 84a148aac19f4e5f3d1dd48f6b9c7622a4364a74 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 12 Mar 2020 14:43:27 +0100 Subject: [PATCH] Properly respect hide download on sharebymail fixes #19484 Signed-off-by: Roeland Jago Douma --- apps/sharebymail/lib/ShareByMailProvider.php | 11 ++++++++--- .../sharebymail/tests/ShareByMailProviderTest.php | 15 +++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index 48c60b168e..a7b8f54121 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -354,7 +354,8 @@ class ShareByMailProvider implements IShareProvider { $share->getPermissions(), $share->getToken(), $share->getPassword(), - $share->getSendPasswordByTalk() + $share->getSendPasswordByTalk(), + $share->getHideDownload() ); try { @@ -686,9 +687,10 @@ class ShareByMailProvider implements IShareProvider { * @param string $token * @param string $password * @param bool $sendPasswordByTalk + * @param bool $hideDownload * @return int */ - protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password, $sendPasswordByTalk) { + protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password, $sendPasswordByTalk, $hideDownload) { $qb = $this->dbConnection->getQueryBuilder(); $qb->insert('share') ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) @@ -702,7 +704,8 @@ class ShareByMailProvider implements IShareProvider { ->setValue('token', $qb->createNamedParameter($token)) ->setValue('password', $qb->createNamedParameter($password)) ->setValue('password_by_talk', $qb->createNamedParameter($sendPasswordByTalk, IQueryBuilder::PARAM_BOOL)) - ->setValue('stime', $qb->createNamedParameter(time())); + ->setValue('stime', $qb->createNamedParameter(time())) + ->setValue('hide_download', $qb->createNamedParameter($hideDownload, IQueryBuilder::PARAM_BOOL)); /* * Added to fix https://github.com/owncloud/core/issues/22215 @@ -747,6 +750,7 @@ class ShareByMailProvider implements IShareProvider { ->set('password_by_talk', $qb->createNamedParameter($share->getSendPasswordByTalk(), IQueryBuilder::PARAM_BOOL)) ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) ->set('note', $qb->createNamedParameter($share->getNote())) + ->set('hide_download', $qb->createNamedParameter($share->getHideDownload(), IQueryBuilder::PARAM_BOOL)) ->execute(); if ($originalShare->getNote() !== $share->getNote() && $share->getNote() !== '') { @@ -1007,6 +1011,7 @@ class ShareByMailProvider implements IShareProvider { $share->setSharedWith($data['share_with']); $share->setPassword($data['password']); $share->setSendPasswordByTalk((bool)$data['password_by_talk']); + $share->setHideDownload((bool)$data['hide_download']); if ($data['uid_initiator'] !== null) { $share->setShareOwner($data['uid_owner']); diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php index 27805691ec..07bba57a19 100644 --- a/apps/sharebymail/tests/ShareByMailProviderTest.php +++ b/apps/sharebymail/tests/ShareByMailProviderTest.php @@ -313,7 +313,7 @@ class ShareByMailProviderTest extends TestCase { ); } - + public function testCreateFailed() { $this->expectException(\Exception::class); @@ -356,7 +356,7 @@ class ShareByMailProviderTest extends TestCase { } - + public function testCreateMailShareFailed() { $this->expectException(\OC\HintException::class); @@ -406,6 +406,7 @@ class ShareByMailProviderTest extends TestCase { $token = 'token'; $password = 'password'; $sendPasswordByTalk = true; + $hideDownload = true; $instance = $this->getInstance(); @@ -421,7 +422,8 @@ class ShareByMailProviderTest extends TestCase { $permissions, $token, $password, - $sendPasswordByTalk + $sendPasswordByTalk, + $hideDownload ] ); @@ -442,6 +444,7 @@ class ShareByMailProviderTest extends TestCase { $this->assertSame($token, $result[0]['token']); $this->assertSame($password, $result[0]['password']); $this->assertSame($sendPasswordByTalk, (bool)$result[0]['password_by_talk']); + $this->assertSame($hideDownload, (bool)$result[0]['hide_download']); } @@ -580,7 +583,7 @@ class ShareByMailProviderTest extends TestCase { $this->assertInstanceOf('OCP\Share\IShare', $result); } - + public function testGetShareByIdFailed() { $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class); @@ -665,7 +668,7 @@ class ShareByMailProviderTest extends TestCase { $this->assertInstanceOf('OCP\Share\IShare', $result); } - + public function testGetShareByTokenFailed() { $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class); @@ -782,7 +785,7 @@ class ShareByMailProviderTest extends TestCase { $this->assertSame($token, $result['token']); } - + public function testGetRawShareFailed() { $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);