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

Merge branch '5135-filter-enhancement-and-management-refactor' into '1.4-dev'

Resolve "filter enhancement and management refactor"

See merge request fusiondirectory/fd!523
parents c2cf0407 1c785ba3
......@@ -62,7 +62,7 @@ class Action
$this->callable = $callable;
$this->inmenu = $inmenu;
$this->inline = $inline;
$this->validTypes = $validTypes;
$this->validTypes = array_map('strtoupper', $validTypes);
$this->acl = array();
/*
* acl may be of the form:
......@@ -194,7 +194,7 @@ class Action
return '';
}
if (!empty($this->validTypes) && !($entry->isTemplate() && in_array('template', $this->validTypes)) && !in_array($entry->type, $this->validTypes)) {
if (!empty($this->validTypes) && !($entry->isTemplate() && in_array('TEMPLATE', $this->validTypes)) && !in_array($entry->type, $this->validTypes)) {
return '';
}
......
......@@ -38,6 +38,17 @@ class SubMenuAction extends Action
}
}
function addAction(Action $action)
{
$this->actions[] = $action;
$names = $action->listActions();
foreach ($names as $name) {
$this->handlers[$name] = $action;
}
/* Rerun registerAction process */
$this->parent->registerAction($this);
}
function setParent(management $parent)
{
parent::setParent($parent);
......@@ -46,7 +57,6 @@ class SubMenuAction extends Action
}
}
function listActions()
{
return array_keys($this->handlers);
......
......@@ -29,15 +29,20 @@ class LinkColumn extends Column
if ($value == '') {
return ' ';
} else {
if ($this->parent->parent instanceof selectManagement) {
if ($this->parent->getMultiSelect()) {
return '<label title="'.$entry->dn.'" for="listing_selected_'.$entry->row.'">'.htmlentities($value, ENT_COMPAT, 'UTF-8').'</label>';
} else {
return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$entry->getPid().'&amp;act=listing_select_'.$entry->row.'&amp;add_finish=1" title="'.$entry->dn.'">'.htmlentities($value, ENT_COMPAT, 'UTF-8').'</a>';
}
return $this->renderLink($entry, htmlentities($value, ENT_COMPAT, 'UTF-8'));
}
}
protected function renderLink(ListingEntry $entry, $htmlValue)
{
if ($this->parent->parent instanceof selectManagement) {
if ($this->parent->getMultiSelect()) {
return '<label title="'.$entry->dn.'" for="listing_selected_'.$entry->row.'">'.$htmlValue.'</label>';
} else {
return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$entry->getPid().'&amp;act=listing_edit_'.$entry->row.'" title="'.$entry->dn.'">'.htmlentities($value, ENT_COMPAT, 'UTF-8').'</a>';
return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$entry->getPid().'&amp;act=listing_select_'.$entry->row.'&amp;add_finish=1" title="'.$entry->dn.'">'.$htmlValue.'</a>';
}
} else {
return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$entry->getPid().'&amp;act=listing_edit_'.$entry->row.'" title="'.$entry->dn.'">'.$htmlValue.'</a>';
}
}
}
<?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.
*/
/*!
* \brief Column rendering unix timestamp
*/
class UnixTimestampColumn extends LinkColumn
{
protected $type = 'integer';
function renderCell(ListingEntry $entry)
{
$value = $this->getAttributeValue($entry);
if ($value != '') {
$dateObject = DateTime::createFromFormat('U', $value, new DateTimeZone('UTC'));
if (is_object($dateObject)) {
return $this->renderLink($entry, $dateObject->format('d.m.Y'));
}
}
return '&nbsp;';
}
}
<?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 LockAction extends Action
{
function __construct($name, $targets, $callable, array $acl = array(), $inmenu = TRUE, $inline = TRUE)
{
parent::__construct(
$name,
array('lock' => _('Lock users'), 'unlock' => _('Unlock users')),
array(
'lock' => 'geticon.php?context=status&icon=object-locked&size=16',
'unlock' => 'geticon.php?context=status&icon=object-unlocked&size=16',
),
$targets, $callable, $acl, $inmenu, $inline);
}
function isLocked(ListingEntry $entry)
{
if (isset($entry['userPassword']) && preg_match('/^\{[^\}]/', $entry['userPassword'])) {
return (preg_match('/^[^\}]*+\}!/', $entry['userPassword']) === 1);
} elseif ((strtolower($entry->type) == 'user') && !isset($entry['userPassword'])) {
/* Empty lockable password */
return FALSE;
}
return NULL;
}
function fillMenuItems(&$actions)
{
if (!$this->inmenu) {
return;
}
if (!$this->hasPermission($this->parent->listing->getBase())) {
return;
}
$actions[] = array(
'name' => $this->name.'_lock',
'icon' => $this->icon['lock'],
'label' => $this->label['lock'],
'enabled' => $this->isEnabledFor(),
'separator' => $this->separator,
);
$actions[] = array(
'name' => $this->name.'_unlock',
'icon' => $this->icon['unlock'],
'label' => $this->label['unlock'],
'enabled' => $this->isEnabledFor(),
'separator' => FALSE,
);
}
function fillRowClasses(&$classes, ListingEntry $entry)
{
if ($this->isLocked($entry) === TRUE) {
$classes[] = 'entry-locked';
}
}
function renderColumnIcons(ListingEntry $entry)
{
if (!$this->inline) {
return '';
}
// Skip the entry completely if there's no permission to execute it
if (!$this->hasPermission($entry->dn, $entry->getTemplatedType(), $entry->isTemplate())) {
return '<img src="images/empty.png" alt=" " class="center optional"/>';
}
$lockStatus = $this->isLocked($entry);
if ($lockStatus === NULL) {
return '<img src="images/empty.png" alt=" " class="center optional"/>';
} elseif ($lockStatus) {
// Render
return '<input type="image" src="'.htmlentities($this->icon['lock'], ENT_COMPAT, 'UTF-8').'"'.
' title="'.$this->label['unlock'].'" alt="'.$this->label['unlock'].'" name="listing_'.$this->name.'_unlock_'.$entry->row.'"/>';
} else {
return '<input type="image" src="'.htmlentities($this->icon['unlock'], ENT_COMPAT, 'UTF-8').'"'.
' title="'.$this->label['lock'].'" alt="'.$this->label['lock'].'" name="listing_'.$this->name.'_lock_'.$entry->row.'"/>';
}
}
}
......@@ -19,90 +19,6 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class LockAction extends Action
{
function __construct($name, $targets, $callable, array $acl = array(), $inmenu = TRUE, $inline = TRUE)
{
parent::__construct(
$name,
array('lock' => _('Lock users'), 'unlock' => _('Unlock users')),
array(
'lock' => 'geticon.php?context=status&icon=object-locked&size=16',
'unlock' => 'geticon.php?context=status&icon=object-unlocked&size=16',
),
$targets, $callable, $acl, $inmenu, $inline);
}
function isLocked(ListingEntry $entry)
{
if (isset($entry['userPassword']) && preg_match('/^\{[^\}]/', $entry['userPassword'])) {
return (preg_match('/^[^\}]*+\}!/', $entry['userPassword']) === 1);
} elseif ((strtolower($entry->type) == 'user') && !isset($entry['userPassword'])) {
/* Empty lockable password */
return FALSE;
}
return NULL;
}
function fillMenuItems(&$actions)
{
if (!$this->inmenu) {
return;
}
if (!$this->hasPermission($this->parent->listing->getBase())) {
return;
}
$actions[] = array(
'name' => $this->name.'_lock',
'icon' => $this->icon['lock'],
'label' => $this->label['lock'],
'enabled' => $this->isEnabledFor(),
'separator' => $this->separator,
);
$actions[] = array(
'name' => $this->name.'_unlock',
'icon' => $this->icon['unlock'],
'label' => $this->label['unlock'],
'enabled' => $this->isEnabledFor(),
'separator' => FALSE,
);
}
function fillRowClasses(&$classes, ListingEntry $entry)
{
if ($this->isLocked($entry) === TRUE) {
$classes[] = 'entry-locked';
}
}
function renderColumnIcons(ListingEntry $entry)
{
if (!$this->inline) {
return '';
}
// Skip the entry completely if there's no permission to execute it
if (!$this->hasPermission($entry->dn, $entry->getTemplatedType(), $entry->isTemplate())) {
return '<img src="images/empty.png" alt=" " class="center optional"/>';
}
$lockStatus = $this->isLocked($entry);
if ($lockStatus === NULL) {
return '<img src="images/empty.png" alt=" " class="center optional"/>';
} elseif ($lockStatus) {
// Render
return '<input type="image" src="'.htmlentities($this->icon['lock'], ENT_COMPAT, 'UTF-8').'"'.
' title="'.$this->label['unlock'].'" alt="'.$this->label['unlock'].'" name="listing_'.$this->name.'_unlock_'.$entry->row.'"/>';
} else {
return '<input type="image" src="'.htmlentities($this->icon['unlock'], ENT_COMPAT, 'UTF-8').'"'.
' title="'.$this->label['lock'].'" alt="'.$this->label['lock'].'" name="listing_'.$this->name.'_lock_'.$entry->row.'"/>';
}
}
}
class userManagement extends management
{
public $neededAttrs = array('userPassword' => '1');
......@@ -209,4 +125,3 @@ class userManagement extends management
}
}
}
?>
  • SonarQube analysis indicates that quality gate is failed.

    • Security Rating on New Code is passed: Actual value 1
    • Reliability Rating on New Code is failed: Actual value 3 > 1
    • Maintainability Rating on New Code is passed: Actual value 1
    • Duplicated Lines on New Code (%) is passed: Actual value 3.2458870609159627

    SonarQube analysis reported no issues.

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