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

:sparkles: feat(invitations) Fix problems with invitations

Added a field for creation base in public form objects
Fixed problems in schemas and code
Move registrations to their own management class
Changed format of fdRegistrationLastChange and added
 RegistrationLastChangeAttribute to render it better
This should be completed and also made available as a column for
 registrationManagement
The object resulting from the form filling is not created in the correct
 base for now.

issue #5850
Showing with 133 additions and 22 deletions
+133 -22
...@@ -153,7 +153,7 @@ class invitation extends simplePlugin ...@@ -153,7 +153,7 @@ class invitation extends simplePlugin
$baseObject->base = $this->base; $baseObject->base = $this->base;
$baseObject->fdRegistrationEmailAddress = $email; $baseObject->fdRegistrationEmailAddress = $email;
$baseObject->fdRegistrationState = 'sent'; $baseObject->fdRegistrationState = 'sent';
$baseObject->fdRegistrationLastChange = date('c').':'.$ui->dn; $baseObject->fdRegistrationLastChange = date('c').'|'.$ui->dn;
$baseObject->fdRegistrationInvitationDN = $this->dn; $baseObject->fdRegistrationInvitationDN = $this->dn;
$baseObject->fdRegistrationToken = $token; $baseObject->fdRegistrationToken = $token;
...@@ -175,4 +175,3 @@ class invitation extends simplePlugin ...@@ -175,4 +175,3 @@ class invitation extends simplePlugin
return $errors; 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','registration'), 'plManages' => array('invitation'),
'plProvidedAcls' => array() 'plProvidedAcls' => array()
); );
......
...@@ -19,4 +19,3 @@ ...@@ -19,4 +19,3 @@
*/ */
management::mainInc('invitationManagement'); management::mainInc('invitationManagement');
?>
...@@ -18,6 +18,25 @@ ...@@ -18,6 +18,25 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
class RegistrationLastChangeAttribute extends DisplayLDAPAttribute
{
function renderFormInput ()
{
$value = $this->getValue();
if (!empty($value)) {
list($ldapDate, $author) = explode('|', $value, 2);
$date = LdapGeneralizedTime::fromString($ldapDate);
$date->setTimezone(timezone::getDefaultTimeZone());
$value = sprintf(_('%s - by %s'), $date->format('Y-m-d H:i:s'), $author);
}
if ($this->allowSmarty) {
return $value;
} else {
return '{literal}'.$value.'{/literal}';
}
}
}
class registration extends simplePlugin class registration extends simplePlugin
{ {
public static function plInfo() public static function plInfo()
...@@ -57,7 +76,7 @@ class registration extends simplePlugin ...@@ -57,7 +76,7 @@ class registration extends simplePlugin
_('Status'), _('State of this registration'), _('Status'), _('State of this registration'),
'fdRegistrationState', FALSE 'fdRegistrationState', FALSE
), ),
new DisplayLDAPAttribute( new RegistrationLastChangeAttribute(
_('Last change'), _('Date and author of the last state change'), _('Last change'), _('Date and author of the last state change'),
'fdRegistrationLastChange', FALSE 'fdRegistrationLastChange', FALSE
), ),
...@@ -80,4 +99,3 @@ class registration extends simplePlugin ...@@ -80,4 +99,3 @@ class registration extends simplePlugin
parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo); parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo);
} }
} }
?>
<?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 registrationManagement extends management
{
public static $columns = array(
array('ObjectTypeColumn', array()),
array('LinkColumn', array('attributes' => 'nameAttr', 'label' => 'Email')),
array('LinkColumn', array('attributes' => 'fdRegistrationState', 'label' => 'Status')),
array('LinkColumn', array('attributes' => 'fdRegistrationLastChange', 'label' => 'Last change')),
array('ActionsColumn', array('label' => 'Actions')),
);
public static function plInfo()
{
return array(
'plShortName' => _('Registrations'),
'plTitle' => _('Registrations management'),
'plDescription' => _('Manage registrations'),
'plIcon' => '',
'plSection' => 'accounts',
'plManages' => array('registration'),
'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.
*/
management::mainInc('registrationManagement');
...@@ -80,10 +80,14 @@ attributetype ( 1.3.6.1.4.1.38414.69.11.6 NAME 'fdRegistrationToken' ...@@ -80,10 +80,14 @@ attributetype ( 1.3.6.1.4.1.38414.69.11.6 NAME 'fdRegistrationToken'
objectclass ( 1.3.6.1.4.1.38414.69.2.1 NAME 'fdInvitation' objectclass ( 1.3.6.1.4.1.38414.69.2.1 NAME 'fdInvitation'
DESC 'FusionDirectory - Invitation' DESC 'FusionDirectory - Invitation'
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 'fdRegistration' objectclass ( 1.3.6.1.4.1.38414.69.2.2 NAME 'fdRegistration'
DESC 'FusionDirectory - Registration status and information' DESC 'FusionDirectory - Registration status and information'
MUST ( fdRegistrationEmailAddress $ fdRegistrationState ) MUST ( fdRegistrationEmailAddress $ fdRegistrationState )
MAY ( fdRegistrationLastChange $ MAY (
fdRegistrationInvitationDN $ fdRegistrationUserDN ) ) fdRegistrationLastChange $
fdRegistrationInvitationDN $ fdRegistrationUserDN $
fdRegistrationToken ) )
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
<div id="window-content"> <div id="window-content">
<div> <div>
<p class="infotext"> <p class="infotext">
Hello. Hello.<br/>
<a href="/privateform.php?token={$token|escape}">Click here to connect</a> <a href="privateform.php?token={$token|escape}">Click here to connect</a><br/>
<a href="/publicform.php?token={$token|escape}">Click here if you fail to connect</a> <a href="publicform.php?token={$token|escape}">Click here if you fail to connect</a>
</p> </p>
</div> </div>
</div> </div>
......
...@@ -42,6 +42,8 @@ class publicForm extends simplePlugin ...@@ -42,6 +42,8 @@ class publicForm extends simplePlugin
static function getAttributesInfo () static function getAttributesInfo ()
{ {
global $config;
return array( return array(
'main' => array( 'main' => array(
'name' => _('Form'), 'name' => _('Form'),
...@@ -79,6 +81,11 @@ class publicForm extends simplePlugin ...@@ -79,6 +81,11 @@ class publicForm extends simplePlugin
'fdPublicFormPrivate', FALSE, 'fdPublicFormPrivate', FALSE,
FALSE FALSE
), ),
new StringAttribute(
_('Creation base'), _('Base in which objects will get created'),
'fdPublicFormCreationBase', TRUE,
$config->current['BASE']
),
) )
), ),
); );
...@@ -92,7 +99,7 @@ class publicForm extends simplePlugin ...@@ -92,7 +99,7 @@ class publicForm extends simplePlugin
$choices = template::getTemplatedTypes(); $choices = template::getTemplatedTypes();
$attributesInfo['main']['attrs'][4]->setChoices(array_keys($choices), array_values($choices)); $attributesInfo['main']['attrs'][4]->setChoices(array_keys($choices), array_values($choices));
if (!class_available(invitationManagement)) { if (!class_available('invitationManagement')) {
$attributesInfo['main']['attrs'][7]->setVisible(FALSE); $attributesInfo['main']['attrs'][7]->setVisible(FALSE);
} }
......
...@@ -47,6 +47,13 @@ attributetype ( 1.3.6.1.4.1.38414.67.10.6 NAME 'fdPublicFormPrivate' ...@@ -47,6 +47,13 @@ attributetype ( 1.3.6.1.4.1.38414.67.10.6 NAME 'fdPublicFormPrivate'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
SINGLE-VALUE ) SINGLE-VALUE )
attributetype ( 1.3.6.1.4.1.38414.67.10.7 NAME 'fdPublicFormCreationBase'
DESC 'FusionDirectory - Base in which the objects are created'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE )
# Objectclasses # Objectclasses
objectclass ( 1.3.6.1.4.1.38414.67.2.1 NAME 'fdPublicForm' objectclass ( 1.3.6.1.4.1.38414.67.2.1 NAME 'fdPublicForm'
...@@ -55,4 +62,4 @@ objectclass ( 1.3.6.1.4.1.38414.67.2.1 NAME 'fdPublicForm' ...@@ -55,4 +62,4 @@ objectclass ( 1.3.6.1.4.1.38414.67.2.1 NAME 'fdPublicForm'
MAY ( MAY (
fdPublicFormTitle $ fdPublicFormText $ fdPublicFormTitle $ fdPublicFormText $
fdPublicFormTemplateType $ fdPublicFormTemplateDN $ fdPublicFormTemplateType $ fdPublicFormTemplateDN $
fdPublicFormFinalText $ fdPublicFormPrivate ) ) fdPublicFormFinalText $ fdPublicFormPrivate $ fdPublicFormCreationBase ) )
...@@ -35,7 +35,7 @@ class publicFormPage extends standAlonePage ...@@ -35,7 +35,7 @@ class publicFormPage extends standAlonePage
function save_object() function save_object()
{ {
global $ui; global $config, $ui;
if (!$this->activated) { if (!$this->activated) {
return; return;
...@@ -79,7 +79,7 @@ class publicFormPage extends standAlonePage ...@@ -79,7 +79,7 @@ class publicFormPage extends standAlonePage
} elseif (count($invitations) > 1) { } elseif (count($invitations) > 1) {
throw new FusionDirectoryException('Found several invitations matching token "'.$_GET['token'].'"'); throw new FusionDirectoryException('Found several invitations matching token "'.$_GET['token'].'"');
} }
$this->invitation = reset($registrations); $this->invitation = reset($invitations);
/* Search for the form object */ /* Search for the form object */
$forms = objects::ls( $forms = objects::ls(
'publicForm', 'publicForm',
...@@ -91,11 +91,13 @@ class publicFormPage extends standAlonePage ...@@ -91,11 +91,13 @@ class publicFormPage extends standAlonePage
'fdPublicFormFinalText' => 1, 'fdPublicFormFinalText' => 1,
'fdPublicFormTemplateType' => 1, 'fdPublicFormTemplateType' => 1,
'fdPublicFormTemplateDN' => 1, 'fdPublicFormTemplateDN' => 1,
'fdPublicFormPrivate' => 1 'fdPublicFormPrivate' => 1,
'fdPublicFormCreationBase' => 1
), ),
$this->invitation['fdInvitationFormDN'], $this->invitation['fdInvitationFormDN'],
'', FALSE, 'base' '', FALSE, 'base'
); );
$formName = $this->invitation['fdInvitationFormDN'];
} elseif (isset($_GET['form'])) { } elseif (isset($_GET['form'])) {
/* Search for the form object */ /* Search for the form object */
$forms = objects::ls( $forms = objects::ls(
...@@ -108,18 +110,20 @@ class publicFormPage extends standAlonePage ...@@ -108,18 +110,20 @@ class publicFormPage extends standAlonePage
'fdPublicFormFinalText' => 1, 'fdPublicFormFinalText' => 1,
'fdPublicFormTemplateType' => 1, 'fdPublicFormTemplateType' => 1,
'fdPublicFormTemplateDN' => 1, 'fdPublicFormTemplateDN' => 1,
'fdPublicFormPrivate' => 1 'fdPublicFormPrivate' => 1,
'fdPublicFormCreationBase' => 1
), ),
NULL, NULL,
'(cn='.ldap_escape_f($_GET['form']).')' '(cn='.ldap_escape_f($_GET['form']).')'
); );
$formName = $_GET['form'];
} else { } else {
throw new FusionDirectoryException('Form name or token missing from URL'); throw new FusionDirectoryException('Form name or token missing from URL');
} }
if (count($forms) <= 0) { if (count($forms) <= 0) {
throw new FusionDirectoryException('Form "'.$_GET['form'].'" could not be found'); throw new FusionDirectoryException('Form "'.$formName.'" could not be found');
} elseif (count($forms) > 1) { } elseif (count($forms) > 1) {
throw new FusionDirectoryException('Found several forms named "'.$_GET['form'].'"'); throw new FusionDirectoryException('Found several forms named "'.$formName.'"');
} }
$this->form = reset($forms); $this->form = reset($forms);
if (!isset($this->registration) && isset($this->form['fdPublicFormPrivate']) && ($this->form['fdPublicFormPrivate'] == 'TRUE')) { if (!isset($this->registration) && isset($this->form['fdPublicFormPrivate']) && ($this->form['fdPublicFormPrivate'] == 'TRUE')) {
...@@ -134,7 +138,15 @@ class publicFormPage extends standAlonePage ...@@ -134,7 +138,15 @@ class publicFormPage extends standAlonePage
['user' => ['base']] ['user' => ['base']]
); );
/* TODO Remplir les champs depuis les headers HTTP */ /* TODO Remplir les champs depuis les headers HTTP */
/* TODO Remplir la base en fonction de la base de l’invitation */ /* Fill base depending on publicForm creation base and invitation base */
$base = $this->form['fdPublicFormCreationBase'];
if (isset($this->invitation)) {
$invitationBase = preg_replace('/'.preg_quote($config->current['BASE'], '/').'$/', '', dn2base($this->invitation['dn'], get_ou('invitationRDN')));
if (!empty($invitationBase)) {
$base = $invitationBase.','.$base;
}
}
$this->template->base = $base;
} }
$this->template->save_object(); $this->template->save_object();
...@@ -153,7 +165,7 @@ class publicFormPage extends standAlonePage ...@@ -153,7 +165,7 @@ class publicFormPage extends standAlonePage
$baseObject->fdRegistrationUserDN = $userTabObject->dn; $baseObject->fdRegistrationUserDN = $userTabObject->dn;
$baseObject->fdRegistrationState = 'filled'; $baseObject->fdRegistrationState = 'filled';
$baseObject->fdRegistrationLastChange = date('c').':'.$ui->dn; $baseObject->fdRegistrationLastChange = date('c').'|'.$ui->dn;
$messages = $tabObject->save(); $messages = $tabObject->save();
msg_dialog::displayChecks($messages); msg_dialog::displayChecks($messages);
......
  • SonarQube analysis reported 1 issue

    • :arrow_down_small: 1 minor

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. :arrow_down_small: Remove this method "__construct" to simply inherit it. :blue_book:
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