From ba26dbe761b37785c17592646c89e175eaba5f3e Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Fri, 11 Aug 2023 15:11:59 +0200 Subject: [PATCH] Controller::createColumnControl(): Make columns mandatory in `tabular` view mode --- library/Icingadb/Web/Controller.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/library/Icingadb/Web/Controller.php b/library/Icingadb/Web/Controller.php index 957100079..49bd1c799 100644 --- a/library/Icingadb/Web/Controller.php +++ b/library/Icingadb/Web/Controller.php @@ -14,6 +14,7 @@ use Icinga\Data\ConfigObject; use Icinga\Date\DateFormatter; use Icinga\Exception\ConfigurationError; +use Icinga\Exception\Http\HttpBadRequestException; use Icinga\Exception\Json\JsonDecodeException; use Icinga\Module\Icingadb\Common\Auth; use Icinga\Module\Icingadb\Common\BaseItemTable; @@ -72,12 +73,27 @@ public function getFilter(): Filter\Rule return $this->filter; } - public function createColumnControl(Query $query, ViewModeSwitcher $viewModeSwitcher) + /** + * Create column control + * + * @param Query $query + * @param ViewModeSwitcher $viewModeSwitcher + * + * @return array provided columns + * + * @throws HttpBadRequestException + */ + public function createColumnControl(Query $query, ViewModeSwitcher $viewModeSwitcher): array { // All of that is essentially what `ColumnControl::apply()` should do + $viewMode = $this->getRequest()->getUrl()->getParam($viewModeSwitcher->getViewModeParam()); $columnsDef = $this->params->shift('columns'); if (! $columnsDef) { - return null; + if ($viewMode === 'tabular') { + $this->httpBadRequest('Missing parameter "columns"'); + } + + return []; } $columns = []; @@ -89,7 +105,7 @@ public function createColumnControl(Query $query, ViewModeSwitcher $viewModeSwit $query->withColumns($columns); - if (! $this->getRequest()->getUrl()->hasParam($viewModeSwitcher->getViewModeParam())) { + if (! $viewMode) { $viewModeSwitcher->setViewMode('tabular'); }