From 6c327e7a64791426351a0ccdbb737cd53209d6a3 Mon Sep 17 00:00:00 2001 From: ralf Date: Fri, 3 Feb 2023 11:28:43 +0100 Subject: [PATCH] * LDAP/Addressbook: make further LDAP attributes available as custom-fields using "ldap_" as name for accounts in LDAP --- addressbook/inc/class.addressbook_ui.inc.php | 8 +++++++- api/src/Contacts/Ldap.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 5317d5a6cd..bff4686e89 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -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'] || diff --git a/api/src/Contacts/Ldap.php b/api/src/Contacts/Ldap.php index 8287de943d..9598a69c95 100644 --- a/api/src/Contacts/Ldap.php +++ b/api/src/Contacts/Ldap.php @@ -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);