Commit 55e13734 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

🚑 fix(management) Using '*' for all attributes in management

There was too many tricky cases of array or string value, now '*' is
 asked for all attributes so that all values are array.
Also started to migrate MailsAttribute to selectManagement

issue #5965
parent d6e4c9ba
......@@ -171,11 +171,11 @@ class managementFilter
$attrsAsked = $attrs;
if (!empty($infos['mainAttr']) && !isset($attrsAsked[$infos['mainAttr']])) {
/* Ask for mainAttr */
$attrsAsked[$infos['mainAttr']] = '1';
$attrsAsked[$infos['mainAttr']] = '*';
}
if (!empty($infos['nameAttr']) && !isset($attrsAsked[$infos['nameAttr']])) {
/* Ask for nameAttr */
$attrsAsked[$infos['nameAttr']] = '1';
$attrsAsked[$infos['nameAttr']] = '*';
}
foreach ($attrsAsked as $attr => $data) {
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2018-2019 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class mailAddressSelect extends selectManagement
{
/* Default columns */
public static $columns = [
['ObjectTypeColumn', []],
['LinkColumn', ['attributes' => 'mail', 'label' => 'Email']],
['LinkColumn', ['attributes' => 'nameAttr', 'label' => 'Name']],
];
protected function setUpFilter ()
{
parent::setUpFilter();
$this->filter->addElement(new FixedFilterElement($this->filter, '(mail=*)'));
}
}
/*! \brief Mail address selection dialog
*/
class MailSelectDialog extends GenericSelectManagementDialog
{
protected $dialogClass = 'mailAddressSelect';
}
/*! \brief This class allows to handle an attribute for selecting an mail address
*
* It looks like a SetAttribute, but clicking "Add (from list)" will open a dialog that allow to select one or more users.
*
*/
class MailsAttribute extends DialogAttribute
{
protected $dialogClass = 'MailSelectDialog';
/*! \brief The constructor of MailsAttribute
*
* \param string $label The label to show for this attribute
* \param string $description A more detailed description for the attribute
* \param string $ldapName The name of the attribute in the LDAP (If it's not in the ldap, still provide a unique name)
* \param boolean $required Is this attribute mandatory or not
* \param array $defaultValue The default value for this attribute
* \param string $acl The name of the acl for this attribute if he does not use its own. (Leave empty if he should use its own like most attributes do)
  • Remove this commented out code. 📘

Please register or sign in to reply
*/
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $acl = '')
{
SetAttribute::__construct(new MailAttribute($label, $description, $ldapName, $required, '', $acl), $defaultValue);
$this->selectManagementParameters = [
['user','group'],
TRUE,
[
'objectClass' => '*',
'dn' => 'raw',
'cn' => '*',
'mail' => '*',
]
];
}
function getFilterBlackList ()
{
return ['mail' => $this->getValue()];
}
function addValue ($dn, $attrs)
{
$value = (($attrs != NULL) ? $attrs['mail'][0] : $dn);
if (!in_array($value, $this->value)) {
$this->value[] = $value;
}
}
function renderButtons ()
{
$id = $this->getHtmlId();
$buttons = $this->renderInputField(
'submit', 'add'.$id,
['value' => '{msgPool type=addButton}']
);
$buttons .= $this->renderInputField(
'submit', 'add'.$id.'_dialog',
[
'class' => 'dialog',
'value' => '{msgPool type=addButton} (from list)'
]
);
$buttons .= $this->renderInputField(
'submit', 'del'.$id,
['value' => '{msgPool type=delButton}']
);
return $buttons;
}
public function htmlIds (): array
{
$id = $this->getHtmlId();
return ['add'.$id,'add'.$id.'_dialog','del'.$id,'row'.$id];
}
}
......@@ -115,13 +115,6 @@ class SystemSelectDialog extends GenericSelectManagementDialog
protected $dialogClass = 'systemSelect';
}
/*! \brief Mail address selection dialog
*/
class MailSelectDialog extends GenericSelectDialog
{
protected $dialogClass = 'mailAddressSelect';
}
/*! \brief This class allows to handle an attribute with a popup for selection
*
* It looks like a SetAttribute, but clicking "Add" will open a dialog that allow to select one or more items.
......@@ -359,13 +352,7 @@ class GenericDialogAttribute extends DialogAttribute
) {
$value = $dn;
} else {
if (is_array($attrs)) {
// simpleSelectManagement
$value = $attrs[$this->store_attr][0];
} else {
// selectManagement
$value = $attrs[$this->store_attr];
}
$value = $attrs[$this->store_attr][0];
}
if (!in_array($value, $this->value)) {
end($this->value);
......@@ -431,13 +418,7 @@ class GenericDialogAttribute extends DialogAttribute
if ($this->display_attr == 'dn') {
$this->displays[$i] = $attrs['dn'];
} else {
if (is_array($attrs[$this->display_attr])) {
// simpleSelectManagement or LDAP data
$this->displays[$i] = $attrs[$this->display_attr][0];
} else {
// selectManagement
$this->displays[$i] = $attrs[$this->display_attr];
}
$this->displays[$i] = $attrs[$this->display_attr][0];
}
}
}
......@@ -522,8 +503,8 @@ class ObjectsAttribute extends GenericDialogAttribute
TRUE,
[
'objectClass' => '*',
$store_attr => (($store_attr == 'dn') ? 'raw' : 1),
$display_attr => (($display_attr == 'dn') ? 'raw' : 1),
$store_attr => (($store_attr == 'dn') ? 'raw' : '*'),
$display_attr => (($display_attr == 'dn') ? 'raw' : '*'),
]
];
}
......@@ -553,8 +534,8 @@ class UsersGroupsRolesAttribute extends ObjectsAttribute
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $store_attr = 'dn', $display_attr = 'cn', $acl = '')
{
parent::__construct($label, $description, $ldapName, $required, ['user', 'group', 'role', 'ogroup'], $defaultValue, $store_attr, $display_attr, $acl);
$this->selectManagementParameters[2]['cn'] = 1;
$this->selectManagementParameters[2]['uid'] = 1;
$this->selectManagementParameters[2]['cn'] = '*';
$this->selectManagementParameters[2]['uid'] = '*';
$this->selectManagementParameters[2]['objectClass'] = '*';
}
......@@ -568,11 +549,7 @@ class UsersGroupsRolesAttribute extends ObjectsAttribute
if (!isset($attrs[$this->display_attr])) {
unset($this->value[$i]);
} else {
if (is_array($attrs['cn'])) {
$cn = $attrs['cn'][0];
} else {
$cn = $attrs['cn'];
}
$cn = $attrs['cn'][0];
if ($this->display_attr == 'dn') {
$this->displays[$i] = $attrs['dn'];
} elseif (in_array('posixGroup', $attrs['objectClass'])) {
......@@ -582,88 +559,14 @@ class UsersGroupsRolesAttribute extends ObjectsAttribute
} elseif (in_array('groupOfNames', $attrs['objectClass'])) {
$this->displays[$i] = sprintf(_('Group %s'), trim($cn));
} elseif (isset($attrs['uid'])) {
if (is_array($attrs['uid'])) {
$uid = $attrs['uid'][0];
} else {
$uid = $attrs['uid'];
}
$this->displays[$i] = trim($uid);
$this->displays[$i] = trim($attrs['uid'][0]);
} else {
if (is_array($attrs[$this->display_attr])) {
$display = $attrs[$this->display_attr][0];
} else {
$display = $attrs[$this->display_attr];
}
$this->displays[$i] = $display;
$this->displays[$i] = $attrs[$this->display_attr][0];
}
}
}
}
/*! \brief This class allows to handle an attribute for selecting an mail address
*
* It looks like a SetAttribute, but clicking "Add" will open a dialog that allow to select one or more users.
*
*/
class MailsAttribute extends DialogAttribute
{
protected $dialogClass = 'MailSelectDialog';
/*! \brief The constructor of MailsAttribute
*
* \param string $label The label to show for this attribute
* \param string $description A more detailed description for the attribute
* \param string $ldapName The name of the attribute in the LDAP (If it's not in the ldap, still provide a unique name)
* \param boolean $required Is this attribute mandatory or not
* \param array $defaultValue The default value for this attribute
* \param string $acl The name of the acl for this attribute if he does not use its own. (Leave empty if he should use its own like most attributes do)
*/
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $acl = "")
{
SetAttribute::__construct(new MailAttribute($label, $description, $ldapName, $required, "", $acl), $defaultValue);
}
function getFilterBlackList ()
{
return ['mail' => $this->getValue()];
}
function addValue ($dn, $attrs)
{
$value = (($attrs != NULL) ? $attrs['mail'][0] : $dn);
if (!in_array($value, $this->value)) {
$this->value[] = $value;
}
}
function renderButtons ()
{
$id = $this->getHtmlId();
$buttons = $this->renderInputField(
'submit', 'add'.$id,
['value' => '{msgPool type=addButton}']
);
$buttons .= $this->renderInputField(
'submit', 'add'.$id.'_dialog',
[
'class' => 'dialog',
'value' => '{msgPool type=addButton} (from list)'
]
);
$buttons .= $this->renderInputField(
'submit', 'del'.$id,
['value' => '{msgPool type=delButton}']
);
return $buttons;
}
public function htmlIds (): array
{
$id = $this->getHtmlId();
return ['add'.$id,'add'.$id.'_dialog','del'.$id,'row'.$id];
}
}
/*!
* \brief Attribute storing a system list
*/
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003 Cajus Pollmeier
Copyright (C) 2011-2016 FusionDirectory
Copyright (C) 2011-2019 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -21,7 +22,7 @@
class GroupMembersAttribute extends ObjectsAttribute
{
protected $types = [];
protected $types = [];
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $store_attr = 'dn', $display_attr = 'cn', $acl = '')
{
......@@ -66,15 +67,15 @@ class GroupMembersAttribute extends ObjectsAttribute
if ($code !== FALSE) {
$infos = objects::infos($objectType);
$this->types[$i] = $code;
$this->displays[$i] = $attrs[$infos['nameAttr']];
$this->displays[$i] = $attrs[$infos['nameAttr']][0];
if (strtolower($objectType) == 'user') {
if (isset($attrs['description'])) {
$this->displays[$i] .= ' ['.$attrs['uid'].' - '.$attrs['description'].']';
if (isset($attrs['description'][0])) {
$this->displays[$i] .= ' ['.$attrs['uid'][0].' - '.$attrs['description'][0].']';
} else {
$this->displays[$i] .= ' ['.$attrs['uid'].']';
$this->displays[$i] .= ' ['.$attrs['uid'][0].']';
}
} elseif (isset($attrs['description'][0])) {
$this->displays[$i] .= ' ['.$attrs['description'].']';
$this->displays[$i] .= ' ['.$attrs['description'][0].']';
}
}
}
......
  • SonarQube analysis reported 3 issues

    • 2 major
    • 🔽 1 minor

    Watch the comments in this conversation to review them.

    2 extra issues

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. Update this method so that its implementation is not identical to "getFilterBlackList" on line 161. 📘
    2. 🔽 Remove this method "__construct" to simply inherit it. 📘
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