UserController: Behave nicely when it's not possible to fetch any users

refs #8826
This commit is contained in:
Johannes Meyer 2015-05-13 13:50:19 +02:00
parent e9fee2dad6
commit 8927121266
2 changed files with 15 additions and 3 deletions

View File

@ -1,12 +1,14 @@
<?php <?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ /* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
use \Exception;
use \Zend_Controller_Action_Exception; use \Zend_Controller_Action_Exception;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Authentication\User\UserBackend; use Icinga\Authentication\User\UserBackend;
use Icinga\Authentication\User\UserBackendInterface; use Icinga\Authentication\User\UserBackendInterface;
use Icinga\Web\Controller; use Icinga\Web\Controller;
use Icinga\Web\Form; use Icinga\Web\Form;
use Icinga\Web\Notification;
use Icinga\Web\Widget; use Icinga\Web\Widget;
class UserController extends Controller class UserController extends Controller
@ -74,12 +76,17 @@ class UserController extends Controller
$query->applyFilter($filterEditor->getFilter()); $query->applyFilter($filterEditor->getFilter());
$this->setupFilterControl($filterEditor); $this->setupFilterControl($filterEditor);
$this->getTabs()->activate('user/list'); try {
$this->view->users = $query->paginate();
$this->setupPaginationControl($this->view->users);
} catch (Exception $e) {
Notification::error($e->getMessage());
}
$this->view->backend = $backend; $this->view->backend = $backend;
$this->view->users = $query->paginate(); $this->getTabs()->activate('user/list');
$this->setupLimitControl(); $this->setupLimitControl();
$this->setupPaginationControl($this->view->users);
$this->setupSortControl( $this->setupSortControl(
array( array(
'user_name' => $this->translate('Username'), 'user_name' => $this->translate('Username'),

View File

@ -18,6 +18,11 @@ if ($backend === null) {
return; return;
} }
if (! isset($users)) {
echo $this->translate('Failed to fetch any users') . '</div>';
return;
}
if (count($users) === 0) { if (count($users) === 0) {
echo $this->translate('No users found matching the filter') . '</div>'; echo $this->translate('No users found matching the filter') . '</div>';
return; return;