Commit 13653866 authored by Côme Chilliet's avatar Côme Chilliet

Merge branch '5999-allow-objecsattribute-instances-to-specify-filter-elements' into '1.4-dev'

Resolve "Allow ObjecsAttribute instances to specify filter elements"

See merge request fusiondirectory/fd!607
parents 0bcf4cf7 afdded58
......@@ -84,7 +84,12 @@ class management
// Whether to display a header or not.
protected $skipHeader = FALSE;
function __construct ($objectTypes = FALSE)
function __construct (
$objectTypes = FALSE,
array $filterElementDefinitions = [
['TabFilterElement', []],
]
)
{
global $config, $class_mapping;
......@@ -111,7 +116,7 @@ class management
$this->setUpHeadline();
$this->setUpListing();
$this->setUpFilter();
$this->setUpFilter($filterElementDefinitions);
// Add copy&paste and snapshot handler.
if (!$this->skipCpHandler) {
......@@ -139,9 +144,9 @@ class management
$this->listing = new managementListing($this);
}
protected function setUpFilter ()
protected function setUpFilter (array $filterElementDefinitions)
{
$this->filter = new managementFilter($this);
$this->filter = new managementFilter($this, NULL, $filterElementDefinitions);
}
protected function setUpHeadline ()
......
......@@ -46,7 +46,7 @@ class managementFilter
*
* \param string $parent management instance
*/
function __construct (management $parent, bool $fixedScope = NULL)
function __construct (management $parent, bool $fixedScope = NULL, array $filterElementDefinitions = [])
{
global $config;
......@@ -62,9 +62,11 @@ class managementFilter
];
}
$this->filterElements = [
new TabFilterElement($this),
];
$this->filterElements = [];
foreach ($filterElementDefinitions as $filterElementDefinition) {
list($class, $args) = $filterElementDefinition;
$this->filterElements[] = new $class($this, ...$args);
}
$this->fixedScope = $fixedScope;
}
......
......@@ -39,13 +39,21 @@ class selectManagement extends management
['LinkColumn', ['attributes' => 'description', 'label' => 'Description']],
];
function __construct ($objectTypes = FALSE, bool $multiSelect = TRUE, array $neededAttrs = [], array $blackList = [], array $whiteList = [])
function __construct (
$objectTypes = FALSE,
bool $multiSelect = TRUE,
array $neededAttrs = [],
array $blackList = [],
array $whiteList = [],
array $filterElementDefinitions = [
['TabFilterElement', []],
])
{
$this->neededAttrs = $neededAttrs;
$this->multiSelect = $multiSelect;
$this->blackList = $blackList;
$this->whiteList = $whiteList;
parent::__construct($objectTypes);
parent::__construct($objectTypes, $filterElementDefinitions);
}
protected function setUpListing ()
......
......@@ -27,12 +27,6 @@ class mailAddressSelect extends selectManagement
['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
......@@ -77,6 +71,11 @@ class MailsAttribute extends DialogAttribute
'mail' => '*',
],
$this->getFilterBlackList(),
[],
[
['TabFilterElement', []],
['FixedFilterElement', ['(mail=*)']],
]
];
}
......
......@@ -30,12 +30,6 @@ class phoneSelect extends selectManagement
['LinkColumn', ['attributes' => 'nameAttr', 'label' => 'Name']],
['LinkColumn', ['attributes' => 'telephoneNumber', 'label' => 'Number']],
];
protected function setUpFilter ()
{
parent::setUpFilter();
$this->filter->addElement(new FixedFilterElement($this->filter, '(telephoneNumber=*)'));
}
}
/*!
......@@ -104,6 +98,12 @@ class PhoneNumberButtonAttribute extends PhoneNumberAttribute
'macAddress' => '*',
'telephoneNumber' => '*',
],
[],
[],
[
['TabFilterElement', []],
['FixedFilterElement', ['(telephoneNumber=*)']],
]
];
}
......
......@@ -457,6 +457,11 @@ class GenericSelectManagementDialog extends GenericSelectDialog
$this->attribute = $attribute;
$this->dialog = new $this->dialogClass(...$this->attribute->getSelectManagementParameters());
}
function dialog_execute ()
{
return GenericDialog::dialog_execute();
}
}
/*! \brief Object selection dialog allowing only one object to get selected
......@@ -486,8 +491,9 @@ class ObjectsAttribute extends GenericDialogAttribute
protected $dialogClass = 'GenericSelectManagementDialog';
protected $selectManagementParameters;
protected $filterElementDefinitions;
function __construct (string $label, string $description, string $ldapName, bool $required, array $objectTypes, array $defaultValue = [], string $store_attr = 'dn', string $display_attr = 'cn', string $acl = '')
function __construct (string $label, string $description, string $ldapName, bool $required, array $objectTypes, array $defaultValue = [], string $store_attr = 'dn', string $display_attr = 'cn', array $filterElementDefinitions = NULL, string $acl = '')
{
parent::__construct($label, $description, $ldapName, $required, $defaultValue, $store_attr, $display_attr, $acl);
$this->selectManagementParameters = [
......@@ -499,17 +505,22 @@ class ObjectsAttribute extends GenericDialogAttribute
$display_attr => (($display_attr == 'dn') ? 'raw' : '*'),
]
];
$this->filterElementDefinitions = $filterElementDefinitions;
}
public function getSelectManagementParameters (): array
{
return array_merge(
$parameters = array_merge(
$this->selectManagementParameters,
[
$this->getFilterBlackList(),
$this->getFilterWhiteList(),
]
);
if (isset($this->filterElementDefinitions)) {
$parameters[] = $this->filterElementDefinitions;
}
return $parameters;
}
}
......@@ -521,9 +532,9 @@ class ObjectsAttribute extends GenericDialogAttribute
*/
class UsersAttribute extends ObjectsAttribute
{
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $store_attr = 'dn', $display_attr = 'cn', $acl = '')
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $store_attr = 'dn', $display_attr = 'cn', array $filterElementDefinitions = NULL, $acl = '')
{
parent::__construct($label, $description, $ldapName, $required, ['user'], $defaultValue, $store_attr, $display_attr, $acl);
parent::__construct($label, $description, $ldapName, $required, ['user'], $defaultValue, $store_attr, $display_attr, $filterElementDefinitions, $acl);
}
}
......@@ -534,9 +545,9 @@ class UsersAttribute extends ObjectsAttribute
*/
class UsersGroupsRolesAttribute extends ObjectsAttribute
{
function __construct (string $label, string $description, string $ldapName, bool $required = FALSE, array $defaultValue = [], string $store_attr = 'dn', string $display_attr = 'cn', string $acl = '')
function __construct (string $label, string $description, string $ldapName, bool $required = FALSE, array $defaultValue = [], string $store_attr = 'dn', string $display_attr = 'cn', array $filterElementDefinitions = NULL, string $acl = '')
{
parent::__construct($label, $description, $ldapName, $required, ['user', 'group', 'role', 'ogroup'], $defaultValue, $store_attr, $display_attr, $acl);
parent::__construct($label, $description, $ldapName, $required, ['user', 'group', 'role', 'ogroup'], $defaultValue, $store_attr, $display_attr, $filterElementDefinitions, $acl);
$this->selectManagementParameters[2]['cn'] = '*';
$this->selectManagementParameters[2]['uid'] = '*';
$this->selectManagementParameters[2]['objectClass'] = '*';
......@@ -577,9 +588,9 @@ class SystemsAttribute extends ObjectsAttribute
{
protected $dialogClass = 'SystemSelectDialog';
function __construct (string $label, string $description, string $ldapName, bool $required, array $objectTypes = ['terminal', 'workstation', 'server'], array $defaultValue = [], string $store_attr = 'cn', string $display_attr = 'cn', string $acl = '')
function __construct (string $label, string $description, string $ldapName, bool $required, array $objectTypes = ['terminal', 'workstation', 'server'], array $defaultValue = [], string $store_attr = 'cn', string $display_attr = 'cn', array $filterElementDefinitions = NULL, string $acl = '')
{
parent::__construct($label, $description, $ldapName, $required, $objectTypes, $defaultValue, $store_attr, $display_attr, $acl);
parent::__construct($label, $description, $ldapName, $required, $objectTypes, $defaultValue, $store_attr, $display_attr, $filterElementDefinitions, $acl);
}
}
......
......@@ -156,10 +156,10 @@ class aclManagement extends management
$this->listing = new managementListing($this, FALSE);
}
protected function setUpFilter ()
protected function setUpFilter (array $filterElementDefinitions)
{
parent::setUpFilter($filterElementDefinitions);
/* Set scope to sub */
parent::setUpFilter();
$this->filter->setScope('sub');
}
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003 Cajus Pollmeier
Copyright (C) 2011-2018 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
......@@ -57,10 +58,13 @@ class groupManagement extends management
$this->siActive = $o->is_available();
}
parent::__construct();
// TODO enable sort by properties and member types
$this->filter->addElement(new GroupContentFilterElement($this->filter));
parent::__construct(
FALSE,
[
['TabFilterElement', []],
['GroupContentFilterElement', []],
]
);
}
protected function configureActions ()
......
......@@ -24,9 +24,9 @@ class GroupMembersAttribute extends ObjectsAttribute
{
protected $types = [];
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $store_attr = 'dn', $display_attr = 'cn', $acl = '')
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $store_attr = 'dn', $display_attr = 'cn', array $filterElementDefinitions = NULL, $acl = '')
{
parent::__construct($label, $description, $ldapName, $required, array_values(ogroup::$objectTypes), $defaultValue, $store_attr, $display_attr, $acl);
parent::__construct($label, $description, $ldapName, $required, array_values(ogroup::$objectTypes), $defaultValue, $store_attr, $display_attr, $filterElementDefinitions, $acl);
}
function getFilterBlackList ()
......
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