Skip to content

Commit

Permalink
fix: import groups
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineLemarchand committed Oct 21, 2024
1 parent c274f49 commit b26c8bd
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b26c8bd

Please sign in to comment.