-
Notifications
You must be signed in to change notification settings - Fork 149
Description
We noticed that on our course syncing cron, the Teams groups were being created with "description" as name instead of the actual course name:

When looking at the plugin files we came upon this piece of code:
file: https://github.com/microsoft/o365-moodle/blob/master/local/o365/classes/rest/unified.php
$groupdata = [
'groupTypes' => ['Unified'],
'displayName' => $name,
'mailEnabled' => false,
'securityEnabled' => false,
'mailNickname' => $mailnickname,
'visibility' => 'Private',
'resourceBehaviorOptions' => ['HideGroupInOutlook', 'WelcomeEmailDisabled'],
];
if (!empty($extra)) {
// Set extra parameters.
foreach ($extra as $name => $value) {
$groupdata[$name] = $value;
}
}
// Description cannot be set and empty.
if (empty($groupdata['description'])) {
unset($groupdata['description']);
}
$response = $this->apicall('post', '/groups', json_encode($groupdata));
$expectedparams = ['id' => null];
try {
$response = $this->process_apicall_response($response, $expectedparams);
} catch (Exception $e) {
$expectedexception = 'Another object with the same value for property mailNickname already exists.';
if ($e->a == $expectedexception) {
$mailnickname .= '_ ' . sprintf('%04d', random_int(0, 9999));
return $this->create_group($name, $mailnickname, $extra);
} else {
utils::debug($e->getMessage(), __METHOD__, $e);
throw $e;
}
The variable $name stores the name of the course, which is used on the $groupdata in the line 329: 'displayName' => $name,. But, the foreach method on line 339: foreach ($extra as $name => $value) changes the value of the $name variable. At first this isn't a problem, but whenever a course being synced falls in the if on line 355: if ($e->a == $expectedexception) it calls the method create_group again, sending the $name variable as one of the parameters of the method, but now it's value is 'description' (or any other key that may be present on the mentioned foreach) instead of the original value which was the Course name, thus resulting in the Teams groups being created incorrectly.
Is there any way this can be fixed?