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

Commit

Permalink
fix: User hasn't to be deleted when no computers left
Browse files Browse the repository at this point in the history
  • Loading branch information
DIOHz0r authored and btry committed Sep 6, 2017
1 parent 0984273 commit 2ef3ffb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 0 additions & 8 deletions inc/agent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,6 @@ public function pre_deleteItem() {
Session::addMessageAfterRedirect(__('Failed to remove guest habilitation for the user of the device', 'flyvemdm'));
return false;
}

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

// Delete the user account of the agent
Expand Down
16 changes: 14 additions & 2 deletions tests/suite-integration/PluginFlyvemdmAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ public function testDelete() {
$invitation = $this->createInvitation($guestEmail);
$user = new \User();
$user->getFromDB($invitation->getField(\User::getForeignKeyField()));
$testUserId = $user->getID();

// Enroll
$agent = $this->enrollFromInvitation(
Expand Down Expand Up @@ -509,6 +510,9 @@ public function testDelete() {

// check the agent is deleted
$this->boolean($deleteSuccess)->isTrue();

// Check if user has not been deleted
$this->boolean($user->getFromDb($testUserId))->isTrue();
}

/**
Expand Down Expand Up @@ -610,6 +614,7 @@ public function testPurgeEnroledAgent() {
$invitation = $this->createInvitation($guestEmail);
$user = new \User();
$user->getFromDB($invitation->getField(\User::getForeignKeyField()));
$testUserId = $user->getID();

// Enroll
$serial = $this->getUniqueString();
Expand Down Expand Up @@ -644,19 +649,23 @@ public function testPurgeEnroledAgent() {
$this->boolean($mqttUser->getByUser($serial))->isFalse();
$computer = new \Computer();
$this->boolean($computer->getFromDB($computerId))->isFalse();

// Check if user has not been deleted
$this->boolean($user->getFromDb($testUserId))->isTrue();
}

/**
* Test the purge of an agent deletes the user if he no longer has any agent
*
* Test the purge of an agent the user must persist if he no longer has any agent
*
* @tags purgeAgent
*/
public function testPurgeAgent() {
// Create an invitation
$guestEmail = $this->getUniqueEmail();
$invitation = $this->createInvitation($guestEmail);
$user = new \User();
$user->getFromDB($invitation->getField(\User::getForeignKeyField()));
$testUserId = $user->getID();

// Enroll
$serial = $this->getUniqueString();
Expand Down Expand Up @@ -696,6 +705,9 @@ public function testPurgeAgent() {
// Test the owner user is deleted
$user = new \User();
$this->boolean($user->getFromDB($userId))->isFalse();

// Check if user has not been deleted
$this->boolean($user->getFromDb($testUserId))->isTrue();
}

/**
Expand Down

0 comments on commit 2ef3ffb

Please sign in to comment.