From e1b696929fe5f7a1f5f967c6833f7ca5bd4ecc7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 24 Jul 2020 07:53:48 +0200 Subject: [PATCH] Move NotFoundResponse to a proper TemplateResponse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../Middleware/AdditionalScriptsMiddleware.php | 17 ++++++++--------- .../AppFramework/Http/NotFoundResponse.php | 15 ++------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php b/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php index 619432be78..9eafd5b740 100644 --- a/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php +++ b/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php @@ -53,16 +53,15 @@ class AdditionalScriptsMiddleware extends Middleware { } public function afterController($controller, $methodName, Response $response): Response { - /* - * There is no need to emit these signals on a public share page - * There is a separate event for that already - */ - if ($controller instanceof PublicShareController) { - return $response; - } - if ($response instanceof TemplateResponse) { - $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent()); + if (!$controller instanceof PublicShareController) { + /* + * The old event was not dispatched on the public share controller as there was + * OCA\Files_Sharing::loadAdditionalScripts for that. This is kept for compatibility reasons + * only for the old event as this is now also included in BeforeTemplateRenderedEvent + */ + $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent()); + } if (!($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn()) { $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent()); diff --git a/lib/public/AppFramework/Http/NotFoundResponse.php b/lib/public/AppFramework/Http/NotFoundResponse.php index ffebfdf3c7..9bf08443a8 100644 --- a/lib/public/AppFramework/Http/NotFoundResponse.php +++ b/lib/public/AppFramework/Http/NotFoundResponse.php @@ -24,30 +24,19 @@ namespace OCP\AppFramework\Http; -use OCP\Template; - /** * A generic 404 response showing an 404 error page as well to the end-user * @since 8.1.0 */ -class NotFoundResponse extends Response { +class NotFoundResponse extends TemplateResponse { /** * @since 8.1.0 */ public function __construct() { - parent::__construct(); + parent::__construct('core', '404', [], 'guest'); $this->setContentSecurityPolicy(new ContentSecurityPolicy()); $this->setStatus(404); } - - /** - * @return string - * @since 8.1.0 - */ - public function render() { - $template = new Template('core', '404', 'guest'); - return $template->fetchPage(); - } }