Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion application/controllers/SuggestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Icinga\Module\Director\Controllers;

use Icinga\Module\Director\Objects\IcingaUser;
use Icinga\Module\Director\Restriction\HostgroupRestriction;
use ipl\Html\Html;
use Icinga\Exception\NotFoundError;
Expand All @@ -26,7 +27,7 @@ public function indexAction()
$key = null;

if (strpos($context, '!') !== false) {
list($context, $key) = preg_split('~!~', $context, 2);
[$context, $key] = preg_split('~!~', $context, 2);
}

$func = 'suggest' . ucfirst($context);
Expand Down Expand Up @@ -264,6 +265,14 @@ protected function suggestServiceFilterColumns()
]);
}

protected function suggestUserFilterColumns()
{
return $this->getFilterColumns('user.', [
$this->translate('User properties'),
$this->translate('Custom variables')
]);
}

protected function suggestDataListValuesForListId($id)
{
$db = $this->db()->getDbAdapter();
Expand Down Expand Up @@ -336,6 +345,8 @@ protected function getFilterColumns($prefix, $keys)
{
if ($prefix === 'host.') {
$all = IcingaHost::enumProperties($this->db(), $prefix);
} elseif ($prefix === 'user.') {
$all = IcingaUser::enumProperties($this->db(), $prefix);
} else {
$all = IcingaService::enumProperties($this->db(), $prefix);
}
Expand Down
47 changes: 47 additions & 0 deletions application/controllers/UsergroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,55 @@

namespace Icinga\Module\Director\Controllers;

use gipfl\Web\Widget\Hint;
use Icinga\Module\Director\Forms\IcingaDeleteUsergroupForm;
use Icinga\Module\Director\Web\Controller\ObjectController;
use Icinga\Web\Notification;
use ipl\Web\Url;

class UsergroupController extends ObjectController
{
public function deleteAction()
{
$this->addTitle($this->translate('Delete Usergroup'));

$directMemberQuery = $this->db()
->select()
->from('icinga_usergroup_user')
->where('usergroup_id', $this->object->get('id'));

$appliedMemberQuery = $this->db()
->select()
->from('icinga_usergroup_user_resolved')
->where('usergroup_id', $this->object->get('id'));

if ($this->db()->count($directMemberQuery) > 0 || $this->db()->count($appliedMemberQuery) > 0) {
$this->content()->add(
Hint::info(sprintf(
$this->translate('The usergroup "%s" has members. Do you still want to delete it?'),
$this->object->getObjectName()
))
);
} else {
$this->content()->add(
Hint::info(sprintf(
$this->translate('The usergroup "%s" does not have any members. You can go ahead and delete it.'),
$this->object->getObjectName()
))
);
}

$this->content()->add(
(new IcingaDeleteUsergroupForm($this->object, $this->db(), $this->branch))
->on(IcingaDeleteUsergroupForm::ON_SUCCESS, function () {
Notification::success(sprintf(
$this->translate('User group %s has been deleted.'),
$this->object->getObjectName()
));

$this->redirectNow(Url::fromPath('director/usergroups'));
})
->handleRequest($this->getServerRequest())
);
}
}
37 changes: 37 additions & 0 deletions application/forms/IcingaDeleteUsergroupForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Icinga\Module\Director\Forms;

use Icinga\Module\Director\Data\Db\DbObjectStore;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Db\Branch\Branch;
use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Web\Session;
use ipl\Web\Common\CsrfCounterMeasure;
use ipl\Web\Compat\CompatForm;

class IcingaDeleteUsergroupForm extends CompatForm
{
use CsrfCounterMeasure;

public function __construct(
protected IcingaObject $object,
protected Db $db,
protected ?Branch $branch = null
) {
}

protected function assemble(): void
{
$this->addElement($this->createCsrfCounterMeasure(Session::getSession()->getId()));

$this->addElement('submit', 'submit', [
'label' => $this->translate('Delete')
]);
}

protected function onSuccess(): void
{
(new DbObjectStore($this->db, $this->branch))->delete($this->object);
}
}
49 changes: 49 additions & 0 deletions application/forms/IcingaServiceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Icinga\Module\Director\Web\Table\ObjectsTableHost;
use ipl\Html\Html;
use gipfl\IcingaWeb2\Link;
use ipl\Html\HtmlElement;
use RuntimeException;

class IcingaServiceForm extends DirectorObjectForm
Expand Down Expand Up @@ -666,6 +667,15 @@
));
}

$applied = $this->getAppliedGroups();
if (! empty($applied)) {
$this->addElement('simpleNote', 'applied_groups', [
'label' => $this->translate('Applied groups'),
'value' => $this->createServicegroupLinks($applied),
'ignore' => true,
]);
}

return $this;
}

Expand Down Expand Up @@ -808,4 +818,43 @@
}
}
}

/**
* Create links to applied servicegroups.
*
* @param $groups
*
* @return HtmlElement
*/
protected function createServicegroupLinks($groups): HtmlElement
{
$links = [];
foreach ($groups as $name) {
if (! empty($links)) {
$links[] = ', ';
}
$links[] = Link::create(
$name,
'director/servicegroup',
['name' => $name],
['data-base-target' => '_next']
);
}

return Html::tag('span', ['class' => 'host-group-links'], $links);
}

