Commit 3a241bec authored by Côme Chilliet's avatar Côme Chilliet
Browse files

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

Resolve "Use only selectManagement for selection dialogs"

See merge request fusiondirectory/fd!564
parents 23b3c367 4f6175ca
<fieldset><legend>{$NAME}</legend>
{foreach from=$INPUTS key="key" item="input"}
<label title="{$input.desc|escape}">
{if isset($input.icon)}
<img src="{$input.icon|escape}" alt=""/>
{/if}
{$input.name|escape}
</label>
{/foreach}
</fieldset>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2013-2016 FusionDirectory
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
......@@ -18,18 +19,34 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*!
* \brief POSIX group selection
*/
class groupSelect extends simpleSelectManagement
class FixedFilterElement extends FilterElement
{
protected $objectTypes = ['group'];
protected $autoFilter = FALSE;
protected $filter;
function __construct ()
public function __construct (managementFilter $parent, string $filter)
{
$this->filterXMLPath = get_template_path('group-filter.xml', TRUE, dirname(__FILE__));
parent::__construct($parent);
$this->filter = $filter;
}
parent::__construct();
public function render (): string
{
$inputs = [
[
'name' => $this->filter,
'desc' => $this->filter,
]
];
$smarty = get_smarty();
$smarty->assign('NAME', _('Fixed'));
$smarty->assign('INPUTS', $inputs);
return $smarty->fetch(get_template_path('management/filter-element-fixed.tpl'));
}
public function getFilters (string $type, array &$filters): bool
{
$filters[] = $this->filter;
return FALSE;
}
}
......@@ -133,6 +133,40 @@ class ManagementConfigurationDialog extends simplePlugin
}
}
function save_object ()
{
parent::save_object();
if (isset($_POST['edit_cancel'])) {
$this->handle_cancel();
} elseif (isset($_POST['edit_finish'])) {
$this->handle_finish();
}
}
protected function handle_finish ()
{
$msgs = $this->check();
if (count($msgs)) {
msg_dialog::displayChecks($msgs);
return;
} else {
$errors = $this->save();
if (count($errors)) {
msg_dialog::displayChecks($errors);
return;
} else {
$this->parent->remove_lock();
$this->parent->closeDialogs();
}
}
}
protected function handle_cancel ()
{
$this->parent->remove_lock();
$this->parent->closeDialogs();
}
function execute (): string
{
global $config, $ui;
......@@ -173,8 +207,9 @@ class ManagementConfigurationDialog extends simplePlugin
$this->parent->setColumnConfiguration($columnInfos);
if ($this->saveInLdap) {
$errors = $config->updateManagementConfig(get_class($this->parent), $columnInfos);
msg_dialog::displayChecks($errors);
return $config->updateManagementConfig(get_class($this->parent), $columnInfos);
}
return [];
}
}
......@@ -366,7 +366,7 @@ class management
throw new FusionDirectoryException('No valid listing object');
}
$action = ['targets' => [], 'action' => '', 'subaction' => NULL];
if ($this->is_modal_dialog()) {
if ($this->showTabFooter()) {
if (isset($_POST['edit_cancel'])) {
$action['action'] = 'cancel';
} elseif (isset($_POST['edit_finish'])) {
......@@ -374,7 +374,7 @@ class management
} elseif (isset($_POST['edit_apply'])) {
$action['action'] = 'apply';
}
} else {
} elseif (!$this->dialogOpened()) {
if (isset($_POST['delete_confirmed'])) {
$action['action'] = 'removeConfirmed';
} elseif (isset($_POST['delete_cancel'])) {
......@@ -451,7 +451,7 @@ class management
}
if (method_exists($this->dialogObject, 'execute')) {
$display = $this->dialogObject->execute();
$display .= $this->_getTabFooter();
$display .= $this->getTabFooter();
return $this->getHeader().$display;
}
}
......@@ -460,7 +460,7 @@ class management
if ($this->tabObject instanceOf simpleTabs) {
$this->tabObject->save_object();
$display = $this->tabObject->execute();
$display .= $this->_getTabFooter();
$display .= $this->getTabFooter();
return $this->getHeader().$display;
}
......@@ -554,7 +554,7 @@ class management
}
}
function is_modal_dialog (): bool
function dialogOpened (): bool
{
return (is_object($this->tabObject) || is_object($this->dialogObject));
}
......@@ -608,17 +608,30 @@ class management
}
/*!
* \brief Generates the footer which is used whenever a tab object is displayed.
* \brief Whether footer buttons should appear
*/
protected function _getTabFooter (): string
protected function showTabFooter (): bool
{
// Do not display tab footer for non tab objects
if (!($this->tabObject instanceOf simpleTabs)) {
return '';
return FALSE;
}
// Check if there is a dialog opened - We don't need any buttons in this case.
if ($this->tabObject->dialogOpened()) {
return FALSE;
}
return TRUE;
}
/*!
* \brief Generates the footer which is used whenever a tab object is displayed.
*/
protected function getTabFooter (): string
{
// Do not display tab footer for non tab objects
if (!$this->showTabFooter()) {
return '';
}
......@@ -814,7 +827,7 @@ class management
}
/*!
* \brief Editing an object was caneled.
* \brief Editing an object was canceled.
* Close dialogs/tabs and remove locks.
*/
function cancelEdit ()
......@@ -850,18 +863,6 @@ class management
$this->remove_lock();
$this->closeDialogs();
}
} elseif ($this->dialogObject instanceOf simplePlugin) {
$this->dialogObject->save_object();
$msgs = $this->dialogObject->check();
if (count($msgs)) {
msg_dialog::displayChecks($msgs);
return;
} else {
$this->dialogObject->save();
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Dialog saved');
$this->remove_lock();
$this->closeDialogs();
}
}
}
......
......@@ -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) 2003 Cajus Pollmeier
Copyright (C) 2011-2016 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.
*/
/*!
* \brief filterLDAP backend with blacklist/whitelist handling
*/
class filterLDAPBlacklist
{
static function query ($parent, $base, $scope, $filter, $attributes, $category, $objectStorage = "")
{
$result = filterLDAP::query($parent, $base, $scope, $filter, $attributes, $category, $objectStorage);
return filterLDAPBlacklist::filterByBlacklist($result);
}
static function filterByBlacklist ($entries)
{
if (session::is_set('filterWhitelist')) {
$wlist = session::get('filterWhitelist');
if (!empty($wlist)) {
foreach ($entries as $id => $entry) {
if (in_array($entry['dn'], $wlist['dn'])) {
continue;
}
foreach ($wlist['branches'] as $branch) {
if (preg_match('/'.preg_quote($branch, '/').'$/', $entry['dn'])) {
continue 2;
}
}
unset($entries[$id]);
}
}
}
if (session::is_set('filterBlacklist')) {
$blist = session::get('filterBlacklist');
foreach ($blist as $attr_name => $attr_values) {
foreach ($attr_values as $match) {
foreach ($entries as $id => $entry) {
if (isset($entry[$attr_name])) {
$test = $entry[$attr_name];
if (!is_array($test)) {
$test = [$test];
}
if (in_array($match, $test)) {
unset($entries[$id]);
}
}
}
}
}
}
return array_values($entries);
}
}
<div class="contentboxh">
<p>{t}Filter{/t}</p>
</div>
<div class="contentboxb">
<label for="PRIMARY">{$PRIMARY}&nbsp;{t}Show primary groups{/t}</label><br/>
<label for="SAMBA">{$SAMBA}&nbsp;{t}Show samba groups{/t}</label><br/>
<label for="MAIL">{$MAIL}&nbsp;{t}Show mail groups{/t}</label><br/>
<hr/>
{$SCOPE}
<hr/>
<label for="NAME"><img src="geticon.php?context=actions&amp;icon=system-search&amp;size=16"/>{$NAME}</label>
<div>
{$APPLY}
</div>
</div>
<?xml version="1.0" encoding="UTF-8"?>
<filterdef>
<definition>
<category>group</category>
<template>../include/select/groupSelect/group-filter.tpl</template>
<initial>true</initial>
</definition>
<search>
<query>
<backend>LDAPBlacklist</backend>
<filter>(&amp;(objectClass=posixGroup)$NAME(|$PRIMARY$MAIL$SAMBA))</filter>
<attribute>dn</attribute>
<attribute>objectClass</attribute>
<attribute>cn</attribute>
<attribute>description</attribute>
</query>
<scope>auto</scope>
</search>
<element>
<type>checkbox</type>
<tag>PRIMARY</tag>
<default>true</default>
<unset></unset>
<set>(objectClass=posixGroup)</set>
</element>
<element>
<type>checkbox</type>
<tag>MAIL</tag>
<default>true</default>
<unset></unset>
<set>(objectClass=gosaMailAccount)</set>
</element>
<element>
<type>checkbox</type>
<tag>SAMBA</tag>
<default>true</default>
<unset></unset>
<set>(objectClass=sambaGroupMapping)</set>
</element>
<element>
<type>textfield</type>
<tag>NAME</tag>
<size>20</size>
<maxlength>60</maxlength>
<default></default>
<unset></unset>
<set>(|(cn=*$*)(description=*$*))</set>
<autocomplete>
<backend>LDAPBlacklist</backend>
<filter>(&amp;(objectClass=posixGroup)(|(cn=*$NAME*)(description=*$NAME*)))</filter>
<attribute>cn</attribute>
<attribute>description</attribute>
<frequency>0.5</frequency>
<characters>3</characters>
</autocomplete>
</element>
</filterdef>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2013-2016 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.
*/
/*!
* \brief System selection
*/
class systemSelect extends simpleSelectManagement
{
protected $autoFilterAttributes = ['dn', 'cn', 'ipHostNumber', 'macAddress'];
protected $objectTypes = [
'terminal', 'workstation', 'server'
];
}
<?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)
*/
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];
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2016-2017 FusionDirectory
Copyright (C) 2016-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,89 +22,28 @@
/*!
* \brief Phone number selection
*/
class phoneSelect extends simpleSelectManagement
class phoneSelect extends selectManagement
{
protected $multiSelect = FALSE;
protected $autoFilterAttributes = ['dn','cn','ipHostNumber','macAddress','telephoneNumber'];
protected $objectTypes = ['phone'];
function parseXML ($file)
{
$data = parent::parseXML($file);
/* Add column for phone number */
$data['list']['table']['layout'] .= '|';
$columns = [
[
'label' => _('Number'),
'sortAttribute' => 'telephoneNumber',
'sortType' => 'string',
'value' => '%{filter:selectLink(pid,row,dn,telephoneNumber)}',
'export' => 'true',
],
];
array_splice($data['list']['table']['column'], 2, 0, $columns);
return $data;
}
function configureFilter ()
/* Default columns */
public static $columns = [
['ObjectTypeColumn', []],
['LinkColumn', ['attributes' => 'nameAttr', 'label' => 'Name']],
['LinkColumn', ['attributes' => 'telephoneNumber', 'label' => 'Number']],
];
protected function setUpFilter ()
{
parent::configureFilter();
/* Only display entries with a phone number */
$this->filter->query[0]['filter'] = '(&(telephoneNumber=*)'.$this->filter->query[0]['filter'].')';
parent::setUpFilter();
$this->filter->addElement(new FixedFilterElement($this->filter, '(telephoneNumber=*)'));
}
}
/*!
* \brief Mobile phone number selection
*/
class mobilePhoneSelect extends phoneSelect
{
protected $objectTypes = ['mobilePhone'];