icingadb-web/application/controllers/UsersController.php

76 lines
2.1 KiB
PHP
Raw Normal View History

2019-10-24 07:59:20 -04:00
<?php
2020-03-13 03:38:01 -04:00
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
2019-11-04 19:07:30 -05:00
namespace Icinga\Module\Icingadb\Controllers;
2019-10-24 07:59:20 -04:00
2020-11-02 08:33:32 -05:00
use GuzzleHttp\Psr7\ServerRequest;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Model\User;
2020-11-02 08:33:32 -05:00
use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\ItemList\UserList;
use Icinga\Security\SecurityException;
2019-10-24 07:59:20 -04:00
class UsersController extends Controller
{
public function init()
{
parent::init();
if (! $this->hasPermission('*') && $this->hasPermission('no-monitoring/contacts')) {
throw new SecurityException(t('No permission for %s'), 'monitoring/contacts');
}
}
2019-10-24 07:59:20 -04:00
public function indexAction()
{
$this->setTitle(t('Users'));
2019-10-24 07:59:20 -04:00
$db = $this->getDb();
$users = User::on($db);
2020-11-02 08:33:32 -05:00
$this->handleSearchRequest($users);
2019-10-24 07:59:20 -04:00
$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($users);
2019-12-11 08:01:06 -05:00
$sortControl = $this->createSortControl(
$users,
[
'user.display_name' => t('Name'),
'user.email' => t('Email'),
'user.pager' => t('Pager Address / Number')
2019-12-11 08:01:06 -05:00
]
);
2020-11-02 08:33:32 -05:00
$searchBar = $this->createSearchBar($users, [
$limitControl->getLimitParam(),
$sortControl->getSortParam()
]);
2019-10-24 07:59:20 -04:00
2020-11-02 08:33:32 -05:00
$this->filter($users, $searchBar->getFilter());
2019-10-24 07:59:20 -04:00
yield $this->export($users);
$this->addControl($paginationControl);
2019-12-11 08:01:06 -05:00
$this->addControl($sortControl);
2019-10-24 07:59:20 -04:00
$this->addControl($limitControl);
2020-11-02 08:33:32 -05:00
$this->addControl($searchBar);
2019-10-24 07:59:20 -04:00
$this->addContent(new UserList($users));
2020-11-02 08:33:32 -05:00
if ($searchBar->hasBeenSent()) {
$this->sendMultipartUpdate();
}
$this->setAutorefreshInterval(10);
2019-10-24 07:59:20 -04:00
}
2020-11-02 08:33:32 -05:00
public function completeAction()
{
$suggestions = new ObjectSuggestions();
$suggestions->setModel(User::class);
$suggestions->forRequest(ServerRequest::fromGlobals());
$this->getDocument()->add($suggestions);
}
2019-10-24 07:59:20 -04:00
}