User: add table, form, object

This commit is contained in:
Alexander Fuhr 2015-06-01 17:00:02 +02:00
parent c118b24056
commit 39c53813e7
6 changed files with 161 additions and 0 deletions

View File

@ -37,6 +37,17 @@ class Director_ListController extends ActionController
$this->render('table'); $this->render('table');
} }
public function usersAction()
{
$this->view->addLink = $this->view->qlink(
$this->translate('Add User'),
'director/object/user'
);
$this->view->title = $this->translate('Icinga Users');
$this->view->table = $this->loadTable('icingaUser')->setConnection($this->db());
$this->render('table');
}
public function zonesAction() public function zonesAction()
{ {
$this->view->addLink = $this->view->qlink( $this->view->addLink = $this->view->qlink(

View File

@ -52,6 +52,22 @@ class Director_ObjectController extends ActionController
$this->render('form'); $this->render('form');
} }
public function userAction()
{
$this->view->form = $this->loadForm('icingaUser')
->setDb($this->db())
->setSuccessUrl('director/list/users');
if ($id = $this->params->get('id')) {
$this->view->form->loadObject($id);
$this->view->title = $this->translate('Modify Icinga User');
} else {
$this->view->title = $this->translate('Add new Icinga User');
}
$this->view->form->handleRequest();
$this->render('form');
}
public function zoneAction() public function zoneAction()
{ {
$this->view->form = $this->loadForm('icingaZone') $this->view->form = $this->loadForm('icingaZone')

View File

@ -0,0 +1,60 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaUserForm extends DirectorObjectForm
{
public function setup()
{
$isTemplate = isset($_POST['object_type']) && $_POST['object_type'] === 'template';
$this->addElement('select', 'object_type', array(
'label' => $this->translate('Object type'),
'description' => $this->translate('Whether this should be a template'),
'multiOptions' => array(
null => '- please choose -',
'object' => 'User object',
'template' => 'User template',
)
));
if ($isTemplate) {
$this->addElement('text', 'object_name', array(
'label' => $this->translate('User template name'),
'required' => true,
'description' => $this->translate('User for the Icinga host template you are going to create')
));
} else {
$this->addElement('text', 'object_name', array(
'label' => $this->translate('Username'),
'required' => true,
'description' => $this->translate('Username for the Icinga host you are going to create')
));
}
$this->addElement('text', 'email', array(
'label' => $this->translate('Email'),
'description' => $this->translate('The Email address of the user.')
));
$this->addElement('text', 'pager', array(
'label' => $this->translate('Pager'),
'description' => $this->translate('The pager address of the user.')
));
$this->optionalBoolean(
'enable_notifications',
$this->translate('Send notifications'),
$this->translate('Whether to send notifications for this user')
);
$this->addElement('select', 'zone_id', array(
'label' => $this->translate('Cluster Zone'),
'description' => $this->translate('Check this user in this specific Icinga cluster zone')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\QuickTable;
class IcingaUserTable extends QuickTable
{
public function getColumns()
{
return array(
'id' => 'u.id',
'user' => 'u.object_name',
// 'display_name' => 'u.display_name',
'email' => 'u.email',
// 'pager' => 'u.pager',
// 'enable_notifications' => 'u.enable_notifications',
// 'period' => ''
'zone' => 'z.object_name',
);
}
protected function getActionUrl($row)
{
return $this->url('director/object/user', array('id' => $row->id));
}
public function getTitles()
{
$view = $this->view();
return array(
'user' => $view->translate('Username'),
'email' => $view->translate('Email'),
'zone' => $view->translate('Zone'),
);
}
public function fetchData()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('u' => 'icinga_user'),
$this->getColumns()
)->joinLeft(
array('z' => 'icinga_zone'),
'u.zone_id = z.id',
array()
);
return $db->fetchAll($query);
}
}

View File

@ -11,6 +11,8 @@ $section->add($this->translate('Command Arguments'))
->setUrl('director/list/commandarguments'); ->setUrl('director/list/commandarguments');
$section->add($this->translate('Hosts')) $section->add($this->translate('Hosts'))
->setUrl('director/list/hosts'); ->setUrl('director/list/hosts');
$section->add($this->translate('Users'))
->setUrl('director/list/users');
$section->add($this->translate('Activity Log')) $section->add($this->translate('Activity Log'))
->setUrl('director/list/activitylog') ->setUrl('director/list/activitylog')
->setPriority(900); ->setPriority(900);

View File

@ -0,0 +1,20 @@
<?php
namespace Icinga\Module\Director\Objects;
class IcingaUser extends IcingaObject
{
protected $table = 'icinga_user';
protected $defaultProperties = array(
'id' => null,
'object_name' => null,
'display_name' => null,
'email' => null,
'pager' => null,
'enable_notifications' => null,
'period_id' => null,
'zone_id' => null,
'object_type' => null,
);
}