Verified Commit e6064cc5 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(invitations) Add registrations handling

issue #5850
Showing with 198 additions and 21 deletions
+198 -21
...@@ -52,6 +52,10 @@ class invitation extends simplePlugin ...@@ -52,6 +52,10 @@ class invitation extends simplePlugin
_('Name'), _('Name used to identify this invitation'), _('Name'), _('Name used to identify this invitation'),
'cn', TRUE 'cn', TRUE
), ),
new SelectAttribute(
_('Form'), _('Public form this invitation should link to'),
'fdInvitationFormDN', TRUE
),
new StringAttribute( new StringAttribute(
_('Email subject'), _('Subject of the email sent for this invitation'), _('Email subject'), _('Subject of the email sent for this invitation'),
'fdInvitationEmailSubject', TRUE 'fdInvitationEmailSubject', TRUE
...@@ -60,10 +64,6 @@ class invitation extends simplePlugin ...@@ -60,10 +64,6 @@ class invitation extends simplePlugin
_('Email content'), _('Content of the email sent for this invitation'), _('Email content'), _('Content of the email sent for this invitation'),
'fdInvitationEmailContent', TRUE 'fdInvitationEmailContent', TRUE
), ),
new SelectAttribute(
_('Form'), _('Public form this invitation should link to'),
'fdInvitationFormDN', TRUE
),
new DisplayLDAPAttribute( new DisplayLDAPAttribute(
_('Author'), _('Author of this invitation'), _('Author'), _('Author of this invitation'),
'fdInvitationAuthor', FALSE, 'fdInvitationAuthor', FALSE,
...@@ -71,6 +71,19 @@ class invitation extends simplePlugin ...@@ -71,6 +71,19 @@ class invitation extends simplePlugin
), ),
) )
), ),
'emails' => array(
'name' => _('Emails'),
'attrs' => array(
new StringAttribute(
_('From email'), _('Email address set as "From" field and "Reply to" in the sent emails'),
'from_mail', FALSE
),
new FileTextAreaAttribute(
_('Emails'), _('List of email adresses of people to invite - one per line'),
'emails', FALSE
),
)
)
); );
} }
...@@ -80,9 +93,79 @@ class invitation extends simplePlugin ...@@ -80,9 +93,79 @@ class invitation extends simplePlugin
$attributesInfo = $this->getAttributesInfo(); $attributesInfo = $this->getAttributesInfo();
} }
$choices = objects::ls('publicForm'); $choices = objects::ls('publicForm');
$attributesInfo['main']['attrs'][4]->setChoices(array_keys($choices), array_values($choices)); $attributesInfo['main']['attrs'][2]->setChoices(array_keys($choices), array_values($choices));
$attributesInfo['emails']['attrs'][0]->setInLdap(FALSE);
$attributesInfo['emails']['attrs'][1]->setInLdap(FALSE);
parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo); parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo);
} }
function check()
{
$messages = parent::check();
$emails = explode("\n", $this->emails);
foreach ($emails as $email) {
if (!tests::is_email($email)) {
$messages[] = sprintf(_('"%s" is not a valid email address'), $email);
}
}
if (!empty($emails) && empty($this->from_mail)) {
$messages[] = sprintf(_('You need to fill the "%s" field in order to send invitations'), $this->attributesAccess['from_mail']->getLabel());
}
return $messages;
}
protected function shouldSave()
{
return (parent::shouldSave() || !empty($this->emails));
}
protected function ldap_save ()
{
global $ui;
$errors = parent::ldap_save();
if (!empty($errors)) {
return $errors;
}
$emails = explode("\n", $this->emails);
$success = 0;
foreach ($emails as $email) {
if (empty($email)) {
continue;
}
if (mail_utf8($email, FALSE, $this->from_mail, $this->fdInvitationEmailSubject, $this->fdInvitationEmailContent)) {
$tabObject = objects::create('registration');
$baseObject = $tabObject->getBaseObject();
$baseObject->base = $this->base;
$baseObject->fdRegistrationEmailAddress = $email;
$baseObject->fdRegistrationState = 'sent';
$baseObject->fdRegistrationLastChange = date('c').':'.$ui->dn;
$baseObject->fdRegistrationInvitationDN = $this->dn;
$messages = $tabObject->save();
if (!empty($messages)) {
$errors[] = sprintf(_('Failed to create registration object for "%s", because of the following errors: %s'), $email, implode("\n", $messages));
} else {
$success++;
}
} else {
$errors[] = sprintf(_('Failed to send invitation email to "%s". Check your email settings.'), $email);
}
}
if ($success > 0) {
msg_dialog::display(_('Success'), sprintf(_('%d invitations were sent and saved successfully'), $success), INFO_DIALOG);
}
return $errors;
}
} }
?> ?>
...@@ -28,7 +28,7 @@ class invitationManagement extends management ...@@ -28,7 +28,7 @@ class invitationManagement extends management
'plDescription' => _('Manage invitations'), 'plDescription' => _('Manage invitations'),
'plIcon' => '', 'plIcon' => '',
'plSection' => 'accounts', 'plSection' => 'accounts',
'plManages' => array('invitation'), 'plManages' => array('invitation','registration'),
'plProvidedAcls' => array() 'plProvidedAcls' => array()
); );
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class registration extends simplePlugin
{
public static function plInfo()
{
return array(
'plShortName' => _('Registration'),
'plDescription' => _('Registration sent through a public form'),
'plIcon' => '',
'plObjectClass' => array('fdRegistration'),
'plObjectType' => array('registration' => array(
'name' => _('Registration'),
'ou' => get_ou('registrationRDN'),
'icon' => '',
'mainAttr' => 'fdRegistrationEmailAddress',
)),
'plForeignKeys' => array(
'fdRegistrationInvitationDN' => 'invitation',
'fdRegistrationUserDN' => 'user',
),
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo())
);
}
static function getAttributesInfo ()
{
return array(
'main' => array(
'name' => _('Registration'),
'attrs' => array(
new BaseSelectorAttribute(get_ou('registrationRDN')),
new DisplayLDAPAttribute(
_('Email address'), _('Email address which the invitation was sent to'),
'fdRegistrationEmailAddress', TRUE
),
new DisplayLDAPAttribute(
_('Status'), _('State of this registration'),
'fdRegistrationState', FALSE
),
new DisplayLDAPAttribute(
_('Last change'), _('Date and author of the last state change'),
'fdRegistrationLastChange', FALSE
),
new DisplayLDAPAttribute(
_('Invitation'), _('Invitation object used to create this registration'),
'fdRegistrationInvitationDN', FALSE
),
new DisplayLDAPAttribute(
_('User object'), _('User object created by this registration'),
'fdRegistrationUserDN', FALSE
),
)
),
);
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE, $attributesInfo = NULL)
{
parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo);
}
}
?>
...@@ -44,6 +44,11 @@ class invitationsConfig extends simplePlugin ...@@ -44,6 +44,11 @@ class invitationsConfig extends simplePlugin
'fdInvitationRDN', TRUE, 'fdInvitationRDN', TRUE,
'ou=invitations' 'ou=invitations'
), ),
new StringAttribute (
_('Registrations RDN'), _('Branch in which registrations will be stored'),
'fdRegistrationRDN', TRUE,
'ou=registrations'
),
) )
), ),
); );
......
...@@ -10,9 +10,16 @@ attributetype ( 1.3.6.1.4.1.38414.70.1.1 NAME 'fdInvitationRDN' ...@@ -10,9 +10,16 @@ attributetype ( 1.3.6.1.4.1.38414.70.1.1 NAME 'fdInvitationRDN'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE) SINGLE-VALUE)
attributetype ( 1.3.6.1.4.1.38414.70.1.2 NAME 'fdRegistrationRDN'
DESC 'FusionDirectory - Registrations RDN'
EQUALITY caseExactIA5Match
SUBSTR caseExactIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26
SINGLE-VALUE)
# Object Class # Object Class
objectclass ( 1.3.6.1.4.1.38414.70.2.1 NAME 'fdInvitationsPluginConf' objectclass ( 1.3.6.1.4.1.38414.70.2.1 NAME 'fdInvitationsPluginConf'
DESC 'FusionDirectory - Invitations plugin configuration' DESC 'FusionDirectory - Invitations plugin configuration'
SUP top AUXILIARY SUP top AUXILIARY
MUST ( cn ) MUST ( cn )
MAY ( fdInvitationRDN ) ) MAY ( fdInvitationRDN $ fdRegistrationRDN ) )
...@@ -34,36 +34,36 @@ attributetype ( 1.3.6.1.4.1.38414.69.10.4 NAME 'fdInvitationAuthor' ...@@ -34,36 +34,36 @@ attributetype ( 1.3.6.1.4.1.38414.69.10.4 NAME 'fdInvitationAuthor'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE ) SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.69.11.1 NAME 'fdInscriptionEmailAddress' attributetype ( 1.3.6.1.4.1.38414.69.11.1 NAME 'fdRegistrationEmailAddress'
DESC 'FusionDirectory - Email address to which the invitation was sent to' DESC 'FusionDirectory - Email address which the invitation was sent to'
EQUALITY caseIgnoreIA5Match EQUALITY caseIgnoreIA5Match
SUBSTR caseIgnoreIA5SubstringsMatch SUBSTR caseIgnoreIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256}
SINGLE-VALUE ) SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.69.11.2 NAME 'fdInscriptionState' attributetype ( 1.3.6.1.4.1.38414.69.11.2 NAME 'fdRegistrationState'
DESC 'FusionDirectory - State of this inscription' DESC 'FusionDirectory - State of this registration'
EQUALITY caseIgnoreIA5Match EQUALITY caseIgnoreIA5Match
SUBSTR caseIgnoreIA5SubstringsMatch SUBSTR caseIgnoreIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256}
SINGLE-VALUE ) SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.69.11.3 NAME 'fdInscriptionLastChange' attributetype ( 1.3.6.1.4.1.38414.69.11.3 NAME 'fdRegistrationLastChange'
DESC 'FusionDirectory - Date and author of the last state change' DESC 'FusionDirectory - Date and author of the last state change'
EQUALITY caseIgnoreIA5Match EQUALITY caseIgnoreIA5Match
SUBSTR caseIgnoreIA5SubstringsMatch SUBSTR caseIgnoreIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256}
SINGLE-VALUE ) SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.69.11.4 NAME 'fdInscriptionInvitationDN' attributetype ( 1.3.6.1.4.1.38414.69.11.4 NAME 'fdRegistrationInvitationDN'
DESC 'FusionDirectory - DN of the invitation object used for this inscription' DESC 'FusionDirectory - DN of the invitation object used for this registration'
EQUALITY caseIgnoreMatch EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE ) SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.69.11.5 NAME 'fdInscriptionUserDN' attributetype ( 1.3.6.1.4.1.38414.69.11.5 NAME 'fdRegistrationUserDN'
DESC 'FusionDirectory - DN of the user object created by this inscription' DESC 'FusionDirectory - DN of the user object created by this registration'
EQUALITY caseIgnoreMatch EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
...@@ -76,8 +76,8 @@ objectclass ( 1.3.6.1.4.1.38414.69.2.1 NAME 'fdInvitation' ...@@ -76,8 +76,8 @@ objectclass ( 1.3.6.1.4.1.38414.69.2.1 NAME 'fdInvitation'
MUST ( cn ) MUST ( cn )
MAY ( fdInvitationEmailSubject $ fdInvitationEmailContent $ fdInvitationFormDN $ fdInvitationAuthor ) ) MAY ( fdInvitationEmailSubject $ fdInvitationEmailContent $ fdInvitationFormDN $ fdInvitationAuthor ) )
objectclass ( 1.3.6.1.4.1.38414.69.2.2 NAME 'fdInscription' objectclass ( 1.3.6.1.4.1.38414.69.2.2 NAME 'fdRegistration'
DESC 'FusionDirectory - Inscription status and information' DESC 'FusionDirectory - Registration status and information'
MUST ( fdInscriptionEmailAddress $ fdInscriptionState ) MUST ( fdRegistrationEmailAddress $ fdRegistrationState )
MAY ( fdInscriptionLastChange $ MAY ( fdRegistrationLastChange $
fdInscriptionInvitationDN $ fdInscriptionUserDN ) ) fdRegistrationInvitationDN $ fdRegistrationUserDN ) )
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment