From ed65985cf5c3309c59b76fee6f5f4f07c58d1749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Wed, 21 Mar 2018 16:31:46 +0100 Subject: [PATCH] :sparkles: feat(management) Add group content filter to group management --- include/class_objects.inc | 4 +- include/management/class_FilterElement.inc | 10 ++- include/management/class_managementFilter.inc | 25 ++++-- .../admin/groups/class_GroupContentColumn.inc | 2 +- .../class_GroupContentFilterElement.inc | 88 +++++++++++++++++++ .../admin/groups/class_groupManagement.inc | 2 +- 6 files changed, 116 insertions(+), 15 deletions(-) create mode 100644 plugins/admin/groups/class_GroupContentFilterElement.inc diff --git a/include/class_objects.inc b/include/class_objects.inc index 9d4cb560d..6c1459599 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 4ca56378e..e58bb6bb4 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 b085ae760..13086558a 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 4199599e4..fb90c71f5 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 000000000..f10a626dc --- /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 c68a10a5b..04066e248 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() -- GitLab