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 deeplink in the email to enroll from device and
Browse files Browse the repository at this point in the history
without QR code
  • Loading branch information
btry committed Jun 5, 2017
1 parent eb51e47 commit c3046ae
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
3 changes: 2 additions & 1 deletion inc/invitation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ protected function createQRCodeDocument(User $user, $învitationToken) {
'invitation_token' => $învitationToken
];

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

// Generate a QRCode
$barcodeobj = new TCPDF2DBarcode($encodedRequest, 'QRCODE,L');
Expand Down
20 changes: 19 additions & 1 deletion inc/notificationtargetinvitation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
class PluginFlyvemdmNotificationTargetInvitation extends NotificationTarget {

const EVENT_GUEST_INVITATION = 'plugin_flyvemdm_invitation';
const DEEPLINK = 'flyve://register?data=';

/**
* Define plugins notification events
Expand Down Expand Up @@ -80,6 +81,8 @@ public function getTags() {
* @param array $options
*/
public static function getAdditionalDatasForTemplate(NotificationTarget $event) {
global $CFG_GLPI;

switch ($event->raiseevent) {
case self::EVENT_GUEST_INVITATION:
if (isset($event->obj)) {
Expand All @@ -89,9 +92,24 @@ public static function getAdditionalDatasForTemplate(NotificationTarget $event)
$document = new Document();
$document->getFromDB($invitation->getField('documents_id'));

// build the data of the deeplink
if (version_compare(GLPI_VERSION, "9.2", "ge")) {
$personalToken = User::getToken($invitation->getField('users_id'), 'api_token');
} else {
$personalToken = User::getPersonalToken($invitation->getField('users_id'));
}
$enrollRequest = [
'url' => rtrim($CFG_GLPI["url_base_api"], '/'),
'user_token' => $personalToken,
'invitation_token' => $invitation->getField('invitation_token')
];

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

// Fill the template
$event->datas['##flyvemdm.qrcode##'] = Document::getImageTag($document->getField('tag'));
$event->datas['##flyvemdm.enroll_url##'] = '(not implemented)';
$event->datas['##flyvemdm.enroll_url##'] = static::DEEPLINK . $encodedRequest;
$event->obj->documents = array($document->getID());
$entityConfig = new PluginFlyvemdmEntityconfig();
$entityConfig->getFromDB($event->obj->getField('entities_id'));
Expand Down
12 changes: 10 additions & 2 deletions install/installer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ protected function getNotificationTargetInvitationEvents() {
with the Flyve MDM Application.
If you\'re viewing this email from your device to enroll then tap the
following link.
following link or copy it to your browser.
##flyvemdm.enroll_url##
Expand All @@ -340,6 +340,14 @@ protected function getNotificationTargetInvitationEvents() {
##flyvemdm.download_app##
If you\'re viewing this email from a computer flash the QR code you see below
with the Flyve MDM Application.
If you\'re viewing this email from your device to enroll then tap the
following link or copy it to your browser.
<a href="##flyvemdm.enroll_url##">##flyvemdm.enroll_url##</a>
<img src="cid:##flyvemdm.qrcode##" alt="Enroll QRCode" title="Enroll QRCode" width="128" height="128">
Regards,
Expand Down Expand Up @@ -382,7 +390,7 @@ public function createNotificationTargetInvitation() {
'language' => '',
'subject' => addcslashes($data['subject'], "'\""),
'content_text' => addcslashes($data['content_text'], "'\""),
'content_html' => $contentHtml
'content_html' => addcslashes($contentHtml, "'\"")
]);

// Create the notification
Expand Down
4 changes: 1 addition & 3 deletions tests/0010_Integration/CreateInvitationSendsAnEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ public static function setUpBeforeClass() {
}

/**
*
* session_status()
*/
public function testInitGetSessionToken() {
$this->initSessionByCredentials('glpi', 'glpi');
$this->assertEquals(200, $this->restHttpCode, json_encode($this->restResponse, JSON_PRETTY_PRINT));

self::$sessionToken = $this->restResponse['session_token'];
self::$entityId = $_SESSION['glpiactive_entity'];

Session::destroy();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/0010_Integration/DeviceEnrollmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testEnrollAgentWithBadToken() {
'lastname' => 'Doe',
'version' => '1.0.0',
]);
$this->assertFalse($agentId);
$this->assertFalse($agentId, json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT));

$rows = $invitationLog->find("1");
$this->assertEquals($logCount, count($rows));
Expand Down
6 changes: 5 additions & 1 deletion tests/inc/GuestUserTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public static function setupBeforeClass() {

public function setUp() {
self::setupGLPIFramework();
$_REQUEST['user_token'] = User::getPersonalToken(self::$fixture['guestUser']->getID());
if (version_compare(GLPI_VERSION, '9.2', 'ge')) {
$_REQUEST['user_token'] = User::getToken(self::$fixture['guestUser']->getID(), 'api_token');
} else {
$_REQUEST['user_token'] = User::getPersonalToken(self::$fixture['guestUser']->getID());
}
$this->assertTrue(self::login('', '', false));
}

Expand Down

0 comments on commit c3046ae

Please sign in to comment.