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

:sparkles: feat(sinaps) Only send Sinaps acquisiton if data changed or forced

issue #5913
Showing with 35 additions and 4 deletions
+35 -4
<?php <?php
/* /*
This code is part of FusionDirectory (http://www.fusiondirectory.org/) This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 FusionDirectory
Copyright (C) 2017-2019 FusionDirectory
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -26,14 +27,13 @@ class sinapsUser extends simplePlugin ...@@ -26,14 +27,13 @@ class sinapsUser extends simplePlugin
'plShortName' => _('Sinaps'), 'plShortName' => _('Sinaps'),
'plTitle' => _('Sinaps'), 'plTitle' => _('Sinaps'),
'plDescription' => _('Used to send acquisition request for users'), 'plDescription' => _('Used to send acquisition request for users'),
'plFilter' => '(objectClass=*)',
'plSelfModify' => FALSE, 'plSelfModify' => FALSE,
'plObjectClass' => array(), 'plObjectClass' => array(),
'plObjectType' => array('user'), 'plObjectType' => array('user'),
//~ 'plIcon' => '', //~ 'plIcon' => '',
//~ 'plSmallIcon' => '', //~ 'plSmallIcon' => '',
'plProvidedAcls' => array() 'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo())
); );
} }
...@@ -49,12 +49,23 @@ class sinapsUser extends simplePlugin ...@@ -49,12 +49,23 @@ class sinapsUser extends simplePlugin
'sinaps_explanation', FALSE, 'sinaps_explanation', FALSE,
_('This tab takes care of sending Acquisition event to Sinaps whenever a user is modified.') _('This tab takes care of sending Acquisition event to Sinaps whenever a user is modified.')
), ),
new BooleanAttribute(
_('Force Sinaps Acquisition'), _('Send Acquisition data even if data was not modified in FusionDirectory'),
'force_acquisition', FALSE
),
) )
) )
); );
} }
function codeEntiteToldapUuidCallback($codeEntite) function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE, $attributesInfo = NULL)
{
parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo);
$this->attributesAccess['force_acquisition']->setInLdap(FALSE);
}
function codeEntiteToldapUuidCallback ($codeEntite)
{ {
global $config; global $config;
...@@ -98,6 +109,7 @@ class sinapsUser extends simplePlugin ...@@ -98,6 +109,7 @@ class sinapsUser extends simplePlugin
if ($config->get_cfg_value('SinapsEnabled', 'FALSE') == 'FALSE') { if ($config->get_cfg_value('SinapsEnabled', 'FALSE') == 'FALSE') {
return array(); return array();
} }
if ($config->get_cfg_value('SinapsAcquisitionURL', '') == '') { if ($config->get_cfg_value('SinapsAcquisitionURL', '') == '') {
return array('Sinaps acquisition URL is not filled in FusionDirectory configuration'); return array('Sinaps acquisition URL is not filled in FusionDirectory configuration');
} }
...@@ -126,6 +138,25 @@ class sinapsUser extends simplePlugin ...@@ -126,6 +138,25 @@ class sinapsUser extends simplePlugin
$attributes[$ldapField] = 1; $attributes[$ldapField] = 1;
} }
if (!$this->force_acquisition) {
/* Skip sync if no field changed */
$sync = FALSE;
foreach (array_keys($attributes) as $ldapField) {
foreach ($this->parent->by_object as $class => $tab) {
  • :warning: Remove this unused "$class" local variable. :blue_book:

Please register or sign in to reply
if (isset($tab->attributesAccess[$ldapField])) {
if ($tab->attributesAccess[$ldapField]->hasChanged()) {
$sync = TRUE;
break 2;
}
break;
}
}
}
if (!$sync) {
return array();
}
}
$attributes['dn'] = 'raw'; $attributes['dn'] = 'raw';
$users = objects::ls('user', $attributes, $this->dn, '', FALSE, 'base'); $users = objects::ls('user', $attributes, $this->dn, '', FALSE, 'base');
......
  • SonarQube analysis reported 3 issues

    • :warning: 3 major

    Watch the comments in this conversation to review them.

    2 extra issues

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. :warning: This function "getUserValues" has 198 lines, which is greater than the 150 lines authorized. Split it into smaller functions. :blue_book:
    2. :warning: Review the data-flow - use of uninitialized value. :blue_book:
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