Skip to content

Commit

Permalink
[TASK] Define callable controller actions
Browse files Browse the repository at this point in the history
Several custom controller implementations allow calling internal
*Action methods. In order to avoid unintended behavior and to
streamline the application flow those invocations are
defined now explicitly.

ManagementController just had one possible action method and has been
simplified in this regard.

Resolves: #91564
Releases: master, 10.4, 9.5
Change-Id: I9092088ba66504562b42c522883c022955fa6f36
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64776
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
ohader authored and lolli42 committed Oct 2, 2020
1 parent 505fe2d commit 38e75d9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions typo3/sysext/backend/Classes/Controller/HelpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
*/
class HelpController
{
protected const ALLOWED_ACTIONS = ['index', 'all', 'detail'];

/**
* Section identifiers
*/
Expand Down Expand Up @@ -86,6 +88,10 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
}
}

if (!in_array($action, self::ALLOWED_ACTIONS, true)) {
return new HtmlResponse('Action not allowed', 400);
}

$this->initializeView($action);

$result = call_user_func_array([$this, $action . 'Action'], [$request]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
*/
class SiteConfigurationController
{
protected const ALLOWED_ACTIONS = ['overview', 'edit', 'save', 'delete'];

/**
* @var ModuleTemplate
*/
Expand Down Expand Up @@ -94,7 +96,13 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
$this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
$this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
$action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'overview';

if (!in_array($action, self::ALLOWED_ACTIONS, true)) {
return new HtmlResponse('Action not allowed', 400);
}

$this->initializeView($action);

$result = call_user_func_array([$this, $action . 'Action'], [$request]);
if ($result instanceof ResponseInterface) {
return $result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,9 @@ public function __construct()
public function handleRequest(ServerRequestInterface $request): ResponseInterface
{
$this->request = $request;
$action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'overview';
$this->initializeView($action);
$this->initializeView('overview');

$result = call_user_func_array([$this, $action . 'Action'], [$request]);
if ($result instanceof ResponseInterface) {
return $result;
}
$this->overviewAction($request);
$this->moduleTemplate->setContent($this->view->render());
return new HtmlResponse($this->moduleTemplate->renderContent());
}
Expand Down

0 comments on commit 38e75d9

Please sign in to comment.