From 5c7c30822067ce99ecfa7cff803b28a86b8554c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 17 Oct 2019 10:27:13 +0200 Subject: [PATCH] Include the share in the Files_Sharing::loadAdditionalScripts event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This provides a better context for apps using the event, for example to load one script or another depending on whether the share is a file or a folder. Signed-off-by: Daniel Calviño Sánchez --- .../lib/Controller/ShareController.php | 3 ++- .../tests/Controller/ShareControllerTest.php | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index 0725e520b2d3f..f5cbb63e08315 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -445,7 +445,8 @@ public function showShare($path = ''): TemplateResponse { \OCP\Util::addHeader('meta', ['property' => "og:type", 'content' => "object"]); \OCP\Util::addHeader('meta', ['property' => "og:image", 'content' => $ogPreview]); - $this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts'); + $event = new GenericEvent(null, ['share' => $share]); + $this->eventDispatcher->dispatch('OCA\Files_Sharing::loadAdditionalScripts', $event); $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); $csp->addAllowedFrameDomain('\'self\''); diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php index ea9bd8316e203..97e234ca22c30 100644 --- a/apps/files_sharing/tests/Controller/ShareControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php @@ -254,7 +254,12 @@ public function testShowShare() { $this->eventDispatcher->expects($this->once()) ->method('dispatch') - ->with('OCA\Files_Sharing::loadAdditionalScripts'); + ->with( + 'OCA\Files_Sharing::loadAdditionalScripts', + $this->callback(function($event) use ($share) { + return $event->getArgument('share') === $share; + }) + ); $this->l10n->expects($this->any()) ->method('t') @@ -374,7 +379,12 @@ public function testShowShareHideDownload() { $this->eventDispatcher->expects($this->once()) ->method('dispatch') - ->with('OCA\Files_Sharing::loadAdditionalScripts'); + ->with( + 'OCA\Files_Sharing::loadAdditionalScripts', + $this->callback(function($event) use ($share) { + return $event->getArgument('share') === $share; + }) + ); $this->l10n->expects($this->any()) ->method('t')