diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-09-28 17:03:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-28 17:03:16 +0300 |
commit | 3cf46e62f02337ea693472ad28b67d1f765a2875 (patch) | |
tree | 4f58554417b473b9b84d4797fc04a586b9e59caf | |
parent | 789e214108b6a2fb9b7cb1c0b8558b96449d806f (diff) | |
parent | 8ab2422b6c34e5b0b6d1756cbadbb01899019456 (diff) |
Merge pull request #23012 from nextcloud/enh/template-reponse-renderas
Make BeforeTemplateRenderedEvent aware of the actual response
3 files changed, 15 insertions, 3 deletions
diff --git a/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php b/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php index fa3d8ce9e68..0daaaa9fcf2 100644 --- a/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php +++ b/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php @@ -28,6 +28,7 @@ namespace OCA\UserStatus\Listener; use OCA\UserStatus\AppInfo\Application; use OCA\UserStatus\Service\JSDataService; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\AppFramework\Http\TemplateResponse; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\IInitialStateService; @@ -61,7 +62,7 @@ class BeforeTemplateRenderedListener implements IEventListener { return; } - if (!$event->isLoggedIn()) { + if (!$event->isLoggedIn() || $event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_USER) { return; } diff --git a/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php b/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php index 6c65ee8b2c6..28f322f42b7 100644 --- a/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php +++ b/lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php @@ -71,7 +71,7 @@ class AdditionalScriptsMiddleware extends Middleware { $isLoggedIn = false; } - $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn)); + $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response)); } return $response; diff --git a/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php b/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php index 3d48e9a269d..b96b86abd57 100644 --- a/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php +++ b/lib/public/AppFramework/Http/Events/BeforeTemplateRenderedEvent.php @@ -27,6 +27,7 @@ declare(strict_types=1); namespace OCP\AppFramework\Http\Events; +use OCP\AppFramework\Http\TemplateResponse; use OCP\EventDispatcher\Event; /** @@ -38,14 +39,17 @@ use OCP\EventDispatcher\Event; class BeforeTemplateRenderedEvent extends Event { /** @var bool */ private $loggedIn; + /** @var TemplateResponse */ + private $response; /** * @since 20.0.0 */ - public function __construct(bool $loggedIn) { + public function __construct(bool $loggedIn, TemplateResponse $response) { parent::__construct(); $this->loggedIn = $loggedIn; + $this->response = $response; } /** @@ -54,4 +58,11 @@ class BeforeTemplateRenderedEvent extends Event { public function isLoggedIn(): bool { return $this->loggedIn; } + + /** + * @since 20.0.0 + */ + public function getResponse(): TemplateResponse { + return $this->response; + } } |