Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loadAdditionalScripts hook when displaying public link page #31480

Merged
merged 1 commit into from
Jun 28, 2018

Conversation

PVince81
Copy link
Contributor

Description

Makes it possibles for apps to load custom JS code or styles as required
for file viewers.

Related Issue

Fixes #22328

Motivation and Context

How Has This Been Tested?

Unit test

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Contributor

@sharidas sharidas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@PVince81
Copy link
Contributor Author

   1) apps/files_sharing/tests/Controllers/ShareControllerTest.php (class_definition, function_declaration, braces)
      ---------- begin diff ----------
--- Original
+++ New
@@ @@
 		$loadAdditionalScriptsCalled = false;
-		$this->eventDispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', function() use (&$loadAdditionalScriptsCalled) {
+		$this->eventDispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', function () use (&$loadAdditionalScriptsCalled) {
 			$loadAdditionalScriptsCalled = true;
 		});
 
 		$response = $this->shareController->showShare('token');
 		$sharedTmplParams = [
 			'displayName' => 'ownerDisplay',
 			'owner' => 'ownerUID',
 			'filename' => 'file1.txt',
 			'directory_path' => '/file1.txt',
 			'mimetype' => 'text/plain',
 			'dirToken' => 'token',
 			'sharingToken' => 'token',
 			'protected' => 'true',
 			'dir' => '',
 			'downloadURL' => null,
 			'fileSize' => '33 B',
 			'nonHumanFileSize' => 33,
 			'maxSizeAnimateGif' => 10,
 			'previewSupported' => true,
 			'previewEnabled' => true,
 			'previewMaxX' => 1024,
 			'previewMaxY' => 1024,
 			'shareUrl' => null,
 			'previewImage' => null,
 			'canDownload' => true,
 		];
 
 		$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
 		$csp->addAllowedFrameDomain('\'self\'');
 		$expectedResponse = new TemplateResponse($this->appName, 'public', $sharedTmplParams, 'base');
 		$expectedResponse->setContentSecurityPolicy($csp);
 
 		$this->assertEquals($expectedResponse, $response);
 
 		$this->assertTrue($loadAdditionalScriptsCalled, 'Hook for loading additional scripts was called');
 	}
 
 	/**
 	 * @expectedException \OCP\Files\NotFoundException
 	 */
 	public function testShowShareInvalid() {
 		$owner = $this->createMock('OCP\IUser');
 		$owner->method('getDisplayName')->willReturn('ownerDisplay');
 		$owner->method('getUID')->willReturn('ownerUID');
 
 		$file = $this->createMock('OCP\Files\File');
 		$file->method('getName')->willReturn('file1.txt');
 		$file->method('getMimetype')->willReturn('text/plain');
 		$file->method('getSize')->willReturn(33);
 		$file->method('isShareable')->willReturn(false);
 		$file->method('isReadable')->willReturn(true);
 
 		$share = \OC::$server->getShareManager()->newShare();
 		$share->setId(42);
 		$share->setPassword('password')
 			->setShareOwner('ownerUID')
 			->setNode($file)
 			->setTarget('/file1.txt');
 
 		$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
 		$this->session->method('get')->with('public_link_authenticated')->willReturn('42');
 
 		$this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
 
 		$this->config->method('getSystemValue')
 			->willReturnMap(
 				[
 					['max_filesize_animated_gifs_public_sharing', 10, 10],
 					['enable_previews', true, true],
 				]
 			);
 		$shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
 		$shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
 
 		$this->shareManager
 			->expects($this->once())
 			->method('getShareByToken')
 			->with('token')
 			->willReturn($share);
 
 		$this->userManager->method('get')->with('ownerUID')->willReturn($owner);
 
 		$this->shareController->showShare('token');
 	}
 
 	public function testDownloadShare() {
 		$share = $this->createMock('\OCP\Share\IShare');
 		$share->method('getPassword')->willReturn('password');
 
 		$this->shareManager
 			->expects($this->once())
 			->method('getShareByToken')
 			->with('validtoken')
 			->willReturn($share);
 
 		$this->urlGenerator->expects($this->once())
 			->method('linkToRoute')
 			->with('files_sharing.sharecontroller.authenticate', ['token' => 'validtoken'])
 			->willReturn('redirect');
 
 		// Test with a password protected share and no authentication
 		$response = $this->shareController->downloadShare('validtoken');
 		$expectedResponse = new RedirectResponse('redirect');
 		$this->assertEquals($expectedResponse, $response);
 	}
 
 	/**
 	 * @expectedException \OCP\Files\NotFoundException
 	 */
 	public function testDownloadShareNoReadPermission() {
 		$share = $this->createMock('\OCP\Share\IShare');
 		$share->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_CREATE);
 
 		$this->shareManager
 			->expects($this->once())
 			->method('getShareByToken')
 			->with('validtoken')
 			->willReturn($share);
 
 		$this->shareController->downloadShare('validtoken');
 	}
 }
 

----------- end diff -----------

there's an error from php-cs-fixer but I can't find any useful information to help me fix it

@codecov
Copy link

codecov bot commented May 22, 2018

Codecov Report

Merging #31480 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #31480      +/-   ##
============================================
+ Coverage     63.46%   63.46%   +<.01%     
  Complexity    18532    18532              
============================================
  Files          1167     1167              
  Lines         69503    69504       +1     
  Branches       1264     1264              
============================================
+ Hits          44113    44114       +1     
  Misses        25021    25021              
  Partials        369      369
Flag Coverage Δ Complexity Δ
#javascript 52.58% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 64.71% <100%> (ø) 18532 <0> (ø) ⬇️
Impacted Files Coverage Δ Complexity Δ
.../files_sharing/lib/Controllers/ShareController.php 53.52% <100%> (+0.21%) 54 <0> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a423c84...741ff1f. Read the comment docs.

@phil-davis
Copy link
Contributor

function()
function ()

and #31484 will reduce the crazy long diff output and give some line number hints.

Makes it possibles for apps to load custom JS code or styles as required
for file viewers.
@PVince81 PVince81 force-pushed the files_sharing_loadadditionalscripts branch from 1aac44c to 741ff1f Compare June 28, 2018 11:47
@PVince81 PVince81 merged commit 9a5f0f1 into master Jun 28, 2018
@PVince81 PVince81 deleted the files_sharing_loadadditionalscripts branch June 28, 2018 14:10
@PVince81
Copy link
Contributor Author

stable10: #31944

@lock
Copy link

lock bot commented Jul 30, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

files_sharing is missing loadAdditionalScripts
4 participants