diff --git a/include/class_objects.inc b/include/class_objects.inc index 9d4cb560d84f51f8a6d1ac89ae188e57b9da4f2b..6c1459599a1ea6c6873c719a3d212774f8b9c318 100644 --- a/include/class_objects.inc +++ b/include/class_objects.inc @@ -87,7 +87,7 @@ class objects foreach ($search_attrs as $search_attr) { $category = $ui->getAttributeCategory($types[0], $search_attr); if ($category === FALSE) { - throw new FusionDirectoryException('Could not find ACL for attribute "'.$search_attr.'"'); + throw new FusionDirectoryException('Could not find ACL for attribute "'.$search_attr.'" for type "'.$types[0].'"'); } if ($category === TRUE) { continue; @@ -231,7 +231,7 @@ class objects foreach ($filterAttributes as $acl) { $category = $ui->getAttributeCategory($types[0], $acl); if ($category === FALSE) { - throw new FusionDirectoryException('Could not find ACL for attribute "'.$acl.'"'); + throw new FusionDirectoryException('Could not find ACL for attribute "'.$acl.'" for type "'.$types[0].'"'); } if ($category === TRUE) { continue; diff --git a/include/management/class_FilterElement.inc b/include/management/class_FilterElement.inc index 4ca56378e7be001d39158b25cdee4e221985935b..e58bb6bb489264d45c6fbbe919835deef17569ae 100644 --- a/include/management/class_FilterElement.inc +++ b/include/management/class_FilterElement.inc @@ -39,15 +39,16 @@ class FilterElement { } - /* Fills LDAP filters */ - public function getFilters(&$filters) + /* Fills LDAP filters for the given type. Returns TRUE if type should be skipped altogether. */ + public function getFilters($type, &$filters) { + return FALSE; } } class TabFilterElement extends FilterElement { - protected $types; + protected $tabs; public function __construct(managementFilter $parent) { @@ -105,12 +106,13 @@ class TabFilterElement extends FilterElement return $smarty->fetch(get_template_path('management/filter-element.tpl')); } - public function getFilters(&$filters) + public function getFilters($type, &$filters) { foreach ($this->tabs as $class => $tab) { if ($tab['checked']) { $filters[] = $tab['filter']; } } + return FALSE; } } diff --git a/include/management/class_managementFilter.inc b/include/management/class_managementFilter.inc index b085ae76059c69d3cf0ac7b69448f242ff34aeb0..13086558ad98b00d688f6204895ce66bf233ae16 100644 --- a/include/management/class_managementFilter.inc +++ b/include/management/class_managementFilter.inc @@ -68,6 +68,11 @@ class managementFilter ); } + function addElement(FilterElement $element) + { + $this->filterElements[] = $element; + } + function update() { if (isset($_POST['FILTER_PID']) && ($_POST['FILTER_PID'] == $this->pid)) { @@ -123,9 +128,6 @@ class managementFilter global $ui; $elementFilters = array(); - foreach ($this->filterElements as $element) { - $element->getFilters($elementFilters); - } if (!empty($this->search)) { if (preg_match('/^\(.+\)$/', $this->search)) { $elementFilters[] = $this->search; @@ -133,10 +135,6 @@ class managementFilter $elementFilters[] = '(|('.implode('=*'.$this->search.'*)(', $this->searchAttributes).'=*'.$this->search.'*))'; } } - $filter = ''; - if (!empty($elementFilters)) { - $filter = '(&'.implode('', $elementFilters).')'; - } $objectTypeCount = array(); $entries = array(); @@ -168,6 +166,19 @@ class managementFilter unset($attrsAsked[$attr]); } } + + $typeElementFilters = $elementFilters; + foreach ($this->filterElements as $element) { + $skip = $element->getFilters($type, $typeElementFilters); + if ($skip === TRUE) { + continue 2; + } + } + $filter = ''; + if (!empty($typeElementFilters)) { + $filter = '(&'.implode('', $typeElementFilters).')'; + } + $ldapEntries = objects::ls($type, $attrsAsked, $searchBase, $filter, TRUE, $this->scope); $objectTypeCount[$type] = count($ldapEntries); diff --git a/plugins/admin/groups/class_GroupContentColumn.inc b/plugins/admin/groups/class_GroupContentColumn.inc index 4199599e44f4ddb4481fe028bd12ecb742f938d1..fb90c71f5c9956c7a442eba839d6de472f3fd4d1 100644 --- a/plugins/admin/groups/class_GroupContentColumn.inc +++ b/plugins/admin/groups/class_GroupContentColumn.inc @@ -19,7 +19,7 @@ */ /*! - * \brief Column showing the activated tabs of the object + * \brief Column showing the types of the member objects */ class GroupContentColumn extends Column { diff --git a/plugins/admin/groups/class_GroupContentFilterElement.inc b/plugins/admin/groups/class_GroupContentFilterElement.inc new file mode 100644 index 0000000000000000000000000000000000000000..f10a626dc81a35a9ad8767437f358a93cb472cbb --- /dev/null +++ b/plugins/admin/groups/class_GroupContentFilterElement.inc @@ -0,0 +1,88 @@ +<?php +/* + This code is part of FusionDirectory (http://www.fusiondirectory.org/) + Copyright (C) 2017-2018 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 Filter on member types + */ +class GroupContentFilterElement extends FilterElement +{ + protected $types; + + public function __construct(managementFilter $parent) + { + global $config; + + parent::__construct($parent); + + $this->types = array(); + foreach (ogroup::$objectTypes as $key => $type) { + $infos = objects::infos($type); + $this->types[$type] = array( + 'filter' => '(gosaGroupObjects=*'.$key.'*)', + 'infos' => $infos, + 'checked' => FALSE, + ); + } + } + + public function update() + { + foreach ($this->types as $type => &$infos) { + $infos['checked'] = isset($_POST['filter_type_'.$type]); + } + unset($infos); + } + + public function render() + { + $inputs = array(); + foreach ($this->types as $type => $infos) { + $inputs['filter_type_'.$type] = array( + 'name' => $infos['infos']['name'], + 'desc' => (isset($infos['infos']['description']) ? $infos['infos']['description'] : $infos['infos']['name']).' '.$infos['filter'], + 'icon' => (isset($infos['infos']['icon']) ? $infos['infos']['icon'] : NULL), + 'checked' => $infos['checked'], + ); + } + $smarty = get_smarty(); + $smarty->assign('NAME', _('Members')); + $smarty->assign('INPUTS', $inputs); + return $smarty->fetch(get_template_path('management/filter-element.tpl')); + } + + public function getFilters($type, &$filters) + { + if (strtoupper($type) == 'OGROUP') { + foreach ($this->types as $type => $infos) { + if ($infos['checked']) { + $filters[] = $infos['filter']; + } + } + } elseif (!$this->types['user']['checked']) { + /* Skip POSIX groups and roles if users are unchecked and at least one type is checked */ + foreach ($this->types as $type => $infos) { + if ($infos['checked']) { + return TRUE; + } + } + } + return FALSE; + } +} diff --git a/plugins/admin/groups/class_groupManagement.inc b/plugins/admin/groups/class_groupManagement.inc index c68a10a5beda8a7a5ee769de52237c427c7b52a3..04066e2488e98f7f41206dd65947b878cf4cb54a 100644 --- a/plugins/admin/groups/class_groupManagement.inc +++ b/plugins/admin/groups/class_groupManagement.inc @@ -59,8 +59,8 @@ class groupManagement extends management parent::__construct(); - // TODO? add group content filter // TODO enable sort by properties and member types + $this->filter->addElement(new GroupContentFilterElement($this->filter)); } protected function configureActions()