No need to emit additonalscript event on public pages
There already is a separate event for this. This will make it possible to only inject code with the logged in one on default rendered pages. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
780e1485c8
commit
d88604015a
|
@ -27,6 +27,7 @@ namespace OC\AppFramework\Middleware;
|
||||||
use OCP\AppFramework\Http\Response;
|
use OCP\AppFramework\Http\Response;
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
use OCP\AppFramework\Middleware;
|
use OCP\AppFramework\Middleware;
|
||||||
|
use OCP\AppFramework\PublicShareController;
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
|
@ -42,6 +43,14 @@ class AdditionalScriptsMiddleware extends Middleware {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function afterController($controller, $methodName, Response $response): Response {
|
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) {
|
if ($response instanceof TemplateResponse) {
|
||||||
$this->dispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS);
|
$this->dispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS);
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ use OC\AppFramework\Middleware\AdditionalScriptsMiddleware;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\Response;
|
use OCP\AppFramework\Http\Response;
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\AppFramework\PublicShareController;
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
@ -67,6 +68,15 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
|
||||||
$this->middleWare->afterController($this->controller, 'myMethod', $this->createMock(Response::class));
|
$this->middleWare->afterController($this->controller, 'myMethod', $this->createMock(Response::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPublicShareController() {
|
||||||
|
$this->dispatcher->expects($this->never())
|
||||||
|
->method($this->anything());
|
||||||
|
$this->userSession->expects($this->never())
|
||||||
|
->method($this->anything());
|
||||||
|
|
||||||
|
$this->middleWare->afterController($this->createMock(PublicShareController::class), 'myMethod', $this->createMock(Response::class));
|
||||||
|
}
|
||||||
|
|
||||||
public function testTemplateResponseNotLoggedIn() {
|
public function testTemplateResponseNotLoggedIn() {
|
||||||
$this->dispatcher->expects($this->once())
|
$this->dispatcher->expects($this->once())
|
||||||
->method('dispatch')
|
->method('dispatch')
|
||||||
|
|
Loading…
Reference in New Issue