From 0d986e228de148cee690c26c209ff12cf4fb9bcd Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 21 May 2009 16:33:50 +0000 Subject: [PATCH] added $attributes argument to pre/postModifyActions --- lam/lib/baseModule.inc | 6 ++++-- lam/lib/modules.inc | 28 ++++++++++++++++++++++++++- lam/lib/modules/fixed_ip.inc | 14 +++++++++----- lam/lib/modules/phpGroupwareGroup.inc | 13 ++++++------- lam/lib/modules/phpGroupwareUser.inc | 13 ++++++------- lam/lib/modules/posixAccount.inc | 7 ++++--- lam/lib/modules/quota.inc | 7 ++++--- 7 files changed, 60 insertions(+), 28 deletions(-) diff --git a/lam/lib/baseModule.inc b/lam/lib/baseModule.inc index 42c9ca20..e94c2e66 100644 --- a/lam/lib/baseModule.inc +++ b/lam/lib/baseModule.inc @@ -1012,9 +1012,10 @@ abstract class baseModule { * An error message should be printed if the function returns false. * * @param boolean $newAccount new account + * @param array $attributes LDAP attributes of this entry * @return boolean true, if no problems occured */ - public function preModifyActions($newAccount) { + public function preModifyActions($newAccount, $attributes) { return true; } @@ -1024,8 +1025,9 @@ abstract class baseModule { * Calling this method requires the existence of an enclosing {@link accountContainer}. * * @param boolean $newAccount new account + * @param array $attributes LDAP attributes of this entry */ - public function postModifyActions($newAccount) { + public function postModifyActions($newAccount, $attributes) { return; } diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index cdda963e..0bdad695 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -1684,7 +1684,33 @@ class accountContainer { $attributes[$this->dn_orig] = $attributes[$this->finalDN]; unset ($attributes[$this->finalDN]); $this->finalDN = $this->dn_orig; + } + // pre modify actions + $currentAccountAttributes = array(); + if (isset($attributes[$this->finalDN]) && is_array($attributes[$this->finalDN])) { + if (isset($attributes[$this->finalDN]['modify'])) { + $currentAccountAttributes = array_merge($currentAccountAttributes, $attributes[$this->finalDN]['modify']); } + if (isset($attributes[$this->finalDN]['add'])) { + $currentAccountAttributes = array_merge($currentAccountAttributes, $attributes[$this->finalDN]['add']); + } + if (isset($attributes[$this->finalDN]['notchanged'])) { + $currentAccountAttributes = array_merge($currentAccountAttributes, $attributes[$this->finalDN]['notchanged']); + } + } + $currentAccountAttributes['dn'] = $this->finalDN; + $preModifyOk = true; + foreach ($module as $singlemodule) { + $result = $this->module[$singlemodule]->preModifyActions($this->isNewAccount, $currentAccountAttributes); + if (!$result) { + $preModifyOk = false; + break; + } + } + if (!$preModifyOk) { + $errors[] = array('ERROR', _('The operation was stopped because of the above errors.')); + return $errors; + } // Set to true if an real error has happened $stopprocessing = false; if (strtolower($this->finalDN) != strtolower($this->dn_orig)) { @@ -1763,7 +1789,7 @@ class accountContainer { if (!$stopprocessing) { // post modify actions foreach ($module as $singlemodule) { - $this->module[$singlemodule]->postModifyActions($this->isNewAccount); + $this->module[$singlemodule]->postModifyActions($this->isNewAccount, $currentAccountAttributes); } } $_SESSION['cache']->refresh_cache(true); diff --git a/lam/lib/modules/fixed_ip.inc b/lam/lib/modules/fixed_ip.inc index eaa4f96c..33c4125b 100644 --- a/lam/lib/modules/fixed_ip.inc +++ b/lam/lib/modules/fixed_ip.inc @@ -437,11 +437,15 @@ class fixed_ip extends baseModule { } /** - * This function will be overwrite, because this function - * creates the fixed ips after ldap_add command. - **/ - public function postModifyActions($newAccount) { - if ($_SESSION['account']->getAccountModule('dhcp_settings')->dn!=$_SESSION['config']->get_suffix('dhcp')) { + * This function is overwritten because the fixed IPs are set after the ldap_add command. + * + * @see baseModule::postModifyActions() + * + * @param boolean $newAccount + * @param array $attributes LDAP attributes of this entry + */ + public function postModifyActions($newAccount, $attributes) { + if ($_SESSION['account']->getAccountModule('dhcp_settings')->dn!=$_SESSION['config']->get_suffix('dhcp')) { $add = array(); $delete = array(); // Which dns are to delete and to add diff --git a/lam/lib/modules/phpGroupwareGroup.inc b/lam/lib/modules/phpGroupwareGroup.inc index 0dd5ab78..5e9ee485 100644 --- a/lam/lib/modules/phpGroupwareGroup.inc +++ b/lam/lib/modules/phpGroupwareGroup.inc @@ -170,22 +170,21 @@ class phpGroupwareGroup extends baseModule { } /** - * Allows the module to run commands after the LDAP entry is changed or created. - * - * Calling this method requires the existence of an enclosing {@link accountContainer}. + * @see baseModule::postModifyActions() * - * @param boolean $newAccount new account + * @param boolean $newAccount + * @param array $attributes LDAP attributes of this entry */ - public function postModifyActions($newAccount) { + public function postModifyActions($newAccount, $attributes) { // check if extension was removed if (!$newAccount && (in_array('phpgwGroup', $this->orig['objectClass']) && !in_array('phpgwGroup', $this->attributes['objectClass']))) { $dn = $this->getAccountContainer()->finalDN; - $attributes = array( + $myattributes = array( 'objectClass' => array('phpgwGroup'), 'phpgwGroupID' => $this->attributes['phpgwGroupID'] ); - $success = @ldap_mod_del($_SESSION['ldap']->server(), $dn, $attributes); + $success = @ldap_mod_del($_SESSION['ldap']->server(), $dn, $myattributes); if (!$success) { StatusMessage('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $dn), ldap_error($_SESSION['ldap']->server())); } diff --git a/lam/lib/modules/phpGroupwareUser.inc b/lam/lib/modules/phpGroupwareUser.inc index 59546815..e25bb5ab 100644 --- a/lam/lib/modules/phpGroupwareUser.inc +++ b/lam/lib/modules/phpGroupwareUser.inc @@ -316,19 +316,18 @@ class phpGroupwareUser extends baseModule { } /** - * Allows the module to run commands after the LDAP entry is changed or created. - * - * Calling this method requires the existence of an enclosing {@link accountContainer}. + * @see baseModule::postModifyActions() * - * @param boolean $newAccount new account + * @param boolean $newAccount + * @param array $attributes LDAP attributes of this entry */ - public function postModifyActions($newAccount) { + public function postModifyActions($newAccount, $attributes) { // check if extension was removed if (!$newAccount && (in_array('phpgwAccount', $this->orig['objectClass']) && !in_array('phpgwAccount', $this->attributes['objectClass']))) { $dn = $this->getAccountContainer()->finalDN; - $attributes = array_merge(array('objectClass'), $this->meta['attributes']); - $sr = @ldap_read($_SESSION['ldap']->server(), $dn, 'objectClass=*', $attributes); + $myattributes = array_merge(array('objectClass'), $this->meta['attributes']); + $sr = @ldap_read($_SESSION['ldap']->server(), $dn, 'objectClass=*', $myattributes); if (!$sr) { StatusMessage('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $dn), ldap_error($_SESSION['ldap']->server())); return; diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index 9ededb2d..dbe8b355 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -550,11 +550,12 @@ class posixAccount extends baseModule { } /** - * Allows the module to run commands after the LDAP entry was changed or created. + * @see baseModule::postModifyActions() * - * @param boolean $newAccount new account + * @param boolean $newAccount + * @param array $attributes LDAP attributes of this entry */ - function postModifyActions($newAccount) { + public function postModifyActions($newAccount, $attributes) { // create home directory if needed if ($this->createhomedir) { $server = null; diff --git a/lam/lib/modules/quota.inc b/lam/lib/modules/quota.inc index ccdecd21..ddf8a665 100644 --- a/lam/lib/modules/quota.inc +++ b/lam/lib/modules/quota.inc @@ -223,11 +223,12 @@ class quota extends baseModule { } /** - * Allows the module to run commands after the LDAP entry is changed or created. + * @see baseModule::postModifyActions() * - * @param boolean $newAccount new account + * @param boolean $newAccount + * @param array $attributes LDAP attributes of this entry */ - function postModifyActions($newAccount) { + public function postModifyActions($newAccount, $attributes) { if (!isset($this->quota) || !is_array($this->quota)) return; // determine if this is a user or group account if ($this->get_scope()=='user') {