From b6cf077a0b276cd8d71de73c89c15253e678f2b4 Mon Sep 17 00:00:00 2001 From: Thibault Dockx <thibault.dockx@fusiondirectory.org> Date: Tue, 13 Sep 2022 17:56:36 +0100 Subject: [PATCH] :sparkling: Feat(Tasks) - First steps towards mails retrieval. Mail retrieval from DN put in LDAP. Commit to fix in order to save attribute in ldap. --- contrib/openldap/core-fd.schema | 7 +++- plugins/addons/tasks/class_tasksMail.inc | 44 ++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/contrib/openldap/core-fd.schema b/contrib/openldap/core-fd.schema index 4800378cc..276784c4d 100644 --- a/contrib/openldap/core-fd.schema +++ b/contrib/openldap/core-fd.schema @@ -320,6 +320,11 @@ attributetype ( 1.3.6.1.4.1.38414.89.1.6 NAME 'fdTasksCreationDate' EQUALITY caseExactMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 ) +attributetype ( 1.3.6.1.4.1.38414.89.1.7 NAME 'fdTasksEmailsFromdDN' + DESC 'Fusion Directory - Emails derived from DN' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 ) + ##### Classes ##### objectclass ( 1.3.6.1.4.1.10098.1.2.1.19.4 NAME 'gosaDepartment' SUP top AUXILIARY @@ -413,4 +418,4 @@ objectclass (1.3.6.1.4.1.38414.89.2.2 NAME 'fdTasksMail' DESC 'FusionDirectory - Tasks objects Mail' SUP top AUXILIARY MUST ( fdTasksMailObject ) - MAY ( fdTasksMailUsers ) ) + MAY ( fdTasksMailUsers $ fdTasksEmailsFromdDN ) ) diff --git a/plugins/addons/tasks/class_tasksMail.inc b/plugins/addons/tasks/class_tasksMail.inc index 25451458a..0a171b198 100644 --- a/plugins/addons/tasks/class_tasksMail.inc +++ b/plugins/addons/tasks/class_tasksMail.inc @@ -64,9 +64,15 @@ class tasksMail extends simplePlugin '', _('Select Users/Groups'), 'fdTasksMailUsers', TRUE, [], 'dn' - ) + ), + // new HiddenAttribute('fdTasksEmailsFromdDN', TRUE, '', '', 'E-Mails', 'Emails from DN'), + new StringAttribute( + _('Emails'), _('Name for this task'), + 'fdTasksEmailsFromdDN', TRUE + ), ] - ], + ], + ]; } @@ -85,6 +91,40 @@ class tasksMail extends simplePlugin } asort($tmpSearch); $this->attributesAccess['fdTasksMailObject']->setChoices(array_keys($tmpSearch), array_values($tmpSearch)); + $this->attributesAccess['fdTasksEmailsFromdDN']->setVisible(FALSE); + + + } + + /* + * Populate the fdTasksEmailsFromDN attribute with related mails addresses. + */ + protected function shouldSave (): bool + { + global $config; + + $ldap = $config->get_ldap_link(); + + if ($this->attributesAccess['fdTasksMailUsers']->getValue() == TRUE ) { + foreach ($this->attributesAccess['fdTasksMailUsers']->getValue() as $dn) { + + $ldap->cd($dn); + $filter = "(objectClass=gosaMailAccount)"; + $attrs = ["mail"]; + + $ldap->search($filter, $attrs); + $info = $ldap->fetch(); + // To be developped properly to take Supann and other Mail attributes into consideration. + if (!empty($info["mail"][0]) && isset($info["mail"][0])) { + + // For some obscur reasons this attributes won't save in LDAP. + $this->attributesAccess['fdTasksEmailsFromdDN']->setValue($info["mail"][0]); + print_r($this->attributesAccess['fdTasksEmailsFromdDN']->getValue()); + } + } + } + + return parent::shouldSave(); } } -- GitLab