diff --git a/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php b/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php index fa3d8ce9e6..0daaaa9fcf 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 6c65ee8b2c..28f322f42b 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 3d48e9a269..79c6825d0d 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.1 + */ + public function getResponse(): TemplateResponse { + return $this->response; + } }