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

:sparkles: feat(registrations) Add accept and reject actions on registrations

Also deactivated snapshots and copy/paste for registrations

issue #5850
Showing with 194 additions and 0 deletions
+194 -0
...@@ -20,6 +20,10 @@ ...@@ -20,6 +20,10 @@
class registrationManagement extends management class registrationManagement extends management
{ {
/* Deactivate copy/paste and snapshots */
protected $skipCpHandler = TRUE;
public static $skipSnapshots = TRUE;
public static $columns = array( public static $columns = array(
array('ObjectTypeColumn', array()), array('ObjectTypeColumn', array()),
array('LinkColumn', array('attributes' => 'nameAttr', 'label' => 'Email')), array('LinkColumn', array('attributes' => 'nameAttr', 'label' => 'Email')),
...@@ -28,6 +32,11 @@ class registrationManagement extends management ...@@ -28,6 +32,11 @@ class registrationManagement extends management
array('ActionsColumn', array('label' => 'Actions')), array('ActionsColumn', array('label' => 'Actions')),
); );
public $neededAttrs = array(
'fdRegistrationUserDN' => '1',
'fdRegistrationInvitationDN' => '1',
);
public static function plInfo() public static function plInfo()
{ {
return array( return array(
...@@ -41,4 +50,189 @@ class registrationManagement extends management ...@@ -41,4 +50,189 @@ class registrationManagement extends management
'plProvidedAcls' => array() 'plProvidedAcls' => array()
); );
} }
protected function configureActions()
{
parent::configureActions();
$this->registerAction(
new Action(
'accept', _('Accept'), 'geticon.php?context=actions&icon=add&size=16',
'+', 'acceptRegistration',
array('registration/registration/fdRegistrationState:w')
)
);
$this->registerAction(
new Action(
'reject', _('Reject'), 'geticon.php?context=actions&icon=remove&size=16',
'+', 'rejectRegistration',
array('registration/registration/fdRegistrationState:w')
)
);
$this->actions['accept']->setSeparator(TRUE);
}
/* !\brief Accept registration
*/
function acceptRegistration(array $action)
{
global $config, $ui;
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $action, 'Accept');
foreach ($action['targets'] as $dn) {
// Lock registration object
if ($user = get_lock($dn)) {
msg_dialog::display(
_('Error'),
sprintf(_('Cannot accept %s. It has been locked by %s.'), $dn, $user),
ERROR_DIALOG
);
continue;
}
add_lock ($dn, $ui->dn);
$entry = $this->listing->getEntry($dn);
// Lock user object
if ($user = get_lock($entry['fdRegistrationUserDN'])) {
msg_dialog::display(
_('Error'),
sprintf(_('Cannot move %s. It has been locked by %s.'), $entry['fdRegistrationUserDN'], $user),
ERROR_DIALOG
);
del_lock($dn);
continue;
}
add_lock ($entry['fdRegistrationUserDN'], $ui->dn);
// TODO Détermine la date de peremption
// Open the user
$userTabObject = objects::open($entry['fdRegistrationUserDN'], 'user');
// Move it with the other users
$form = $this->getFormFromRegistration($entry);
$userTabObject->getBaseObject()->base = preg_replace(
'/'.preg_quote($form['fdPublicFormCreationBase'], '$/').'/',
$config->current['BASE'],
$userTabObject->getBaseObject()->base
);
// Deactivate registration tab
$userTabObject->by_object['userRegistration']->is_account = FALSE;
$errors = $userTabObject->save();
// Remove the lock for the user object
del_lock($entry['fdRegistrationUserDN']);
if (empty($errors)) {
// Upon success, update registration object status and history
$tabObject = objects::open($dn, 'registration');
$baseObject = $tabObject->getBaseObject();
$baseObject->fdRegistrationUserDN = $userTabObject->dn;
$baseObject->fdRegistrationState = 'accepted';
$baseObject->fdRegistrationLastChange = date('c').'|'.$ui->dn;
$messages = $tabObject->save();
msg_dialog::displayChecks($messages);
} else {
msg_dialog::displayChecks($errors);
}
// Remove the lock for the registration object
del_lock($dn);
}
}
/* !\brief Reject registration
*/
function rejectRegistration(array $action)
{
global $config, $ui;
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $action, 'Reject');
foreach ($action['targets'] as $dn) {
if ($user = get_lock($dn)) {
msg_dialog::display(
_('Error'),
sprintf(_('Cannot reject %s. It has been locked by %s.'), $dn, $user),
ERROR_DIALOG
);
continue;
}
add_lock ($dn, $ui->dn);
$entry = $this->listing->getEntry($dn);
// Delete the user
if ($user = get_lock($entry['fdRegistrationUserDN'])) {
msg_dialog::display(
_('Error'),
sprintf(_('Cannot delete %s. It has been locked by %s.'), $entry['fdRegistrationUserDN'], $user),
ERROR_DIALOG
);
del_lock($dn);
continue;
}
add_lock ($entry['fdRegistrationUserDN'], $ui->dn);
// Delete the object
$userTabObject = objects::open($entry['fdRegistrationUserDN'], 'user');
$success = $userTabObject->delete();
// Remove the lock for the user object
del_lock($entry['fdRegistrationUserDN']);
if ($success) {
// Upon success, update registration object status and history
$tabObject = objects::open($dn, 'registration');
$baseObject = $tabObject->getBaseObject();
$baseObject->fdRegistrationUserDN = '';
$baseObject->fdRegistrationState = 'rejected';
$baseObject->fdRegistrationLastChange = date('c').'|'.$ui->dn;
$messages = $tabObject->save();
msg_dialog::displayChecks($messages);
}
// Remove the lock for the registration object
del_lock($dn);
}
}
protected function getFormFromRegistration(ListingEntry $entry)
{
$invitations = objects::ls(
'invitation',
array(
'fdInvitationFormDN' => 1
),
$entry['fdRegistrationInvitationDN'],
'', FALSE, 'base'
);
if (count($invitations) <= 0) {
throw new FusionDirectoryException('Could not find invitation "'.$entry['fdRegistrationInvitationDN'].'"');
} elseif (count($invitations) > 1) {
throw new FusionDirectoryException('Found several invitations "'.$entry['fdRegistrationInvitationDN'].'"');
}
$invitation = reset($invitations);
/* Search for the form object */
$forms = objects::ls(
'publicForm',
array(
'dn' => 'raw',
'cn' => 1,
'fdPublicFormTitle' => 1,
'fdPublicFormText' => 1,
'fdPublicFormFinalText' => 1,
'fdPublicFormTemplateType' => 1,
'fdPublicFormTemplateDN' => 1,
'fdPublicFormPrivate' => 1,
'fdPublicFormCreationBase' => 1
),
$invitation['fdInvitationFormDN'],
'', FALSE, 'base'
);
if (count($forms) <= 0) {
throw new FusionDirectoryException('Form "'.$invitation['fdInvitationFormDN'].'" could not be found');
} elseif (count($forms) > 1) {
throw new FusionDirectoryException('Found several forms named "'.$invitation['fdInvitationFormDN'].'"');
}
return reset($forms);
}
} }
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