From 15f2ba913de161d1ecb7658ba010cf5f9a5e4267 Mon Sep 17 00:00:00 2001 From: Antoine Lemarchand Date: Wed, 18 Dec 2024 15:44:23 +0100 Subject: [PATCH] feat: deactivate non imported users --- inc/config.class.php | 60 ++++++++++++++++++++++++++++++++------------ setup.php | 2 +- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/inc/config.class.php b/inc/config.class.php index dedc06b..606545e 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -75,6 +75,7 @@ static function install() { ('use_group_regex', '0'), ('group_regex', ''), ('full_import', '0'), + ('deactivate', '0'), ('use_norm_id', '0'), ('use_norm_name', '0'), ('use_norm_given_name', '0'), @@ -148,6 +149,12 @@ static function install() { ('filter_family_name', ''), ('filter_email', ''), ('filter_phone_number', '') +SQL; + $DB->queryOrDie($query, $DB->error()); + } else if (PLUGIN_OKTA_VERSION == "1.6.0") { + $query = <<queryOrDie($query, $DB->error()); } @@ -356,6 +363,8 @@ private static function createOrUpdateUser($user, $config, $fullImport = false) } static function importUser($authorizedGroups, $fullImport = false, $userId = NULL) { + global $DB; + $importedUsers = []; $config = self::getConfigValues(); if (!$userId) { @@ -385,6 +394,20 @@ static function importUser($authorizedGroups, $fullImport = false, $userId = NUL $importedUsers[] = $importedUser; } } + if ($config['deactivate'] == 1) { + $users = iterator_to_array($DB->request([ + 'SELECT' => ['id'], + 'FROM' => 'glpi_users', + ])); + $importedIds = array_map(function($user) { + return $user['id']; + }, $importedUsers); + foreach ($users as $user) { + if (!in_array($user['id'], $importedIds)) { + $DB->updateOrDie('glpi_users', ['is_active' => 0], ['id' => $user['id']]); + } + } + } } else { $userObject = self::request("api/v1/users/{$userId}"); $user = $userObject['profile']; @@ -541,10 +564,15 @@ public function showConfigForm() { - + > + + + + > + @@ -591,22 +619,22 @@ public function showConfigForm() { $(function() { $('#user').select2({width: '100%'}); }) - document.getElementById('group').addEventListener('change', function() { - var group = this.querySelector('option:checked').getAttribute('data-gid'); - var user = document.getElementById('user'); - user.innerHTML = ''; - // add loading animation - user.innerHTML = ''; - fetch('?action=getUsers&group=' + group) - .then(response => response.json()) - .then(data => { - $("#user").html(''); - $("#user").append(''); - for (const [key, value] of Object.entries(data)) { - $("#user").append(''); - } - }); + document.getElementById('group').addEventListener('change', function() { + var group = this.querySelector('option:checked').getAttribute('data-gid'); + var user = document.getElementById('user'); + user.innerHTML = ''; + // add loading animation + user.innerHTML = ''; + fetch('?action=getUsers&group=' + group) + .then(response => response.json()) + .then(data => { + $("#user").html(''); + $("#user").append(''); + for (const [key, value] of Object.entries(data)) { + $("#user").append(''); + } }); + }); document.getElementById('regex_group_checkbox').addEventListener('change', function() { const value = this.checked; const dropdown = document.getElementById('group'); diff --git a/setup.php b/setup.php index eb82989..d576f0a 100644 --- a/setup.php +++ b/setup.php @@ -30,7 +30,7 @@ * --------------------------------------------------------------------- */ -define('PLUGIN_OKTA_VERSION', '1.5.0'); +define('PLUGIN_OKTA_VERSION', '1.6.0'); if (!defined("PLUGIN_OKTA_DIR")) { define("PLUGIN_OKTA_DIR", Plugin::getPhpDir("okta"));