From b26c8bd39f6b611fb4d82ccb58e2e0b2bdddc0c2 Mon Sep 17 00:00:00 2001 From: Antoine Lemarchand Date: Mon, 21 Oct 2024 13:45:49 +0200 Subject: [PATCH] fix: import groups --- inc/config.class.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/inc/config.class.php b/inc/config.class.php index 9fb2bec..c6173a8 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -181,6 +181,19 @@ static function getUsersInGroup($group) { return self::request($url . "/api/v1/groups/" . $group . "/users", $key); } + static function getGroupsForUser($userId) { + $values = self::getConfigValues(); + $url = $values['url']; + $key = Toolbox::sodiumDecrypt($values['key']); + + $groups = self::request($url . "/api/v1/users/" . $userId . "/groups", $key); + $names= []; + foreach($groups as $group) { + $names[] = $group['profile']['name']; + } + return $names; + } + private static function createOrUpdateUser($userId) { global $DB; @@ -236,14 +249,12 @@ private static function createOrUpdateUser($userId) { $ID = $newUser->add($input); } + $userObject[$OidcMappings['group']] = self::getGroupsForUser($userId); Oidc::addUserData($userObject, $ID); return true; } static function importUser($userId, $groupId = null) { - global $DB; - - if ($userId <= 0) { $userList = self::getUsersInGroup($groupId); foreach ($userList as $user) {