Commit 7985d02e authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Merge branch '6043-add-supannparraindn-attribute-in-the-supann-plugin' into '1.4-dev'

Resolve "add supannParrainDN attribute in the supann plugin"

See merge request fusiondirectory/fd-plugins!703
parents 29f753e8 8127e653
......@@ -48,7 +48,9 @@ class SudoSystemsAttribute extends SystemsAttribute
parent::loadPostValue();
if ($this->isVisible()) {
if (isset($_POST['add'.$this->getHtmlId().'_ALL'])) {
$this->value = ['ALL'];
$this->value = ['ALL'];
$this->displays = ['ALL'];
$this->types = [FALSE];
}
}
}
......@@ -56,8 +58,18 @@ class SudoSystemsAttribute extends SystemsAttribute
function addValue (string $dn, $entry = NULL)
{
if (isset($this->value[0]) && ($this->value[0] === 'ALL')) {
unset($this->value[0]);
$this->removeValue(0);
}
parent::addValue($dn, $entry);
}
protected function fillDisplayValue ($i)
{
if ($this->value[$i] === 'ALL') {
$this->displays[$i] = 'ALL';
$this->types[$i] = FALSE;
} else {
parent::fillDisplayValue($i);
}
}
}
......@@ -20,19 +20,30 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class SudoUsersGroupsAttribute extends DialogAttribute
class SudoUsersGroupsAttribute extends ObjectsAttribute
{
protected $dialogClass = 'UserGroupSelectDialog';
function __construct (string $label, string $description, string $ldapName, bool $required, array $defaultValue = [], string $store_attr = 'uid', string $display_attr = 'nameAttr', array $filterElementDefinitions = NULL, string $acl = '')
{
parent::__construct($label, $description, $ldapName, $required, ['user', 'group', 'ogroup'], $defaultValue, $store_attr, $display_attr, $filterElementDefinitions, $acl);
}
function addValue (string $dn, $entry = NULL)
function addValue (string $dn, $attrs = NULL)
{
if (in_array('posixGroup', $entry['objectClass']) || in_array('groupOfNames', $entry['objectClass'])) {
$name = trim("%".$entry['cn'][0]);
} elseif (isset($entry['uid'][0])) {
$name = trim($entry['uid'][0]);
if (
($this->isTemplate() && ($attrs === NULL)) ||
($this->store_attr == 'dn')
) {
$value = $dn;
} elseif (in_array('posixGroup', $attrs['objectClass']) || in_array('groupOfNames', $attrs['objectClass'])) {
$value = trim('%'.$attrs['cn'][0]);
} elseif (isset($attrs['uid'][0])) {
$value = trim($attrs['uid'][0]);
}
if (!in_array($name, $this->value) && !in_array("!".$name, $this->value)) {
$this->value[] = $name;
if (!in_array($value, $this->value) && !in_array('!'.$value, $this->value)) {
end($this->value);
$new_key = key($this->value) + 1;
$this->value[$new_key] = $value;
$this->fillDisplayValueFrom($new_key, $attrs);
}
}
......@@ -40,13 +51,28 @@ class SudoUsersGroupsAttribute extends DialogAttribute
{
$used = [];
foreach ($this->value as $name) {
$str = preg_replace("/^!/", "", $name);
if (preg_match("/^%/", $str)) {
$used['cn'][] = preg_replace("/^%/", "", $str);
$str = preg_replace('/^!/', '', $name);
if (preg_match('/^%/', $str)) {
$used['cn'][] = preg_replace('/^%/', '', $str);
} else {
$used['uid'][] = $str;
}
}
return $used;
}
protected function fillDisplayValue ($i)
{
$value = $this->value[$i];
if (preg_match('/^%/', $value)) {
$objects = objects::ls(['group','ogroup'], $this->selectManagementParameters[2], NULL, '(cn='.ldap_escape_f(preg_replace('/^%/', '', $value)).')');
} else {
$objects = objects::ls(['user'], $this->selectManagementParameters[2], NULL, '(uid='.ldap_escape_f($value).')');
}
if (empty($objects) && $this->isTemplate()) {
$this->fillDisplayValueFrom($i, NULL);
} else {
$this->fillDisplayValueFrom($i, reset($objects));
}
}
}
......@@ -100,6 +100,7 @@ class sudo extends simplePlugin
new SudoSystemsAttribute(
_('Systems'), _('A host name, IP address or IP network'),
'sudoHost', FALSE,
['terminal', 'workstation', 'server'],
['ALL']
),
new SudoUsersGroupsAttribute(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment