diff --git a/inc/agent.class.php b/inc/agent.class.php index 9b7c0b9d..7d66a623 100644 --- a/inc/agent.class.php +++ b/inc/agent.class.php @@ -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 diff --git a/tests/suite-integration/PluginFlyvemdmAgent.php b/tests/suite-integration/PluginFlyvemdmAgent.php index ef95ec44..63e425e0 100644 --- a/tests/suite-integration/PluginFlyvemdmAgent.php +++ b/tests/suite-integration/PluginFlyvemdmAgent.php @@ -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( @@ -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(); } /** @@ -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(); @@ -644,12 +649,15 @@ 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 @@ -657,6 +665,7 @@ public function testPurgeAgent() { $invitation = $this->createInvitation($guestEmail); $user = new \User(); $user->getFromDB($invitation->getField(\User::getForeignKeyField())); + $testUserId = $user->getID(); // Enroll $serial = $this->getUniqueString(); @@ -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(); } /**