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

Commit

Permalink
feat(enrolment,inventory): get uuid at enrollment to help inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jul 5, 2017
1 parent 62ce681 commit 4d52514
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
21 changes: 13 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
language: php

php:
- 5.6
- 7.0
- 7.1

env:
matrix:
# - GLPI_SOURCE="https://github.com/flyve-mdm/glpi -b 9.1.2-backport" FUSION_SOURCE="https://github.com/fusioninventory/fusioninventory-for-glpi -b glpi9.1+1.1"
- GLPI_SOURCE="https://github.com/glpi-project/glpi -b master" FUSION_SOURCE="https://github.com/fusioninventory/fusioninventory-for-glpi -b master"
# - GLPI_SOURCE="https://github.com/flyve-mdm/glpi -b 9.1.2-backport" FUSION_SOURCE="https://github.com/fusioninventory/fusioninventory-for-glpi -b glpi9.1+1.1"
- GLPI_SOURCE="https://github.com/glpi-project/glpi -b master" FUSION_SOURCE="https://github.com/fusioninventory/fusioninventory-for-glpi -b master"

before_script:
- git clone --depth=1 $GLPI_SOURCE ../glpi && cd ../glpi
Expand All @@ -22,5 +16,16 @@ script:
- vendor/bin/phpunit --verbose
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]]; then vendor/bin/phpcs -p --standard=vendor/glpi-project/coding-standard/GlpiStandard/ *.php install/ inc/ front/ ajax/ tests/; fi

matrix:
include:
- php: 5.6
- php: 7.0
- php: 7.1
- php: nightly
allow_failures:
- php: 7.1
- php: nightly

notifications:
webhooks: https://fathomless-fjord-24024.herokuapp.com/notify

25 changes: 17 additions & 8 deletions inc/agent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,16 +511,16 @@ public function pre_deleteItem() {
$computerId = $computer->getID();
$serial = $computer->getField('serial');
$entityId = $this->getField('entities_id');
$userId = $computer->getField('users_id');
$ownerUserId = $computer->getField('users_id');

// Find other computers belong to the user in the current entity
// TODO : maybe use getEntityRestrict for multientity support
$rows = $computer->find("`entities_id`='$entityId' AND `users_id`='$userId' AND `id` <> '$computerId'", '', '1');
$rows = $computer->find("`entities_id`='$entityId' AND `users_id`='$ownerUserId' AND `id` <> '$computerId'", '', '1');
if (count($rows) == 0) {
// Remove guest habilitation for the entity
$profile_User = new Profile_User();
$success = $profile_User->deleteByCriteria([
'users_id' => $userId,
'users_id' => $ownerUserId,
'entities_id' => $entityId,
'profiles_id' => $guestProfileId,
'is_dynamic' => 0
Expand All @@ -531,14 +531,21 @@ public function pre_deleteItem() {
}

// Check the user still has one or several profiles
$rows = $profile_User->find("`users_id`='$userId'", '', '1');
$rows = $profile_User->find("`users_id`='$ownerUserId'", '', '1');
if (count($rows) == 0) {
// Delete the user
$user = new User();
$user->delete(['id' => $userId], true);
$user->delete(['id' => $ownerUserId], true);
}
}

// Delete the user account of the agent
$agentUserId = $this->fields['users_id'];
$agentUser = new User();
$agentUser->delete([
'id' => $this->fields['users_id'],
], true);

// Delete the MQTT user for the agent
if (!empty($serial)) {
$mqttUser = new PluginFlyvemdmMqttuser();
Expand Down Expand Up @@ -878,6 +885,7 @@ protected function enrollByInvitationToken($input) {
$invitationToken = isset($input['_invitation_token']) ? $input['_invitation_token'] : null;
$email = isset($input['_email']) ? $input['_email'] : null;
$serial = isset($input['_serial']) ? $input['_serial'] : null;
$uuid = isset($input['_uuid']) ? $input['_uuid'] : null;
$csr = isset($input['csr']) ? $input['csr'] : null;
$firstname = isset($input['firstname']) ? $input['firstname'] : null;
$lastname = isset($input['lastname']) ? $input['lastname'] : null;
Expand All @@ -901,8 +909,8 @@ protected function enrollByInvitationToken($input) {
return false;
}

if (empty($serial)) {
$event = __('Serial missing', 'flyvemdm');
if (empty($serial) && empty($uuid)) {
$event = __('One of serial and uuid is mandatory', 'flyvemdm');
$this->filterMessages($event);
$this->logInvitationEvent($invitation, $event);
return false;
Expand Down Expand Up @@ -1042,7 +1050,8 @@ protected function enrollByInvitationToken($input) {
'name' => $email,
'users_id' => $userId,
'entities_id' => $entityId,
'serial' => $serial
'serial' => $serial,
'uuid' => $uuid,
));
if ($computerId === false) {
$event = __("Cannot create the device", 'flyvemdm');
Expand Down
10 changes: 4 additions & 6 deletions tests/0010_Integration/PluginFlyvemdmAgentIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,11 @@ public function testPurgeAgent() {
// Delete shall succeed
$this->assertTrue($agent->delete(['id' => $agentId]));

return $userId;
}
// Test the agent user is deleted
$agentUser = new User();
$this->assertFalse($agentUser->getFromDB($agent->getField('users_id')));

/**
* @depends testPurgeAgent
*/
public function testUserIsDeleted($userId) {
// Test the owner user is deleted
$user = new User();
$this->assertFalse($user->getFromDB($userId));
}
Expand Down

0 comments on commit 4d52514

Please sign in to comment.