From 16f379b9741a2ce9ca0ac3ea0f71a8fc98ce0890 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Wed, 3 Oct 2018 00:06:12 +0200 Subject: [PATCH] Hides the header actions for file drops Signed-off-by: Michael Weimann --- .../lib/Controller/ShareController.php | 1 - .../tests/Controller/ShareControllerTest.php | 103 +++++++++++++++++- 2 files changed, 100 insertions(+), 4 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index 9a8e1298f9..89e619c844 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -61,7 +61,6 @@ use OCA\Files_Sharing\Activity\Providers\Downloads; use OCP\Files\NotFoundException; use OCP\Files\IRootFolder; use OCP\Share\Exceptions\ShareNotFound; -use OCP\Util; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; use OCP\Share\IManager as ShareManager; diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php index 564977c09b..8d7064c031 100644 --- a/apps/files_sharing/tests/Controller/ShareControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php @@ -32,6 +32,7 @@ namespace OCA\Files_Sharing\Tests\Controllers; use OC\Files\Filesystem; +use OC\Files\Node\Folder; use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\Files_Sharing\Controller\ShareController; use OCP\AppFramework\Http\DataResponse; @@ -39,7 +40,9 @@ use OCP\AppFramework\Http\Template\ExternalShareMenuAction; use OCP\AppFramework\Http\Template\LinkMenuAction; use OCP\AppFramework\Http\Template\PublicTemplateResponse; use OCP\AppFramework\Http\Template\SimpleMenuAction; +use OCP\Constants; use OCP\Files\NotFoundException; +use OCP\Files\Storage; use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; @@ -47,14 +50,12 @@ use OCP\IPreview; use OCP\IRequest; use OCP\IUser; use OCP\Share\Exceptions\ShareNotFound; -use OCP\AppFramework\Http\NotFoundResponse; -use OCP\AppFramework\Http\RedirectResponse; -use OCP\AppFramework\Http\TemplateResponse; use OCP\ISession; use OCP\IUserManager; use OCP\Security\ISecureRandom; use OCP\IURLGenerator; use OCP\Share\IShare; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -423,6 +424,102 @@ class ShareControllerTest extends \Test\TestCase { $this->assertEquals($expectedResponse, $response); } + /** + * Checks file drop shares: + * - there must not be any header action + * - the template param "hideFileList" should be true + * + * @test + * @return void + */ + public function testShareFileDrop() { + $this->shareController->setToken('token'); + + $owner = $this->getMockBuilder(IUser::class)->getMock(); + $owner->method('getDisplayName')->willReturn('ownerDisplay'); + $owner->method('getUID')->willReturn('ownerUID'); + + /* @var MockObject|Storage $storage */ + $storage = $this->getMockBuilder(Storage::class) + ->disableOriginalConstructor() + ->getMock(); + + /* @var MockObject|Folder $folder */ + $folder = $this->getMockBuilder(Folder::class) + ->disableOriginalConstructor() + ->getMock(); + $folder->method('getName')->willReturn('/fileDrop'); + $folder->method('isReadable')->willReturn(true); + $folder->method('isShareable')->willReturn(true); + $folder->method('getStorage')->willReturn($storage); + $folder->method('get')->with('')->willReturn($folder); + $folder->method('getSize')->willReturn(1337); + + $share = \OC::$server->getShareManager()->newShare(); + $share->setId(42); + $share->setPermissions(Constants::PERMISSION_CREATE) + ->setShareOwner('ownerUID') + ->setNode($folder) + ->setTarget('/fileDrop'); + + $this->shareManager + ->expects($this->once()) + ->method('getShareByToken') + ->with('token') + ->willReturn($share); + + $this->userManager->method('get')->with('ownerUID')->willReturn($owner); + + $this->l10n->expects($this->any()) + ->method('t') + ->will($this->returnCallback(function($text, $parameters) { + return vsprintf($text, $parameters); + })); + + $response = $this->shareController->showShare(); + // skip the "folder" param for tests + $responseParams = $response->getParams(); + unset($responseParams['folder']); + $response->setParams($responseParams); + + $sharedTmplParams = array( + 'displayName' => 'ownerDisplay', + 'owner' => 'ownerUID', + 'filename' => '/fileDrop', + 'directory_path' => '/fileDrop', + 'mimetype' => null, + 'dirToken' => 'token', + 'sharingToken' => 'token', + 'server2serversharing' => true, + 'protected' => 'false', + 'dir' => null, + 'downloadURL' => '', + 'fileSize' => '1 KB', + 'nonHumanFileSize' => 1337, + 'maxSizeAnimateGif' => null, + 'previewSupported' => null, + 'previewEnabled' => null, + 'previewMaxX' => null, + 'previewMaxY' => null, + 'hideFileList' => true, + 'shareOwner' => 'ownerDisplay', + 'disclaimer' => null, + 'shareUrl' => '', + 'previewImage' => '', + 'previewURL' => '', + 'note' => '' + ); + + $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); + $csp->addAllowedFrameDomain('\'self\''); + $expectedResponse = new PublicTemplateResponse($this->appName, 'public', $sharedTmplParams); + $expectedResponse->setContentSecurityPolicy($csp); + $expectedResponse->setHeaderTitle($sharedTmplParams['filename']); + $expectedResponse->setHeaderDetails('shared by ' . $sharedTmplParams['displayName']); + + self::assertEquals($expectedResponse, $response); + } + /** * @expectedException \OCP\Files\NotFoundException */