Commit e5a02511 authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes: #2407 Cleaned plugin move and tabs_user

Adapted plugin move so that it takes care of update_acls in both mode
(rename or copy/remove). That allows tabs_user to inherit
simpleTabs::save
parent 6012bc7e
......@@ -938,7 +938,7 @@ class plugin
*
* \return boolean TRUE on success else FALSE.
*/
function rename($src_dn, $dst_dn)
private function rename($src_dn, $dst_dn)
{
$start = microtime(1);
......@@ -951,7 +951,43 @@ class plugin
new log("debug","Ldap Protocol v3 implementation error, ldap_rename failed, falling back to manual copy.","FROM: $src_dn -- TO: $dst_dn",array(),$ldap->get_error());
@DEBUG(DEBUG_LDAP,__LINE__,__FUNCTION__,__FILE__,"Rename failed FROM: $src_dn -- TO: $dst_dn",
"Ldap Protocol v3 implementation error, falling back to maunal method.");
return(FALSE);
return FALSE;
}
return TRUE;
}
/*!
* \brief Move ldap entries from one place to another
*
* \param string $src_dn the source DN.
*
* \param string $dst_dn the destination DN.
*/
function move($src_dn, $dst_dn)
{
/* Do not move if only upper- lowercase has changed */
if (strtolower($src_dn) == strtolower($dst_dn)) {
return TRUE;
}
/* Try to move with ldap routines, if this was not successfull
fall back to the old style copy & remove method
*/
if (!$this->rename($src_dn, $dst_dn)) {
/* Copy source to destination */
if (!$this->copy($src_dn, $dst_dn)) {
return FALSE;
}
/* Delete source */
$ldap = $this->config->get_ldap_link();
$ldap->rmdir_recursive($src_dn);
if (!$ldap->success()) {
trigger_error("Trying to delete $src_dn failed.", E_USER_WARNING);
return FALSE;
}
}
/* Get list of users,groups and roles within this tree,
......@@ -1039,53 +1075,6 @@ class plugin
}
/*!
* \brief Move ldap entries from one place to another
*
* \param string $src_dn the source DN.
*
* \param string $dst_dn the destination DN.
*/
function move($src_dn, $dst_dn)
{
/* Do not copy if only upper- lowercase has changed */
if(strtolower($src_dn) == strtolower($dst_dn)){
return(TRUE);
}
/* Try to move the entry instead of copy & delete
*/
if(TRUE){
/* Try to move with ldap routines, if this was not successfull
fall back to the old style copy & remove method
*/
if($this->rename($src_dn, $dst_dn)){
return(TRUE);
}else{
// See code below.
}
}
/* Copy source to destination */
if (!$this->copy($src_dn, $dst_dn)){
return (FALSE);
}
/* Delete source */
$ldap= $this->config->get_ldap_link();
$ldap->rmdir_recursive($src_dn);
if (!$ldap->success()){
trigger_error("Trying to delete $src_dn failed.",
E_USER_WARNING);
return (FALSE);
}
return (TRUE);
}
/* \brief Move/Rename complete trees
*
* \param string $src_dn the source DN.
......
......@@ -292,28 +292,6 @@ function get_browser_language()
return al2gt($langs, 'text/html');
}
/*!
* \brief Rewrite ui object to another dn
*
* Usually used when a user is renamed. In this case the dn
* in the user object must be updated in order to point
* to the correct DN.
*
* \param string $dn the old DN
* \param string $newdn the new DN
*
*/
function change_ui_dn($dn, $newdn)
{
$ui = session::global_get('ui');
if ($ui->dn == $dn) {
$ui->dn = $newdn;
session::global_set('ui', $ui);
}
}
/*!
* \brief Return themed path for specified base file
*
......
......@@ -2,7 +2,7 @@
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003 Cajus Pollmeier
Copyright (C) 2011 FusionDirectory
Copyright (C) 2011-2013 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
......@@ -19,39 +19,15 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class usertabs extends tabs
class usertabs extends simpleTabs
{
function __construct($config, $data, $dn, $cat = '', $copied_object = NULL)
{
parent::__construct($config, $data, $dn, 'user', $copied_object);
/* Add references/acls/snapshots */
$this->addSpecialTabs();
}
function save_object($save_current = FALSE)
{
parent::save_object($save_current);
/* Update reference, transfer variables */
$baseobject = $this->getBaseObject();
foreach ($this->by_object as $name => &$obj) {
/* Don't touch base object */
if ($name != 'user') {
$obj->parent = &$this;
}
/* Copy mail if needed */
if ($name == 'gofaxAccount') {
if (isset($this->by_object['mailAccount']) && $this->by_object['mailAccount']->is_account) {
$obj->mail = $this->by_object['mailAccount']->mail;
}
}
if (isset($this->by_object['gofaxAccount']) && isset($this->by_object['mailAccount']) && $this->by_object['mailAccount']->is_account) {
$this->by_object['gofaxAccount']->mail = $this->by_object['mailAccount']->mail;
}
unset($obj);
/* Update parent in base object */
$baseobject->parent = &$this;
/* Move facsimile / phone number if nessecary */
if ($this->last == 'user' && isset($this->by_object['gofaxAccount'])) {
......@@ -89,31 +65,5 @@ class usertabs extends tabs
/* Possibly change acl base */
$this->set_acl_base();
}
function save()
{
/* Check for new 'dn', in order to propagate the
'dn' to all plugins */
$baseobject = $this->getBaseObject();
$new_dn = $baseobject->compute_dn();
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $new_dn, 'Saving');
/* Move ? */
if ($this->dn != $new_dn) {
/* Write entry on new 'dn' */
if ($this->dn != 'new') {
/* Udpate acls */
$baseobject->update_acls($this->dn, $new_dn);
$baseobject->move($this->dn, $new_dn);
/* Did we change ourselves? Update ui object. */
change_ui_dn($this->dn, $new_dn);
}
/* Happen to use the new one */
$this->dn = $new_dn;
}
return parent::save();
}
}
?>
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