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

🚑 fix(core) Store current base to userinfo object instead of raw session var

issue #5135
parent cbf2a255
......@@ -92,11 +92,6 @@ session::global_set('_LAST_PAGE_REQUEST', time());
/* Set template compile directory */
$smarty->compile_dir = $config->get_cfg_value("templateCompileDirectory", SPOOL_DIR);
/* Preset current main base */
if (!session::global_is_set('CurrentMainBase')) {
session::global_set('CurrentMainBase', get_base_from_people($ui->dn));
}
Language::init();
/* Prepare plugin list */
......
......@@ -345,14 +345,16 @@ class config
*/
function set_current($name)
{
global $ui;
if (!isset($this->data['LOCATIONS'][$name])) {
msg_dialog::display(_('Error'), sprintf(_('Location "%s" could not be found in the configuration file'), $name), FATAL_ERROR_DIALOG);
exit;
}
$this->current = $this->data['LOCATIONS'][$name];
if (isset($this->current['INITIAL_BASE'])) {
session::global_set('CurrentMainBase', $this->current['INITIAL_BASE']);
if (isset($this->current['INITIAL_BASE']) && isset($ui)) {
$ui->setCurrentBase($this->current['INITIAL_BASE']);
}
/* Sort referrals, if present */
......
......@@ -71,8 +71,7 @@ class listing
*/
function __construct($data)
{
global $config;
global $class_mapping;
global $config, $class_mapping, $ui;
// Initialize pid
$this->pid = preg_replace("/[^0-9]/", "", microtime(TRUE));
......@@ -87,10 +86,7 @@ class listing
// Set base for filter
if ($this->baseMode) {
$this->base = session::global_get("CurrentMainBase");
if ($this->base == NULL) {
$this->base = $config->current['BASE'];
}
$this->base = $ui->getCurrentBase();
$this->refreshBasesList();
} else {
$this->base = $config->current['BASE'];
......@@ -522,7 +518,7 @@ class listing
$refresh = FALSE;
if ($this->baseMode) {
$this->base = $this->baseSelector->getBase();
session::global_set("CurrentMainBase", $this->base);
$ui->setCurrentBase($this->base);
$refresh = TRUE;
}
......@@ -632,10 +628,11 @@ class listing
*/
function setBase($base)
{
global $ui;
$this->base = $base;
if ($this->baseMode) {
$this->baseSelector->setBase($this->base);
session::global_set('CurrentMainBase', $this->base);
$ui->setCurrentBase($this->base);
}
}
......
......@@ -52,6 +52,9 @@ class userinfo
/*! \brief LDAP size limit handler */
protected $sizeLimitHandler;
/*! \brief Current management base */
protected $currentBase;
/* get acl's an put them into the userinfo object
attr subtreeACL (userdn:components, userdn:component1#sub1#sub2,component2,...) */
function __construct($userdn)
......@@ -1024,9 +1027,29 @@ class userinfo
return $this->sizeLimitHandler;
}
/* \brief Returns the base this user is stored in
*/
function getBase()
{
return get_base_from_people($this->dn);
}
/* \brief Returns the current base the user went to in management classes
*/
function getCurrentBase()
{
if (!empty($this->currentBase)) {
return $this->currentBase;
} else {
return $this->getBase();
}
}
/* \brief Sets the current base the user went to in management classes
*/
function setCurrentBase($base)
{
$this->currentBase = $base;
}
}
?>
......@@ -60,7 +60,7 @@ class managementListing
*/
function __construct($parent, $baseMode = TRUE)
{
global $config;
global $config, $ui;
$this->parent = $parent;
$this->baseMode = $baseMode;
......@@ -70,10 +70,7 @@ class managementListing
// Set base for filter
if ($this->baseMode) {
$this->base = session::global_get('CurrentMainBase'); // TODO Replace with config or ui var
if ($this->base == NULL) {
$this->base = $config->current['BASE'];
}
$this->base = $ui->getCurrentBase();
$this->refreshBasesList();
// Instanciate base selector
......@@ -217,6 +214,8 @@ class managementListing
*/
function updateBase()
{
global $ui;
// Take care of base selector
if ($this->baseMode) {
$this->baseSelector->update();
......@@ -228,7 +227,7 @@ class managementListing
// Save base
$this->base = $this->baseSelector->getBase();
session::global_set('CurrentMainBase', $this->base);
$ui->setCurrentBase($this->base);
}
// Do not do anything if this is not our PID
......@@ -306,10 +305,11 @@ class managementListing
*/
function setBase($base)
{
global $ui;
$this->base = $base;
if ($this->baseMode) {
$this->baseSelector->setBase($this->base);
session::global_set('CurrentMainBase', $this->base);
$ui->setCurrentBase($this->base);
}
}
......
......@@ -59,9 +59,9 @@ class BaseSelectorAttribute extends Attribute
if ($this->plugin->is_template) {
$this->ou = 'ou=templates,'.$this->ou;
}
if ($this->plugin->dn == "new") {
if ($this->plugin->dn == 'new') {
$ui = get_userinfo();
$this->setValue(session::global_is_set("CurrentMainBase") ? session::global_get("CurrentMainBase") : $ui->getBase());
$this->setValue($ui->getCurrentBase());
} else {
$this->setValue(dn2base($this->plugin->dn, $this->ou));
}
......
......@@ -160,14 +160,11 @@ class simpleTabs
function resetBase()
{
global $ui;
$baseobject = $this->getBaseObject();
if (isset($baseobject->base)) {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $baseobject->base, 'Fixing base');
if (session::global_is_set('CurrentMainBase')) {
$baseobject->base = dn2base('cn=dummy,'.session::global_get('CurrentMainBase'));
} else {
$baseobject->base = dn2base(get_userinfo()->dn);
}
$baseobject->base = $ui->getCurrentBase();
if (!($baseobject instanceOf simplePlugin) && is_object($baseobject->baseSelector)) {
/* For some plugins not yet migrated to simple plugin. */
$baseobject->baseSelector->setBase($baseobject->base);
......
......@@ -825,8 +825,9 @@ class setupStepMigrate extends setupStep
function check_adminAccount_migrate_confirm(&$checkobj)
{
global $config;
session::global_set('CurrentMainBase', $config->current['BASE']);
global $config, $ui;
$ui->setCurrentBase($config->current['BASE']);
/* Creating role */
$ldap = $config->get_ldap_link();
......
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