Commit 1ef55d6a authored by Côme Chilliet's avatar Côme Chilliet

Merge branch '5965-use-only-selectmanagement-for-selection-dialogs' into '1.4-dev'

Resolve "Use only selectManagement for selection dialogs"

See merge request fusiondirectory/fd!574
parents c11e8939 36a45fc5
......@@ -234,6 +234,8 @@ class managementFilter
$ldapEntries = objects::ls($type, $attrsAsked, $searchBase, $filter, TRUE, $this->scope, FALSE, TRUE);
$ldapEntries = $this->filterEntries($ldapEntries);
$objectTypeCount[$type] = count($ldapEntries);
foreach ($ldapEntries as $dn => $entry) {
// TODO: check collisions?
......@@ -243,4 +245,40 @@ class managementFilter
return [$entries, $objectTypeCount];
}
protected function filterEntries (array $ldapEntries): array
{
if (!empty($this->parent->whiteList)) {
foreach ($ldapEntries as $dn => $entry) {
if (in_array($dn, $this->parent->whiteList['dn'])) {
continue;
}
foreach ($this->parent->whiteList['branches'] as $branch) {
if (preg_match('/'.preg_quote($branch, '/').'$/', $dn)) {
continue 2;
}
}
unset($ldapEntries[$dn]);
}
}
if (isset($this->parent->blackList)) {
foreach ($this->parent->blackList as $attr_name => $attr_values) {
foreach ($attr_values as $match) {
foreach ($ldapEntries as $dn => $entry) {
if (isset($entry[$attr_name])) {
$test = $entry[$attr_name];
if (!is_array($test)) {
$test = [$test];
}
if (in_array($match, $test)) {
unset($ldapEntries[$dn]);
}
}
}
}
}
}
return $ldapEntries;
}
}
......@@ -29,6 +29,8 @@ class selectManagement extends management
public static $skipSnapshots = TRUE;
protected $multiSelect = TRUE;
public $blackList;
public $whiteList;
/* Default columns */
public static $columns = [
......@@ -37,10 +39,12 @@ class selectManagement extends management
['LinkColumn', ['attributes' => 'description', 'label' => 'Description']],
];
function __construct ($objectTypes = FALSE, bool $multiSelect = TRUE, array $neededAttrs = [])
function __construct ($objectTypes = FALSE, bool $multiSelect = TRUE, array $neededAttrs = [], array $blackList = [], array $whiteList = [])
{
$this->neededAttrs = $neededAttrs;
$this->multiSelect = $multiSelect;
$this->blackList = $blackList;
$this->whiteList = $whiteList;
parent::__construct($objectTypes);
}
......
......@@ -63,8 +63,11 @@ class MailsAttribute extends DialogAttribute
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $acl = '')
{
SetAttribute::__construct(new MailAttribute($label, $description, $ldapName, $required, '', $acl), $defaultValue);
}
$this->selectManagementParameters = [
public function getSelectManagementParameters (): array
{
return [
['user','group'],
TRUE,
[
......@@ -72,7 +75,8 @@ class MailsAttribute extends DialogAttribute
'dn' => 'raw',
'cn' => '*',
'mail' => '*',
]
],
$this->getFilterBlackList(),
];
}
......
......@@ -70,7 +70,16 @@ class PhoneNumberButtonAttribute extends PhoneNumberAttribute
{
parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
switch ($type) {
if (class_available('phoneGeneric')) {
$this->type = $type;
} else {
$this->type = FALSE;
}
}
public function getSelectManagementParameters (): array
{
switch ($this->type) {
case 'phone':
$objectTypes = ['phone'];
break;
......@@ -81,10 +90,10 @@ class PhoneNumberButtonAttribute extends PhoneNumberAttribute
$objectTypes = ['phone','mobilePhone'];
break;
default:
throw new FusionDirectoryException('Invalid type "'.$type.'" for PhoneNumberButtonAttribute');
throw new FusionDirectoryException('Invalid type "'.$this->type.'" for PhoneNumberButtonAttribute');
}
$this->selectManagementParameters = [
return [
$objectTypes,
FALSE,
[
......@@ -94,14 +103,8 @@ class PhoneNumberButtonAttribute extends PhoneNumberAttribute
'ipHostNumber' => '*',
'macAddress' => '*',
'telephoneNumber' => '*',
]
],
];
if (class_available('phoneGeneric')) {
$this->type = $type;
} else {
$this->type = FALSE;
}
}
function renderFormInput (): string
......@@ -157,14 +160,4 @@ class PhoneNumberButtonAttribute extends PhoneNumberAttribute
$this->setValue('');
}
}
function getFilterBlackList ()
{
return [];
}
function getFilterWhiteList ()
{
return [];
}
}
......@@ -121,7 +121,7 @@ class SystemSelectDialog extends GenericSelectManagementDialog
* It stores their dn as values, but displays the cn.
*
*/
class DialogAttribute extends SetAttribute
abstract class DialogAttribute extends SetAttribute
{
protected $dialogClass = NULL;
......@@ -168,10 +168,7 @@ class DialogAttribute extends SetAttribute
unset($this->value[$row]);
}
function getFilterBlackList ()
{
trigger_error("abstract method");
}
abstract function getFilterBlackList ();
function getFilterWhiteList ()
{
......@@ -247,7 +244,7 @@ class DialogAttribute extends SetAttribute
/*!
* \brief An OrderedArrayAttribute which uses a dialog to create/edit values
*/
class DialogOrderedArrayAttribute extends OrderedArrayAttribute
abstract class DialogOrderedArrayAttribute extends OrderedArrayAttribute
{
protected $dialogClass;
......@@ -258,10 +255,7 @@ class DialogOrderedArrayAttribute extends OrderedArrayAttribute
$this->attribute = FALSE;
}
function getFilterBlackList ()
{
trigger_error("abstract method");
}
abstract function getFilterBlackList ();
function getFilterWhiteList ()
{
......@@ -463,7 +457,7 @@ class GenericSelectManagementDialog extends GenericSelectDialog
function __construct ($simplePlugin, $attribute)
{
$this->attribute = $attribute;
$this->dialog = new $this->dialogClass(...$this->attribute->selectManagementParameters);
$this->dialog = new $this->dialogClass(...$this->attribute->getSelectManagementParameters());
}
}
......@@ -493,7 +487,7 @@ class ObjectsAttribute extends GenericDialogAttribute
{
protected $dialogClass = 'GenericSelectManagementDialog';
public $selectManagementParameters;
protected $selectManagementParameters;
function __construct (string $label, string $description, string $ldapName, bool $required, array $objectTypes, array $defaultValue = [], string $store_attr = 'dn', string $display_attr = 'cn', string $acl = '')
{
......@@ -508,6 +502,17 @@ class ObjectsAttribute extends GenericDialogAttribute
]
];
}
public function getSelectManagementParameters (): array
{
return array_merge(
$this->selectManagementParameters,
[
$this->getFilterBlackList(),
$this->getFilterWhiteList(),
]
);
}
}
/*! \brief This class allows to handle an attribute for selecting users
......@@ -661,8 +666,6 @@ class DialogButtonAttribute extends ButtonAttribute
*/
class ObjectAttribute extends DialogButtonAttribute
{
public $selectManagementParameters;
protected $objectType;
protected $displayAttr;
......@@ -670,10 +673,14 @@ class ObjectAttribute extends DialogButtonAttribute
{
parent::__construct($label, $description, $ldapName, '', 'GenericSingleSelectManagementDialog', $defaultValue, $acl);
$this->setRequired($required);
$this->selectManagementParameters = [[$objectType], FALSE];
$this->objectType = $objectType;
}
public function getSelectManagementParameters (): array
{
return [[$this->objectType], FALSE];
}
function setParent (simplePlugin &$plugin)
{
parent::setParent($plugin);
......
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