* LDAP/Addressbook: make further LDAP attributes available as custom-fields using "ldap_<attribute>" as name for accounts in LDAP

This commit is contained in:
ralf 2023-02-03 11:28:43 +01:00
parent c2714a6813
commit 6c327e7a64
2 changed files with 25 additions and 1 deletions

View File

@ -2730,7 +2730,13 @@ class addressbook_ui extends addressbook_bo
if (isset($readonlys['n_fileas'])) $readonlys['fileas_type'] = $readonlys['n_fileas'];
// disable not needed tabs
$readonlys['tabs']['cats'] = !($content['cat_tab'] = $this->config['cat_tab']);
$readonlys['tabs']['custom'] = !$this->customfields || $this->get_backend($content['id'],$content['owner']) == $this->so_accounts;
$readonlys['tabs']['custom'] = !$this->customfields ||
// only show custom fields tab for LDAP, if we have LDAP CF's defined and an existing contact (as no schema defined)
$this->get_backend($content['id'],$content['owner']) == $this->so_accounts &&
(empty($content['id']) || !array_filter($this->customfields, static function($cf)
{
return substr($cf['name'], 0, 5) === 'ldap_';
}));
$readonlys['tabs']['custom_private'] = $readonlys['tabs']['custom'] || !$this->config['private_cf_tab'];
$readonlys['tabs']['distribution_list'] = !$content['distrib_lists'];#false;
$readonlys['tabs']['history'] = $this->contact_repository != 'sql' || !$content['id'] ||

View File

@ -31,6 +31,11 @@ class Ldap
const PERSONAL = 2;
const GROUP = 3;
/**
* Pseudo objectclass used for LDAP attributes made available to use as custom fields
*/
const CF_OBJECTCLASS = 'egwcustomfields';
var $data;
/**
@ -345,6 +350,15 @@ class Ldap
}
$this->ldapServerInfo = $GLOBALS['egw']->ldap->getLDAPServerInfo($this->ldap_config['ldap_contact_host']);
// check if there are any attributes defined via custom-fields
foreach(Api\Storage\Customfields::get('addressbook') as $cf)
{
if (substr($cf['name'], 0, 5) === 'ldap_')
{
$this->schema2egw[self::CF_OBJECTCLASS]['#'.$cf['name']] = strtolower(substr($cf['name'], 5));
}
}
foreach($this->schema2egw as $attributes)
{
$this->all_attributes = array_merge($this->all_attributes,array_values($attributes));
@ -1284,6 +1298,10 @@ class Ldap
'id' => $entry['uid'][0] ?? $entry['entryuuid'][0],
'tid' => 'n', // the type id for the addressbook
);
if (!empty($this->schema2egw[self::CF_OBJECTCLASS]))
{
$entry['objectclass'][] = self::CF_OBJECTCLASS;
}
foreach($entry['objectclass'] as $ii => $objectclass)
{
$objectclass = strtolower($objectclass);