[FEATURE] Configurable Route Parameters 00/53000/11
authorJohannes Goslar <jogo@kronberger-spiele.de>
Thu, 1 Jun 2017 16:21:17 +0000 (18:21 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 2 Jun 2017 11:57:37 +0000 (13:57 +0200)
Routes definitions are extended by the possibility to defined default
parameters. Those parameters can be overridden during the regular URI
generation process.

Several AjaxRoutes inhibited the backend session update to not keep the
session alive by periodic polling. Those `skipSessionUpdate` parameters
have been removed from the specific URI generation invocations and moved
to the central route definitions.

Resolves: #81409
Releases: master
Change-Id: I1b7c5cfbb3a10cce774e72406115cbac3e2023f1
Reviewed-on: https://review.typo3.org/53000
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Routing/UriBuilder.php
typo3/sysext/backend/Configuration/Backend/AjaxRoutes.php
typo3/sysext/backend/Resources/Public/JavaScript/LoginRefresh.js
typo3/sysext/backend/Tests/Unit/Routing/UriBuilderTest.php [new file with mode: 0644]
typo3/sysext/core/Documentation/Changelog/master/Feature-81409-Configurable-Route-Parameters.rst [new file with mode: 0644]
typo3/sysext/rsaauth/Configuration/Backend/AjaxRoutes.php
typo3/sysext/rsaauth/Resources/Public/JavaScript/RsaEncryptionModule.js

index 8e7d171..7f546e5 100644 (file)
@@ -74,6 +74,10 @@ class UriBuilder
         }
 
         $route = $this->routes[$name];
+        $parameters = array_merge(
+            $route->getOptions()['parameters'] ?? [],
+            $parameters
+        );
 
         // The Route is an AJAX route, so the parameters are different in order
         // for the AjaxRequestHandler to be triggered
