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

:ambulance: fix(supann) Store root establishment information in root node

We misunderstood SupAnn recommendation regarding root establishment,
 this fixes it.
It means we’ll need a migration script in fusiondirectory-setup.

issue #6026
parent 5dc012f8
No related merge requests found
Showing with 65 additions and 52 deletions
+65 -52
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* /*
This code is part of FusionDirectory (http://www.fusiondirectory.org/) This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2012-2019 FusionDirectory Copyright (C) 2012-2020 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
...@@ -21,6 +21,12 @@ ...@@ -21,6 +21,12 @@
class etablissement extends simplePlugin class etablissement extends simplePlugin
{ {
protected static $rootAttributes = [
'o','description','telephoneNumber','facsimileTelephoneNumber','postalAddress','l',
'eduOrgHomePageURI','eduOrgLegalName','eduOrgSuperiorURI','eduOrgWhitePagesURI',
'supannEtablissement'
];
static function plInfo (): array static function plInfo (): array
{ {
return [ return [
...@@ -154,10 +160,9 @@ class etablissement extends simplePlugin ...@@ -154,10 +160,9 @@ class etablissement extends simplePlugin
$this->attributesAccess['supannEtablissement']->setUnique('one'); $this->attributesAccess['supannEtablissement']->setUnique('one');
$this->attributesAccess['eduOrgLegalName']->setUnique('one'); $this->attributesAccess['eduOrgLegalName']->setUnique('one');
$root_code = $this->get_root_code(); $rootCode = $this->get_root_code();
$this->attributesAccess['set_root']->setInLdap(FALSE); $this->attributesAccess['set_root']->setInLdap(FALSE);
$this->attributesAccess['set_root']->setDisabled(($root_code !== FALSE) && !in_array($root_code, $this->supannEtablissement)); $this->set_root = (($rootCode !== FALSE) && in_array($rootCode, $this->supannEtablissement));
$this->set_root = (($root_code !== FALSE) && in_array($root_code, $this->supannEtablissement));
$this->attributesAccess['set_root']->setInitialValue($this->set_root); $this->attributesAccess['set_root']->setInitialValue($this->set_root);
} }
...@@ -175,14 +180,23 @@ class etablissement extends simplePlugin ...@@ -175,14 +180,23 @@ class etablissement extends simplePlugin
return $errors; return $errors;
} }
/* If we're the root etablissement, delete it too */ /* If we're the root etablissement, remove information */
$root_code = $this->get_root_code(); $rootCode = $this->get_root_code();
if (($root_code !== FALSE) && in_array($root_code, $this->supannEtablissement)) { if (($rootCode !== FALSE) && in_array($rootCode, $this->supannEtablissement)) {
$dn = 'o='.$this->o.','.$config->current['BASE']; /* Remove SupAnn attributes from root node */
$ldap = $config->get_ldap_link(); $ldap->cat($config->current['BASE'], array_merge(static::$rootAttributes, ['objectClass']));
  • :no_entry: Review the data-flow - use of uninitialized value. :blue_book:

Please register or sign in to reply
$ldap->rmdir($dn); $baseAttrs = $ldap->fetch();
unset($baseAttrs['objectClass']['count']);
$rootAttrs = [];
$rootAttrs['objectClass'] = array_remove_entries(['supannOrg','eduOrg'], $baseAttrs['objectClass']);
foreach (static::$rootAttributes as $rootAttribute) {
$rootAttrs[$rootAttribute] = [];
}
$rootAttrs['o'] = $baseAttrs['dc'][0];
$ldap->cd($config->current['BASE']);
$ldap->modify($rootAttrs);
if (!$ldap->success()) { if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class())); $errors[] = msgPool::ldaperror($ldap->get_error(), $config->current['BASE'], 0, get_class());
} }
} }
return []; return [];
...@@ -196,50 +210,50 @@ class etablissement extends simplePlugin ...@@ -196,50 +210,50 @@ class etablissement extends simplePlugin
$ldap = $config->get_ldap_link(); $ldap = $config->get_ldap_link();
$wasRoot = $this->attributesAccess['set_root']->getInitialValue(); $wasRoot = $this->attributesAccess['set_root']->getInitialValue();
$root_mode = FALSE; $rootMode = FALSE;
$root_code = $this->get_root_code(); $rootCode = $this->get_root_code();
if (($root_code === FALSE) && ($this->set_root)) { if ($this->set_root) {
/* Set this etablissement as root one */ /* Set this etablissement as root one */
$ldap->cat($this->dn); $rootMode = 'add';
$root_attrs = $ldap->fetch(); } elseif (($rootCode !== FALSE) && $wasRoot && !$this->set_root) {
unset($root_attrs['count']); /* We were the root etablissement, we want to delete it */
unset($root_attrs['dn']); $rootMode = 'remove';
foreach ($root_attrs as $key => $value) {
if (is_numeric($key)) {
unset($root_attrs[$key]);
continue;
}
if (is_array($root_attrs[$key])) {
unset($root_attrs[$key]['count']);
}
}
$root_mode = 'add';
} 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) && $wasRoot && !$this->set_root) {
/* We are the root etablissement, we want to delete it */
$root_mode = 'delete';
} }
if ($root_mode) { if ($rootMode) {
$dn = 'o='.$this->o.','.$config->current['BASE']; $ldap->cat($config->current['BASE'], array_merge(static::$rootAttributes, ['objectClass','dc']));
if ($root_mode == 'delete') { $baseAttrs = $ldap->fetch();
$ldap->rmdir($dn); unset($baseAttrs['objectClass']['count']);
if ($rootMode == 'remove') {
/* Remove SupAnn attributes from root node */
$rootAttrs = [];
$rootAttrs['objectClass'] = array_remove_entries(['supannOrg','eduOrg'], $baseAttrs['objectClass']);
foreach (static::$rootAttributes as $rootAttribute) {
$rootAttrs[$rootAttribute] = [];
}
$rootAttrs['o'] = $baseAttrs['dc'][0];
} else { } else {
$root_attrs['objectClass'] = ['top','dcObject','organization','supannOrg','eduOrg']; /* Add/modify SupAnn attributes of root node */
$root_attrs['dc'] = $root_attrs['o']; $ldap->cat($this->dn, static::$rootAttributes);
unset($root_attrs['supannTypeEntite']); $rootAttrs = $ldap->fetch();
unset($root_attrs['supannCodeEntite']); unset($rootAttrs['count']);
unset($root_attrs['supannCodeEntiteParent']); unset($rootAttrs['dn']);
unset($root_attrs['supannRefId']); foreach ($rootAttrs as $key => $value) {
$ldap->cd($dn); if (is_numeric($key)) {
$ldap->$root_mode($root_attrs); unset($rootAttrs[$key]);
continue;
}
if (is_array($rootAttrs[$key])) {
unset($rootAttrs[$key]['count']);
}
}
$rootAttrs['objectClass'] = array_merge_unique($baseAttrs['objectClass'], ['dcObject','organization','supannOrg','eduOrg']);
} }
$ldap->cd($config->current['BASE']);
$ldap->modify($rootAttrs);
if (!$ldap->success()) { if (!$ldap->success()) {
$errors[] = msgPool::ldaperror($ldap->get_error(), $dn, 0, get_class()); $errors[] = msgPool::ldaperror($ldap->get_error(), $config->current['BASE'], 0, get_class());
} }
} }
...@@ -252,11 +266,10 @@ class etablissement extends simplePlugin ...@@ -252,11 +266,10 @@ class etablissement extends simplePlugin
$ldap = $config->get_ldap_link(); $ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']); $ldap->cd($config->current['BASE']);
$ldap->search('(objectClass=supannOrg)', ['*'], 'one'); $ldap->search('(objectClass=supannOrg)', ['*'], 'base');
if ($ldap->count() > 1) { if ($ldap->count() > 1) {
msg_dialog::display(_('LDAP error'), 'There are several establishments at root!'); throw new FusionDirectoryException('There are several establishments at root!');
return FALSE;
} elseif ($ldap->count() > 0) { } elseif ($ldap->count() > 0) {
$attr = $ldap->fetch(); $attr = $ldap->fetch();
return $attr['supannEtablissement'][0]; return $attr['supannEtablissement'][0];
......
  • SonarQube analysis reported 1 issue

    • :no_entry: 1 blocker

    Watch the comments in this conversation to review them.

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