Merge pull request #23205 from nextcloud/backport/23012/stable20

[stable20] Make BeforeTemplateRenderedEvent aware of the actual response
This commit is contained in:
Morris Jobke 2020-10-19 10:15:22 +02:00 committed by GitHub
commit 41090d0faa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View File

@ -28,6 +28,7 @@ namespace OCA\UserStatus\Listener;
use OCA\UserStatus\AppInfo\Application; use OCA\UserStatus\AppInfo\Application;
use OCA\UserStatus\Service\JSDataService; use OCA\UserStatus\Service\JSDataService;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event; use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener; use OCP\EventDispatcher\IEventListener;
use OCP\IInitialStateService; use OCP\IInitialStateService;
@ -61,7 +62,7 @@ class BeforeTemplateRenderedListener implements IEventListener {
return; return;
} }
if (!$event->isLoggedIn()) { if (!$event->isLoggedIn() || $event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_USER) {
return; return;
} }

View File

@ -71,7 +71,7 @@ class AdditionalScriptsMiddleware extends Middleware {
$isLoggedIn = false; $isLoggedIn = false;
} }
$this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn)); $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response));
} }
return $response; return $response;

View File

@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OCP\AppFramework\Http\Events; namespace OCP\AppFramework\Http\Events;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event; use OCP\EventDispatcher\Event;
/** /**
@ -38,14 +39,17 @@ use OCP\EventDispatcher\Event;
class BeforeTemplateRenderedEvent extends Event { class BeforeTemplateRenderedEvent extends Event {
/** @var bool */ /** @var bool */
private $loggedIn; private $loggedIn;
/** @var TemplateResponse */
private $response;
/** /**
* @since 20.0.0 * @since 20.0.0
*/ */
public function __construct(bool $loggedIn) { public function __construct(bool $loggedIn, TemplateResponse $response) {
parent::__construct(); parent::__construct();
$this->loggedIn = $loggedIn; $this->loggedIn = $loggedIn;
$this->response = $response;
} }
/** /**
@ -54,4 +58,11 @@ class BeforeTemplateRenderedEvent extends Event {
public function isLoggedIn(): bool { public function isLoggedIn(): bool {
return $this->loggedIn; return $this->loggedIn;
} }
/**
* @since 20.0.1
*/
public function getResponse(): TemplateResponse {
return $this->response;
}
} }