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:
Roeland Jago Douma 2019-02-01 10:34:58 +01:00
parent 780e1485c8
commit d88604015a
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 19 additions and 0 deletions

View File

@ -27,6 +27,7 @@ namespace OC\AppFramework\Middleware;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\PublicShareController;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -42,6 +43,14 @@ class AdditionalScriptsMiddleware extends Middleware {
}
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) {
$this->dispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS);

View File

@ -28,6 +28,7 @@ use OC\AppFramework\Middleware\AdditionalScriptsMiddleware;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\PublicShareController;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -67,6 +68,15 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
$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() {
$this->dispatcher->expects($this->once())
->method('dispatch')