Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
feat(enrollment): add support information in invitation email and
Browse files Browse the repository at this point in the history
deeplink
  • Loading branch information
btry committed Jul 6, 2017
1 parent 705d28d commit b19864a
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 16 deletions.
5 changes: 5 additions & 0 deletions front/invitation.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
}
}
Html::back();
} else if (isset($_POST['resend'])) {
$invitation->check($_GET['id'], READ);
$_POST['_notify'] = '';
$invitation->update($_POST);
Html::back();
} else {
$invitation->check($_GET['id'], READ);
Html::header(
Expand Down
4 changes: 2 additions & 2 deletions inc/agent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function showForm($ID, $options = array()) {

$this->initForm($ID, $options);
$this->showFormHeader($options);
$canedit = static::canUpdate();
$canUpdate = (!$this->isNewID($ID)) && ($this->canUpdate() > 0);

$fields = $this->fields;
$objectName = autoName($this->fields["name"], "name",
Expand All @@ -190,7 +190,7 @@ public function showForm($ID, $options = array()) {
$data = [
'withTemplate' => (isset($options['withtemplate']) && $options['withtemplate'] ? '*' : ''),
'isNewID' => $this->isNewID($ID),
'canUpdate' => (!$this->isNewID($ID)) && ($this->canUpdate() > 0),
'canUpdate' => $canUpdate,
'agent' => $fields,
'pingButton' => Html::submit(_x('button', 'Ping'), array('name' => 'ping')),
'geolocateButton' => Html::submit(_x('button', 'Geolocate'), array('name' => 'geolocate')),
Expand Down
25 changes: 18 additions & 7 deletions inc/invitation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,23 @@ public function getUser() {
protected function createQRCodeDocument(User $user, $învitationToken) {
global $CFG_GLPI;

$entityConfig = new PluginFlyvemdmEntityconfig();
$entityConfig->getFromDBByCrit(['entities_id' => $this->input['entities_id']]);

$personalToken = User::getToken($user->getID(), 'api_token');
$enrollRequest = [
$enrollmentData = [
'url' => rtrim($CFG_GLPI["url_base_api"], '/'),
'user_token' => $personalToken,
'invitation_token' => $învitationToken
'invitation_token' => $învitationToken,
'support_name' => $entityConfig->getField('support_name'),
'support_phone' => $entityConfig->getField('support_phone'),
'support_website' => $entityConfig->getField('support_website'),
'support_email' => $entityConfig->getField('support_email'),
'support_address' => $entityConfig->getField('support_address'),
];

$encodedRequest = PluginFlyvemdmNotificationTargetInvitation::DEEPLINK
. base64_encode(json_encode($enrollRequest, JSON_UNESCAPED_SLASHES));
. base64_encode(json_encode($enrollmentData, JSON_UNESCAPED_SLASHES));

// Generate a QRCode
$barcodeobj = new TCPDF2DBarcode($encodedRequest, 'QRCODE,L');
Expand Down Expand Up @@ -392,22 +400,25 @@ public function showForm($ID, $options = array()) {

$this->initForm($ID, $options);
$this->showFormHeader();
$twig = plugin_flyvemdm_getTemplateEngine();
$fields = $this->fields;
$canUpdate = (!$this->isNewID($ID)) && ($this->canView() > 0) || $this->isNewID($ID);

$fields = $this->fields;
$user = new User();
$user->getFromDB($fields['users_id']);
$fields['_useremails'] = $user->getDefaultEmail();
$data = [
'withTemplate' => (isset($options['withtemplate']) && $options['withtemplate'] ? "*" : ""),
'canUpdate' => (!$this->isNewID($ID)) && ($this->canUpdate() > 0) || $this->isNewID($ID),
'canUpdate' => $canUpdate,
'isNewID' => $this->isNewID($ID),
'invitation' => $fields,
'resendButton' => Html::submit(_x('button', 'Re-send'), array('name' => 'resend')),
];

$twig = plugin_flyvemdm_getTemplateEngine();
echo $twig->render('invitation.html', $data);

if (!$this->isNewID($ID)) {
$options['canedit'] = false;
$options['canedit'] = true;
}
$this->showFormButtons($options);
}
Expand Down
46 changes: 40 additions & 6 deletions inc/notificationtargetinvitation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ public function getTags() {
$tagCollection = array(
'flyvemdm.download_app' => __('Link to download the FlyveMDM Android application', 'flyvemdm'),
'flyvemdm.qrcode' => __('Enrollment QR code', 'flyvemdm'),
'flyvemdm.enroll_url' => __('Enrollment URL', 'flyvemdm'),
'user.firstname' => __('First name of the Flyve MDM fleets manager', 'flyvemdm'),
'user.realname' => __('Last name of the Flyve MDM fleets manager', 'flyvemdm'),
'support.name' => __('Name of the helpdesk', 'flyvemdm'),
'support.phone' => __('Phone number of the helpdesk', 'flyvemdm'),
'support.website' => __('Website if the helpdesk', 'flyvemdm'),
'support.email' => __('Email address of the helpdesk', 'flyvemdm'),
'support.address' => __('Address of the helpdesk', 'flyvemdm'),
);

foreach ($tagCollection as $tag => $label) {
Expand All @@ -92,24 +100,50 @@ public static function getAdditionalDatasForTemplate(NotificationTarget $event)
$document = new Document();
$document->getFromDB($invitation->getField('documents_id'));

// Get the entitiy configuration data
$entityConfig = new PluginFlyvemdmEntityconfig();
$entityConfig->getFromDBByCrit(['entities_id' => $event->obj->getField('entities_id')]);

// build the data of the deeplink
$personalToken = User::getToken($invitation->getField('users_id'), 'api_token');
$enrollRequest = [
$enrollmentData = [
'url' => rtrim($CFG_GLPI["url_base_api"], '/'),
'user_token' => $personalToken,
'invitation_token' => $invitation->getField('invitation_token')
'invitation_token' => $invitation->getField('invitation_token'),
'support_name' => $entityConfig->getField('support_name'),
'support_phone' => $entityConfig->getField('support_phone'),
'support_website' => $entityConfig->getField('support_website'),
'support_email' => $entityConfig->getField('support_email'),
'support_address' => $entityConfig->getField('support_address'),
];

$encodedRequest = PluginFlyvemdmNotificationTargetInvitation::DEEPLINK
. base64_encode(json_encode($enrollRequest, JSON_UNESCAPED_SLASHES));
. base64_encode(json_encode($enrollmentData, JSON_UNESCAPED_SLASHES));

// Fill the template
$event->data['##flyvemdm.qrcode##'] = Document::getImageTag($document->getField('tag'));
$event->data['##flyvemdm.enroll_url##'] = static::DEEPLINK . $encodedRequest;
$event->data['##flyvemdm.enroll_url##'] = $encodedRequest;

// fill the application download URL tag
$event->obj->documents = array($document->getID());
$entityConfig = new PluginFlyvemdmEntityconfig();
$entityConfig->getFromDB($event->obj->getField('entities_id'));
$event->data['##flyvemdm.download_app##'] = $entityConfig->getField('download_url');

// fill the helpdesk information tags
$event->data['##support.name##'] = $entityConfig->getField('support_name');
$event->data['##support.phone##'] = $entityConfig->getField('support_phone');
$event->data['##support.website##'] = $entityConfig->getField('support_website');
$event->data['##support.address##'] = $entityConfig->getField('support_address');
$event->data['##support.email##'] = $entityConfig->getField('support_email');

// fill tags for the Fmyve MDM fleets manager
if (isset($_SESSION['glpiID'])) {
$user = new User();
if ($user->getFromDB($_SESSION['glpiID'])) {
$event->data['##user.realname##'] = $user->getField('realname');
$event->data['##user.firstname##'] = $user->getField('firstname');
$event->data['##user.email##'] = $user->getDefaultEmail();
}
}
}
break;
}
Expand Down
13 changes: 13 additions & 0 deletions install/installer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ protected function getNotificationTargetInvitationEvents() {
'subject' => __('You have been invited to join Flyve MDM', 'flyvemdm'),
'content_text' => __('Hi,
##user.firstname## ##user.realname## invited you to enroll your mobile device
in Flyve Mobile Device Managment (Flyve MDM). Flyve MDM allows administrators
to easily manage and administrate mobile devices. For more information,
please contact ##user.firstname## ##user.realname## to his email address
##user.email##.
Please join the Flyve Mobile Device Management system by downloading
and installing the Flyve MDM application for Android from the following link.
Expand All @@ -356,6 +362,13 @@ protected function getNotificationTargetInvitationEvents() {
', 'flyvemdm'),
'content_html' => __('Hi,
##user.firstname## ##user.realname## invited you to enroll your mobile device
in Flyve Mobile Device Managment (Flyve MDM). Flyve MDM allows administrators
to easily manage and administrate mobile devices. For more information,
please contact ##user.firstname## ##user.realname## to his email address
<a href="mailto:##user.email##?subject=Questions about Flyve MDM">
##user.email##</a>.
Please join the Flyve Mobile Device Management system by downloading
and installing the Flyve MDM application for Android from the following link.
Expand Down
92 changes: 92 additions & 0 deletions tests/0005_Unit/PluginFlyvemdmNotificationTargetInvitationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* LICENSE
*
* Copyright © 2016-2017 Teclib'
* Copyright © 2010-2016 by the FusionInventory Development Team.
*
* This file is part of Flyve MDM Plugin for GLPI.
*
* Flyve MDM Plugin for GLPI is a subproject of Flyve MDM. Flyve MDM is a mobile
* device management software.
*
* Flyve MDM Plugin for GLPI is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Flyve MDM Plugin for GLPI 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with Flyve MDM Plugin for GLPI. If not, see http://www.gnu.org/licenses/.
* ------------------------------------------------------------------------------
* @author Thierry Bugier Pineau
* @copyright Copyright © 2017 Teclib
* @license AGPLv3+ http://www.gnu.org/licenses/agpl.txt
* @link https://github.com/flyve-mdm/flyve-mdm-glpi
* @link https://flyve-mdm.com/
* ------------------------------------------------------------------------------
*/

class PluginFlyvemdmNotificationTargetInvitationTest extends SuperAdminTestCase {

/**
* test
*/
function testAdditionalDataForTemplate() {
// create document
$document = new Document();
$documentInput = [];
$documentInput['entities_id'] = $_SESSION['glpiactive_entity'];
$documentInput['is_recursive'] = '0';
$documentInput['name'] = addslashes(__('Enrollment QR code', 'flyvemdm'));
$documentInput['_only_if_upload_succeed'] = false;
$documentId = $document->add($documentInput);
$this->assertFalse($document->isNewItem());

// create notificatoinTarget
$event = new NotificationTarget();
$event->raiseevent = PluginFlyvemdmNotificationTargetInvitation::EVENT_GUEST_INVITATION;
$event->obj = new PluginFlyvemdmInvitation();
$event->obj->fields['documents_id'] = $documentId;

//create entityConfig
$entityConfig = new PluginFlyvemdmEntityConfig();
$entityConfig->getFromDBByCrit(['entities_id' => $_SESSION['glpiactive_entity']]);
$entityConfigInput = [];
$entityConfigInput['id'] = $entityConfig->getID();
$entityConfigInput['support_name'] = $this->getUniqueString();
$entityConfigInput['support_phone'] = $this->getUniqueString();
$entityConfigInput['support_website'] = $this->getUniqueString();
$entityConfigInput['support_email'] = $this->getUniqueString();
$entityConfigInput['support_address'] = $this->getUniqueString();
$entityConfigInput['download_url'] = $this->getUniqueString();
$entityConfig->update($entityConfigInput);

// add name to the current user
$user = new User();
$userInput = [];
$userInput['id'] = $_SESSION['glpiID'];
$userInput['firstname'] = $this->getUniqueString();
$userInput['realname'] = $this->getUniqueString();
$userInput['_useremails'] = ['john.doe@localhost.local'];
$userInput['is_default'] = 1;
$user->update($userInput);

$invitationNotification = new PluginFlyvemdmNotificationTargetInvitation();
$invitationNotification->getAdditionalDatasForTemplate($event);
$this->assertEquals($event->data['##flyvemdm.qrcode##'], Document::getImageTag($document->getField('tag')));
$this->assertEquals($event->data['##flyvemdm.download_app##'], $entityConfigInput['download_url']);
$this->assertNotEmpty($event->data['##flyvemdm.enroll_url##']);
$this->assertEquals($event->data['##flyvemdm.download_app##'], $entityConfigInput['download_url']);
$this->assertEquals($event->data['##user.firstname##'], $userInput['firstname']);
$this->assertEquals($event->data['##user.realname##'], $userInput['realname']);
$this->assertEquals($event->data['##user.email##'], implode('', $userInput['_useremails']));
$this->assertEquals($event->data['##support.name##'], $entityConfigInput['support_name']);
$this->assertEquals($event->data['##support.phone##'], $entityConfigInput['support_phone']);
$this->assertEquals($event->data['##support.website##'], $entityConfigInput['support_website']);
$this->assertEquals($event->data['##support.email##'], $entityConfigInput['support_email']);
$this->assertEquals($event->data['##support.address##'], $entityConfigInput['support_address']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public function testSuccessfulInvitation($data) {

// Check the pending email has the qr code document
$this->assertJsonStringEqualsJsonString(json_encode(array($document->getID())), $queuedNotification->getField('documents'));

}

}
2 changes: 1 addition & 1 deletion tests/inc/SuperAdminTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* ------------------------------------------------------------------------------
*/

use Glpi\test\CommonTestCase;
use Glpi\Test\CommonTestCase;

class SuperAdminTestCase extends CommonTestCase
{
Expand Down

0 comments on commit b19864a

Please sign in to comment.