From 5c4484eebe8b6bf8189d1775fb332fd0e3ed38a5 Mon Sep 17 00:00:00 2001 From: Thibault Dockx <thibault.dockx@fusiondirectory.org> Date: Thu, 5 May 2022 17:31:31 +0100 Subject: [PATCH] :sparkles: Feat(MailTemplate) - Adds User Reminder Adds user reminder capability as well as adding conflict between user recovery and itself. Disallowing the activation of the tab. --- contrib/openldap/core-fd.schema | 87 +++++++++- .../class_mailTemplateUserRecovery.inc | 3 +- .../class_mailTemplateUserReminder.inc | 153 ++++++++++++++++++ 3 files changed, 241 insertions(+), 2 deletions(-) create mode 100644 plugins/addons/mailtemplate/class_mailTemplateUserReminder.inc diff --git a/contrib/openldap/core-fd.schema b/contrib/openldap/core-fd.schema index 6c63b40cb..dead589e6 100644 --- a/contrib/openldap/core-fd.schema +++ b/contrib/openldap/core-fd.schema @@ -158,6 +158,81 @@ attributetype ( 1.3.6.1.4.1.38414.88.1.11 NAME 'fdMailTemplateSubject' SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.40) +# Attributes for mail template user reminder + + +attributetype ( 1.3.6.1.4.1.38414.88.1.12 NAME 'fdMTUserReminderForwardAlert' + DESC 'FusionDirectory - Forward alerts to manager' + EQUALITY booleanMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.88.1.13 NAME 'fdMTUserReminderForwardConfirmation' + DESC 'FusionDirectory - Forward postpone confirmations to manager' + EQUALITY booleanMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.88.1.14 NAME 'fdMTUserReminderAlertSubject' + DESC 'Fusion Directory - User reminder alert email subject' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.88.1.15 NAME 'fdMTUserReminderAlertBody' + DESC 'Fusion Directory - User reminder alert email body' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.88.1.16 NAME 'fdMTUserReminderConfirmationSubject' + DESC 'Fusion Directory - User reminder confirmation email subject' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.88.1.17 NAME 'fdMTUserReminderConfirmationBody' + DESC 'Fusion Directory - User reminder confirmation email body' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.88.1.18 NAME 'fdMTUserReminderForwardPpolicyAlert' + DESC 'FusionDirectory - Forward ppolicy alerts to manager' + EQUALITY booleanMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.88.1.19 NAME 'fdMTUserReminderPpolicyAlertSubject' + DESC 'Fusion Directory - User reminder ppolicy alert email subject' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.88.1.20 NAME 'fdMTUserReminderPpolicyAlertBody' + DESC 'Fusion Directory - User reminder ppolicy alert email body' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.88.1.21 NAME 'fdMTUserReminderExpirationSubject' + DESC 'Fusion Directory - User reminder expired email subject' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.88.1.22 NAME 'fdMTUserReminderExpirationBody' + DESC 'Fusion Directory - User reminder expired email body' + EQUALITY caseExactMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 + SINGLE-VALUE ) + +attributetype ( 1.3.6.1.4.1.38414.88.1.23 NAME 'fdMTUserReminderForwardExpiration' + DESC 'FusionDirectory - User reminder, forward expiration emails to manager' + EQUALITY booleanMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 + SINGLE-VALUE ) + # Classes objectclass ( 1.3.6.1.4.1.10098.1.2.1.19.4 NAME 'gosaDepartment' SUP top AUXILIARY @@ -203,7 +278,6 @@ objectclass (1.3.6.1.4.1.38414.88.2.1 NAME 'fdMailTemplate' MUST ( cn $ fdMailTemplateBody $ fdMailTemplateSubject ) MAY ( fdMailTemplateSignature $ fdMailTemplateReadReceipt $ fdMailTemplateAttachment ) ) - objectclass (1.3.6.1.4.1.38414.88.2.2 NAME 'fdMailTemplateUserRecovery' DESC 'FusionDirectory - template mail object Recovery' SUP top AUXILIARY @@ -215,3 +289,14 @@ objectclass ( 1.3.6.1.4.1.38414.88.2.3 NAME 'fdMailTemplateConf' SUP top AUXILIARY MUST ( cn ) MAY ( fdMailTemplateRDN ) ) + +objectclass ( 1.3.6.1.4.1.38414.88.2.4 NAME 'fdMailTemplateUserReminder' + DESC 'FusionDirectory mail template user-reminder' + SUP top AUXILIARY + MUST ( cn $ fdMTUserReminderForwardConfirmation $ fdMTUserReminderForwardAlert) + MAY ( + fdMTUserReminderConfirmationSubject $ fdMTUserReminderConfirmationBody $ + fdMTUserReminderAlertSubject $ fdMTUserReminderAlertBody $ + fdMTUserReminderPpolicyAlertSubject $ fdMTUserReminderPpolicyAlertBody $ + fdMTUserReminderForwardPpolicyAlert $ fdMTUserReminderExpirationSubject $ + fdMTUserReminderExpirationBody $ fdMTUserReminderForwardExpiration) ) diff --git a/plugins/addons/mailtemplate/class_mailTemplateUserRecovery.inc b/plugins/addons/mailtemplate/class_mailTemplateUserRecovery.inc index f0def946c..0d11b850a 100644 --- a/plugins/addons/mailtemplate/class_mailTemplateUserRecovery.inc +++ b/plugins/addons/mailtemplate/class_mailTemplateUserRecovery.inc @@ -34,6 +34,7 @@ class mailTemplateUserRecovery extends simplePlugin 'plObjectClass' => ['fdMailTemplateUserRecovery'], 'plFilter' => '(objectClass=fdMailTemplateUserRecovery)', 'plObjectType' => ['mailTemplate'], + 'plConflicts' => ['mailTemplateUserReminder'], 'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo()) ]; } @@ -97,7 +98,7 @@ class mailTemplateUserRecovery extends simplePlugin $ldap->search('(&(objectClass=fdMailTemplateUserRecovery))', ['cn','fdMTPasswordRecoveryMailSubject']); while ($attrs = $ldap->fetch()) { if (isset($this->attrs['fdMTPasswordRecoveryMailSubject'])) { - $error = new FusionDirectoryError(htmlescape(sprintf(_('User Reminder Template Is Already Existing!')))); + $error = new FusionDirectoryError(htmlescape(sprintf(_('User Recovery Mail Template Is Already Existing!')))); $error->display(); return FALSE; diff --git a/plugins/addons/mailtemplate/class_mailTemplateUserReminder.inc b/plugins/addons/mailtemplate/class_mailTemplateUserReminder.inc new file mode 100644 index 000000000..d885606ff --- /dev/null +++ b/plugins/addons/mailtemplate/class_mailTemplateUserReminder.inc @@ -0,0 +1,153 @@ +<?php + +class mailTemplateUserReminder extends simplePlugin +{ + protected $displayHeader = TRUE; + + static function plInfo (): array + { + return [ + 'plShortName' => _('Mail Template User Reminder'), + 'plDescription' => _('Mail Template User Reminder'), + 'plIcon' => 'geticon.php?context=applications&icon=supann&size=48', + 'plSmallIcon' => 'geticon.php?context=applications&icon=supann-status&size=16', + 'plPriority' => 32, + 'plObjectClass' => ['fdMailTemplateUserReminder'], + 'plFilter' => '(objectClass=fdMailTemplateUserReminder)', + 'plObjectType' => ['mailTemplate'], + 'plConflicts' => ['mailTemplateUserRecovery'], + 'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo()) + ]; + } + + static function getAttributesInfo (): array + { + return [ + 'emailppolicy' => [ + 'name' => _('Ppolicy email settings'), + 'attrs' => [ + new BooleanAttribute( + _('Forward alerts to the manager'), _('Forward ppolicy alerts to the manager'), + 'fdMTUserReminderForwardPpolicyAlert', FALSE, + TRUE + ), + new StringAttribute( + _('Subject'), _('Subject of the ppolicy alert email'), + 'fdMTUserReminderPpolicyAlertSubject', FALSE, + _('[FusionDirectory] Your password is about to expire') + ), + new TextAreaAttribute( + _('Body (%s are cn and login)'), + _('Body of the ppolicy alert email, sent when the user password is about to expire.'), + 'fdMTUserReminderPpolicyAlertBody', FALSE, + _('Dear %sn%,'."\n". + 'your password for account %login% is about to expire, please change your password: '."\n". + 'https://'.$_SERVER['SERVER_NAME']. + (($_SERVER['SERVER_PORT'] != '80') ? ':'.$_SERVER['SERVER_PORT'] : ''). + (empty($_SERVER['REQUEST_URI']) ? $_SERVER['PATH_INFO'] : $_SERVER['REQUEST_URI']). + "\n") + ) + ] + ], + 'alert_mail_reminder' => [ + 'name' => _('Alert email settings'), + 'attrs' => [ + new BooleanAttribute( + _('Forward alerts to the manager'), _('Forward alerts to the manager'), + 'fdMTUserReminderForwardAlert', TRUE, + TRUE + ), + new StringAttribute( + _('Subject'), _('Subject of the alert email'), + 'fdMTUserReminderAlertSubject', FALSE, + _('[FusionDirectory] Your account is about to expire') + ), + new TextAreaAttribute( + _('Body'), + _('Body of the alert email, sent when the user is about to expire.'), + 'fdMTUserReminderAlertBody', FALSE, + _('Dear %sn%,'."\n". + 'your account %login% is about to expire, please use this link to avoid this: '."\n". + 'https://'.$_SERVER['SERVER_NAME']. + (($_SERVER['SERVER_PORT'] != '80') ? ':'.$_SERVER['SERVER_PORT'] : ''). + (empty($_SERVER['REQUEST_URI']) ? $_SERVER['PATH_INFO'] : $_SERVER['REQUEST_URI']). + '/expired_postpone.php?uid=%login%&token=%token%'."\n") + ) + ] + ], + 'alert_mail_confirmation' => [ + 'name' => _('Confirmation email settings'), + 'attrs' => [ + new BooleanAttribute( + _('Forward confirmation to the manager'), _('Forward account extension confirmation to the manager'), + 'fdMTUserReminderForwardConfirmation', TRUE, + TRUE + ), + new StringAttribute( + _('Subject'), _('Subject of the confirmation email'), + 'fdMTUserReminderConfirmationSubject', FALSE, + _('[FusionDirectory] Your account expiration has been postponed') + ), + new TextAreaAttribute( + _('Body'), + _('Body of the confirmation email, sent when the user has postponed expiration.'), + 'fdMTUserReminderConfirmationBody', FALSE, + _('Dear %sn%,'."\n".' your account %login% expiration has been successfully postponed.'."\n") + ), + ] + ], + 'alert_mail_expiration' => [ + 'name' => _('Expiration email settings'), + 'attrs' => [ + new BooleanAttribute( + _('Forward to the manager'), _('Forward account expiration to the manager'), + 'fdMTUserReminderForwardExpiration', TRUE, + TRUE + ), + new StringAttribute( + _('Subject'), _('Subject of the expiration email'), + 'fdMTUserReminderExpirationSubject', FALSE, + _('[FusionDirectory] Your account has expired') + ), + new TextAreaAttribute( + _('Body (%s are cn and login)'), + _('Body of the expiration email, sent when the user has expired.'), + 'fdMTUserReminderExpirationBody', FALSE, + _('Dear %sn%,'."\n".' your account %login% has expired.'."\n") + ), + ] + ], + ]; + } + + function __construct (string $dn = NULL, $object = NULL, $parent = NULL, bool $mainTab = FALSE, array $attributesInfo = NULL) + { + parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo); + + if (!class_available('ppolicy')) { + $this->attributesAccess['fdMTUserReminderForwardPpolicyAlert']->setDisabled(TRUE); + $this->attributesAccess['fdMTUserReminderPpolicyAlertSubject']->setDisabled(TRUE); + $this->attributesAccess['fdMTUserReminderPpolicyAlertBody']->setDisabled(TRUE); + } + } + + protected function shouldSave (): bool + { + global $config; + + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + $ldap->search('(&(objectClass=fdMailTemplateUserReminder))', ['cn','fdMTUserReminderAlertSubject']); + while ($attrs = $ldap->fetch()) { + if (isset($this->attrs['fdMTUserReminderAlertSubject'])) { + $error = new FusionDirectoryError(htmlescape(sprintf(_('User Reminder Mail Template Is Already Existing!')))); + $error->display(); + + return FALSE; + } + } + + return TRUE; + } +} + -- GitLab