Implemented kolab_delegation_purge_identities setting
This commit is contained in:
parent
167a0bbbdf
commit
cda4c47325
2 changed files with 18 additions and 11 deletions
|
@ -88,16 +88,12 @@ class kolab_delegation extends rcube_plugin
|
||||||
// or alias email if 'kolab_delegation_purge_identities' is set.
|
// or alias email if 'kolab_delegation_purge_identities' is set.
|
||||||
|
|
||||||
$engine = $this->engine();
|
$engine = $this->engine();
|
||||||
$delegators = $engine->list_delegators();
|
|
||||||
|
|
||||||
if (empty($delegators)) {
|
|
||||||
return $args;
|
|
||||||
}
|
|
||||||
|
|
||||||
$storage = $this->rc->get_storage();
|
$storage = $this->rc->get_storage();
|
||||||
|
$delegators = $engine->list_delegators();
|
||||||
$other_ns = $storage->get_namespace('other');
|
$other_ns = $storage->get_namespace('other');
|
||||||
$folders = $storage->list_folders();
|
$folders = $storage->list_folders();
|
||||||
$identities = $this->rc->user->list_identities();
|
$identities = $this->rc->user->list_identities();
|
||||||
|
$emails = array();
|
||||||
|
|
||||||
// convert identities to simpler format for faster access
|
// convert identities to simpler format for faster access
|
||||||
foreach ($identities as $idx => $ident) {
|
foreach ($identities as $idx => $ident) {
|
||||||
|
@ -110,16 +106,17 @@ class kolab_delegation extends rcube_plugin
|
||||||
// 'html_signature' => $ident['html_signature'],
|
// 'html_signature' => $ident['html_signature'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$identities[$idx] = $ident['email'];
|
$emails[$ident['identity_id']] = $ident['email'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// for every delegator...
|
// for every delegator...
|
||||||
foreach ($delegators as $delegator) {
|
foreach ($delegators as $delegator) {
|
||||||
$email_arr = (array)$delegator['email'];
|
$email_arr = $delegator['email'];
|
||||||
$diff = array_intersect($identities, $email_arr);
|
$diff = array_intersect($emails, $email_arr);
|
||||||
|
|
||||||
// identity with delegator's email already exist, do nothing
|
// identity with delegator's email already exist, do nothing
|
||||||
if (count($diff)) {
|
if (count($diff)) {
|
||||||
|
$emails = array_diff($emails, $email_arr);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,6 +143,16 @@ class kolab_delegation extends rcube_plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove identities that "do not belong" to user nor delegators
|
||||||
|
if ($this->rc->config->get('kolab_delegation_purge_identities')) {
|
||||||
|
$user = $engine->user(true);
|
||||||
|
$emails = array_diff($emails, $user['email']);
|
||||||
|
|
||||||
|
foreach (array_keys($emails) as $idx) {
|
||||||
|
$this->rc->user->delete_identity($idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -450,7 +450,7 @@ class kolab_delegation_engine
|
||||||
*
|
*
|
||||||
* @return array User data
|
* @return array User data
|
||||||
*/
|
*/
|
||||||
public function user()
|
public function user($parsed = false)
|
||||||
{
|
{
|
||||||
if (!isset($this->cache['user'])) {
|
if (!isset($this->cache['user'])) {
|
||||||
$ldap = $this->ldap();
|
$ldap = $this->ldap();
|
||||||
|
@ -465,7 +465,7 @@ class kolab_delegation_engine
|
||||||
$this->cache['user'] = $ldap->get_record($this->ldap_dn, true);
|
$this->cache['user'] = $ldap->get_record($this->ldap_dn, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->cache['user'];
|
return $parsed ? $this->parse_ldap_record($this->cache['user']) : $this->cache['user'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue