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

:ambulance: fix(supann) Fixed setting etablissement as root

issue #5911
Showing with 15 additions and 8 deletions
+15 -8
......@@ -157,6 +157,7 @@ class etablissement extends simplePlugin
$this->attributesAccess['set_root']->setInLdap(FALSE);
$this->attributesAccess['set_root']->setDisabled(($root_code !== FALSE) && ($root_code != $this->supannEtablissement));
$this->set_root = (($root_code !== FALSE) && ($root_code == $this->supannEtablissement));
$this->attributes['set_root']->setInitialValue($this->set_root);
}
protected function ldap_remove()
......@@ -183,12 +184,14 @@ class etablissement extends simplePlugin
function ldap_save()
{
global $config;
$errors = parent::ldap_save();
$ldap = $config->get_ldap_link();
$root_mode = FALSE;
$root_code = $this->get_root_code();
$wasRoot = $this->attributes['set_root']->getInitialValue();
$root_mode = FALSE;
$root_code = $this->get_root_code();
if (($root_code === FALSE) && ($this->set_root)) {
/* Set this etablissement as root one */
$ldap->cat($this->dn);
......@@ -205,30 +208,34 @@ class etablissement extends simplePlugin
}
}
$root_mode = 'add';
} elseif (($root_code !== FALSE) && ($root_code == $this->supannEtablissement) && $this->set_root) {
} elseif (($root_code !== FALSE) && $wasRoot && $this->set_root) {
/* We are the root etablissement, we need to update it */
$root_attrs = $this->attrs;
$root_mode = 'modify';
} elseif (($root_code !== FALSE) && ($root_code == $this->supannEtablissement) && !$this->set_root) {
} elseif (($root_code !== FALSE) && $wasRoot && !$this->set_root) {
/* We are the root etablissement, we want to delete it */
$root_mode = 'delete';
}
if ($root_mode) {
$root_attrs['objectClass'] = array('top','dcObject','organization','supannOrg','eduOrg');
$root_attrs['dc'] = $root_attrs['o'];
unset($root_attrs['supannCodeEntite']);
$dn = 'o='.$this->o.','.$config->current['BASE'];
if ($root_mode == 'delete') {
$ldap->rmdir($dn);
} else {
$root_attrs['objectClass'] = array('top','dcObject','organization','supannOrg','eduOrg');
$root_attrs['dc'] = $root_attrs['o'];
unset($root_attrs['supannTypeEntite']);
unset($root_attrs['supannCodeEntite']);
unset($root_attrs['supannCodeEntiteParent']);
unset($root_attrs['supannRefId']);
$ldap->cd($dn);
$ldap->$root_mode($root_attrs);
}
if (!$ldap->success()) {
$errors[] = msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class());
$errors[] = msgPool::ldaperror($ldap->get_error(), $dn, 0, get_class());
}
}
return $errors;
}
......
  • SonarQube analysis reported 2 issues

    • :warning: 2 major

    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 195 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