index b314f20..ef9c745 100644 (file)
@@ -103,7 +103,10 @@ return [
     // Render systeminformtion toolbar item
     'systeminformation_render' => [
         'path' => '/system-information/render',
-        'target' => \TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem::class . '::renderMenuAction'
+        'target' => \TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem::class . '::renderMenuAction',
+        'parameters' => [
+            'skipSessionUpdate' => 1
+        ]
     ],
 
     // Reload the module menu
@@ -140,7 +143,10 @@ return [
     'login_timedout' => [
         'path' => '/login/timedout',
         'target' => \TYPO3\CMS\Backend\AjaxLoginHandler::class . '::isTimedOutAction',
-        'access' => 'public'
+        'access' => 'public',
+        'parameters' => [
+            'skipSessionUpdate' => 1
+        ]
     ],
 
     // ExtDirect routing
index c294442..02fd17c 100644 (file)
@@ -436,9 +436,6 @@ define(['jquery', 'TYPO3/CMS/Backend/Notification', 'bootstrap'], function($, Ty
        LoginRefresh.checkActiveSession = function() {
                $.ajax({
                        url: TYPO3.settings.ajaxUrls['login_timedout'],
-                       data: {
-                               skipSessionUpdate: 1
-                       },
                        success: function(response) {
                                if (response.login.locked) {
                                        if (!LoginRefresh.backendIsLocked) {
diff --git a/typo3/sysext/backend/Tests/Unit/Routing/UriBuilderTest.php b/typo3/sysext/backend/Tests/Unit/Routing/UriBuilderTest.php
new file mode 100644 (file)
index 0000000..667c348
--- /dev/null
@@ -0,0 +1,123 @@
+<?php
+namespace TYPO3\CMS\Backend\Tests\Unit\Routing;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
+use TYPO3\CMS\Backend\Routing\Route;
+use TYPO3\CMS\Backend\Routing\UriBuilder;
+use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+/**
+ * Test case
+ */
+class UriBuilderTest extends UnitTestCase
+{
+    /**
+     * @var UriBuilder|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
+     */
+    protected $uriBuilder;
+
+    protected function setUp()
+    {
+        parent::setUp();
+        $this->uriBuilder = $this->getAccessibleMock(UriBuilder::class, ['loadBackendRoutes']);
+    }
+
+    protected function tearDown()
+    {
+        unset($this->uriBuilder);
+    }
+
+    /**
+     * @return array
+     */
+    public function validRoutesAreBuiltDataProvider()
+    {
+        return [
+            'plain route' => [
+                [ 'route' => new Route('/test/route', []) ],
+                'route',
+                [],
+                '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken',
+            ],
+            'AJAX route' => [
+                [ 'route' => new Route('/test/route', [ 'ajax' => true ]) ],
+                'route',
+                [],
+                '/typo3/index.php?ajaxID=%2Ftest%2Froute&ajaxToken=dummyToken',
+            ],
+            'plain route with default parameters' => [
+                [ 'route' => new Route('/test/route', [ 'parameters' => [ 'key' => 'value' ] ]) ],
+                'route',
+                [],
+                '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken&key=value',
+            ],
+            'AJAX route with default parameters' => [
+                [ 'route' => new Route('/test/route', [ 'ajax' => true, 'parameters' => [ 'key' => 'value' ] ]) ],
+                'route',
+                [],
+                '/typo3/index.php?ajaxID=%2Ftest%2Froute&ajaxToken=dummyToken&key=value',
+            ],
+            'plain route with overridden parameters' => [
+                [ 'route' => new Route('/test/route', [ 'parameters' => [ 'key' => 'value' ] ]) ],
+                'route',
+                ['key' => 'overridden'],
+                '/typo3/index.php?route=%2Ftest%2Froute&token=dummyToken&key=overridden',
+            ],
+            'AJAX route with overridden parameters' => [
+                [ 'route' => new Route('/test/route', [ 'ajax' => true, 'parameters' => [ 'key' => 'value' ] ]) ],
+                'route',
+                ['key' => 'overridden'],
+                '/typo3/index.php?ajaxID=%2Ftest%2Froute&ajaxToken=dummyToken&key=overridden',
+            ],
+        ];
+    }
+
+    /**
+     * @param Route[] $routes
+     * @param string $routeName
+     * @param array $routeParameters
+     * @param string $expectation
+     *
+     * @test
+     * @dataProvider validRoutesAreBuiltDataProvider
+     */
+    public function validRoutesAreBuilt(
+        array $routes,
+        string $routeName,
+        array $routeParameters,
+        string $expectation
+    ) {
+        $this->uriBuilder->_set('routes', $routes);
+
+        $uri = $this->uriBuilder->buildUriFromRoute(
+            $routeName,
+            $routeParameters
+        );
+
+        $this->assertEquals($expectation, $uri->__toString());
+    }
+
+    /**
+     * @test
+     */
+    public function nonExistingRouteThrowsException()
+    {
+        $this->expectException(RouteNotFoundException::class);
+        $this->expectExceptionCode(1476050190);
+        $this->uriBuilder->buildUriFromRoute(uniqid('any'));
+    }
+}
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-81409-Configurable-Route-Parameters.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-81409-Configurable-Route-Parameters.rst
new file mode 100644 (file)
index 0000000..339427d
--- /dev/null
@@ -0,0 +1,37 @@
+.. include:: ../../Includes.txt
+
+===============================================
+Feature: #81409 - Configurable Route Parameters
+===============================================
+
+See :issue:`81409`
+
+Description
+===========
+
+Routes definitions are extended by the possibility to defined default parameters.
+Those parameters can be overridden during the regular URI generation process.
+
+Several AjaxRoutes inhibited the backend session update to not keep the session
+alive by periodic polling. Those `skipSessionUpdate` parameters have been removed
+from the specific URI generation invocations and moved to the central route definitions.
+
+Default route parameters are defined in an associative key-value-array using the
+index `parameters`. This definition can be used for both, plain routes and AJAX routes.
+
+.. code-block:: php
+
+    'systeminformation_render' => [
+        'path' => '/system-information/render',
+        'target' => \TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem::class . '::renderMenuAction',
+        'parameters' => [
+            'skipSessionUpdate' => 1
+        ]
+    ]
+
+Impact
+======
+
+Developers have easier and more standardized control over AjaxRoute parameters.
+
+.. index:: JavaScript, Backend
index 9ceae86..7af395f 100644 (file)
@@ -8,6 +8,9 @@ return [
     'rsa_publickey' => [
         'path' => '/rsa/publickey',
         'target' => \TYPO3\CMS\Rsaauth\RsaEncryptionEncoder::class . '::getRsaPublicKeyAjaxHandler',
-        'access' => 'public'
+        'access' => 'public',
+        'parameters' => [
+            'skipSessionUpdate' => 1
+        ]
     ],
 ];
index 41eb330..6ae8daf 100644 (file)
@@ -75,7 +75,6 @@ define(['jquery', './RsaLibrary'], function($) {
 
                                $.ajax({
                                        url: TYPO3.settings.ajaxUrls['rsa_publickey'],
-                                       data: {'skipSessionUpdate': 1},
                                        success: RsaEncryption.handlePublicKeyResponse
                                });