/**
* Get applied servicegroups.
*
* @return array
*/
protected function getAppliedGroups(): array
{
if ($this->isNew()) {
return [];
}

return $this->object()->getAppliedGroups();

Check failure on line 858 in application/forms/IcingaServiceForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.3 on ubuntu-latest

Call to an undefined method Icinga\Module\Director\Data\Db\DbObject::getAppliedGroups().

Check failure on line 858 in application/forms/IcingaServiceForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.2 on ubuntu-latest

Call to an undefined method Icinga\Module\Director\Data\Db\DbObject::getAppliedGroups().
}
}
51 changes: 51 additions & 0 deletions application/forms/IcingaUserForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Icinga\Module\Director\Forms;

use gipfl\IcingaWeb2\Link;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
use ipl\Html\Html;
use ipl\Html\HtmlElement;

class IcingaUserForm extends DirectorObjectForm
{
Expand Down Expand Up @@ -116,6 +119,15 @@
)
));

$applied = $this->getAppliedGroups();
if (! empty($applied)) {
$this->addElement('simpleNote', 'applied_groups', [
'label' => $this->translate('Applied groups'),
'value' => $this->createUsergroupLinks($applied),
'ignore' => true,
]);
}

return $this;
}

Expand Down Expand Up @@ -211,4 +223,43 @@

return $db->fetchPairs($select);
}

/**
* Get applied user groups
*
* @return array
*/
protected function getAppliedGroups(): array
{
if ($this->isNew()) {
return [];
}

return $this->object()->getAppliedGroups();

Check failure on line 238 in application/forms/IcingaUserForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.3 on ubuntu-latest

Call to an undefined method Icinga\Module\Director\Data\Db\DbObject::getAppliedGroups().

Check failure on line 238 in application/forms/IcingaUserForm.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.2 on ubuntu-latest

Call to an undefined method Icinga\Module\Director\Data\Db\DbObject::getAppliedGroups().
}

/**
* Create links for applied user groups
*
* @param $groups
*
* @return HtmlElement
*/
protected function createUsergroupLinks($groups): HtmlElement
{
$links = [];
foreach ($groups as $name) {
if (! empty($links)) {
$links[] = ', ';
}
$links[] = Link::create(
$name,
'director/usergroup',
['name' => $name],
['data-base-target' => '_next']
);
}

return Html::tag('span', ['class' => 'user-group-links'], $links);
}
}
26 changes: 26 additions & 0 deletions application/forms/IcingaUserGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Forms;

use Icinga\Module\Director\Web\Form\DirectorObjectForm;
use ipl\Web\Url;

class IcingaUserGroupForm extends DirectorObjectForm
{
Expand All @@ -20,6 +21,7 @@ public function setup()
));

$this->addGroupDisplayNameElement()
->addAssignmentElements()
->addZoneElements()
->groupMainProperties()
->setButtons();
Expand All @@ -44,4 +46,28 @@ protected function addZoneElements()

return $this;
}

protected function addAssignmentElements()
{
$this->addAssignFilter([
'suggestionContext' => 'UserFilterColumns',
'required' => false,
'description' => $this->translate(
'This allows you to configure an assignment filter. Please feel'
. ' free to combine as many nested operators as you want. The'
. ' "contains" operator is valid for arrays only. Please use'
. ' wildcards and the = (equals) operator when searching for'
. ' partial string matches, like in *.example.com'
)
]);

return $this;
}

protected function deleteObject($object)
{
$this->redirectAndExit(
Url::fromPath('director/usergroup/delete', ['uuid' => $object->getUniqueId()->toString()])
);
}
}
2 changes: 2 additions & 0 deletions library/Director/Data/PropertiesFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class PropertiesFilter
public static $HOST_PROPERTY = 'HOST_PROPERTY';
public static $SERVICE_PROPERTY = 'SERVICE_PROPERTY';

public static $USER_PROPERTY = 'USER_PROPERTY';

protected $blacklist = array(
'id',
'object_name',
Expand Down
25 changes: 25 additions & 0 deletions library/Director/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,31 @@ public function fetchDistinctServiceVars()
return $this->db()->fetchAll($select);
}

/**
* Fetch all distinct user vars.
*
* @return ?array
*/
public function fetchDistinctUserVars()
{
$select = $this->db()->select()->distinct()->from(
array('u' => 'icinga_user_var'),
array(
'varname' => 'u.varname',
'format' => 'u.format',
'caption' => 'df.caption',
'datatype' => 'df.datatype'
)
)->joinLeft(
array('df' => 'director_datafield'),
'df.varname = u.varname',
array()
)->order('varname');

return $this->db()->fetchAll($select);
}


public function dbHexFunc($column)
{
if ($this->isPgsql()) {
Expand Down
3 changes: 0 additions & 3 deletions library/Director/Objects/IcingaObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,6 @@ public function hasModifiedGroups()
public function getAppliedGroups()
{
$this->assertGroupsSupport();
if (! $this instanceof IcingaHost) {
throw new RuntimeException('getAppliedGroups is only available for hosts currently!');
}
if (! $this->hasBeenLoadedFromDb()) {
// There are no stored related/resolved groups. We'll also not resolve
// them here on demand.
Expand Down
Loading
Loading