Skip to content

Commit

Permalink
Merge pull request #23012 from nextcloud/enh/template-reponse-renderas
Browse files Browse the repository at this point in the history
Make BeforeTemplateRenderedEvent aware of the actual response
  • Loading branch information
rullzer committed Sep 28, 2020
2 parents 789e214 + 8ab2422 commit 3cf46e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -61,7 +62,7 @@ public function handle(Event $event): void {
return;
}

if (!$event->isLoggedIn()) {
if (!$event->isLoggedIn() || $event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_USER) {
return;
}

Expand Down
Expand Up @@ -71,7 +71,7 @@ public function afterController($controller, $methodName, Response $response): R
$isLoggedIn = false;
}

$this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn));
$this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn, $response));
}

return $response;
Expand Down
Expand Up @@ -27,6 +27,7 @@

namespace OCP\AppFramework\Http\Events;

use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event;

/**
Expand All @@ -38,14 +39,17 @@
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;
}

/**
Expand All @@ -54,4 +58,11 @@ public function __construct(bool $loggedIn) {
public function isLoggedIn(): bool {
return $this->loggedIn;
}

/**
* @since 20.0.0
*/
public function getResponse(): TemplateResponse {
return $this->response;
}
}

0 comments on commit 3cf46e6

Please sign in to comment.