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

:sparkles: feat(management) Add group content filter to group management

Showing with 116 additions and 15 deletions
+116 -15
......@@ -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;
......
......@@ -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)
  • :warning: Remove the unused function parameter "$type". :blue_book: :warning: Remove the unused function parameter "$filters". :blue_book:

    By Ghost User on 2018-04-25T14:21:51 (imported from GitLab)

Please register or sign in to reply
{
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;
}
}
......@@ -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);
......
......@@ -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
{
......
<?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;
}
}
......@@ -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()
......
Supports Markdown
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