icingadb-web/application/controllers/UserController.php

70 lines
2.1 KiB
PHP
Raw Normal View History

2019-10-31 12:40:31 -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-31 12:40:31 -04:00
use Icinga\Exception\NotFoundError;
2019-11-04 19:07:30 -05:00
use Icinga\Module\Icingadb\Model\User;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\ItemList\UserList;
use Icinga\Security\SecurityException;
2019-10-31 12:40:31 -04:00
use ipl\Html\Html;
class UserController extends Controller
{
/** @var User The user object */
protected $user;
public function init()
{
if (! $this->hasPermission('*') && $this->hasPermission('no-monitoring/contacts')) {
throw new SecurityException($this->translate('No permission for %s'), 'monitoring/contacts');
}
2019-10-31 12:40:31 -04:00
$this->setTitle($this->translate('User'));
$name = $this->params->shiftRequired('name');
$query = User::on($this->getDb());
$query->getSelectBase()
->where(['user.name = ?' => $name]);
2019-10-31 12:40:31 -04:00
$this->applyMonitoringRestriction($query);
2019-10-31 12:40:31 -04:00
$user = $query->first();
if ($user === null) {
throw new NotFoundError($this->translate('User not found'));
}
$this->user = $user;
}
public function indexAction()
{
$this->addControl(new UserList([$this->user]));
$this->addContent(Html::tag('h2', $this->translate('Details')));
2019-10-31 12:40:31 -04:00
$this->addContent(Html::tag('ul', ['class' => 'key-value-list'], [
Html::tag('li', [
Html::tag('span', ['class' => 'label'], $this->translate('E-Mail')),
2019-10-31 12:40:31 -04:00
Html::tag(
'span',
['class' => 'value'],
$this->user->email ?: Html::tag('span', ['class' => 'text-muted'], $this->translate('Unset'))
2019-10-31 12:40:31 -04:00
)
]),
Html::tag('li', [
Html::tag('span', ['class' => 'label'], $this->translate('Pager')),
2019-10-31 12:40:31 -04:00
Html::tag(
'span',
['class' => 'value'],
$this->user->pager ?: Html::tag('span', ['class' => 'text-muted'], $this->translate('Unset'))
2019-10-31 12:40:31 -04:00
)
])
]));
$this->setAutorefreshInterval(10);
2019-10-31 12:40:31 -04:00
}
}