Skip to content

Commit

Permalink
update version file for auth_oidc bug fix in 3.9.2 release
Browse files Browse the repository at this point in the history
Add option to enable sync only on newly created courses

Add option to enable sync only on newly created courses
  • Loading branch information
weilai-irl committed Jan 7, 2021
1 parent 7a6b60d commit 20871b1
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 16 deletions.
2 changes: 1 addition & 1 deletion auth/oidc/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2020071501;
$plugin->version = 2020071502;
$plugin->requires = 2020061500;
$plugin->release = '3.9.2';
$plugin->component = 'auth_oidc';
Expand Down
16 changes: 11 additions & 5 deletions local/o365/classes/feature/usergroups/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,25 +605,31 @@ public static function delete_course_group($courseid) {
*
* @param int $courseid The ID of the course.
* @param bool $enabled Whether to enable or disable.
* @param bool $allfeatures Whether to enable all features, or just teams.
*/
public static function set_course_group_enabled($courseid, $enabled = true) {
public static function set_course_group_enabled($courseid, $enabled = true, $allfeatures = false) {
$usergroupconfig = get_config('local_o365', 'usergroupcustom');
$usergroupconfig = @json_decode($usergroupconfig, true);
if (empty($usergroupconfig) || !is_array($usergroupconfig)) {
$usergroupconfig = [];
}

if ($enabled === true) {
$usergroupconfig[$courseid] = $enabled;
static::set_course_group_feature_enabled($courseid, ['team'],
$enabled);
} else {
if (isset($usergroupconfig[$courseid])) {
unset($usergroupconfig[$courseid]);
static::delete_course_group($courseid);
}
static::set_course_group_feature_enabled($courseid, ['team'],
$enabled);
}

$features = ['team', 'onedrive', 'calendar', 'conversations', 'notebook'];
if ($allfeatures) {
static::set_course_group_feature_enabled($courseid, $features, $enabled);
} else {
static::set_course_group_feature_enabled($courseid, ['team'], $enabled);
}

set_config('usergroupcustom', json_encode($usergroupconfig), 'local_o365');
}

Expand Down
23 changes: 18 additions & 5 deletions local/o365/classes/observers.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,32 @@ public static function construct_sharepoint_api_with_system_user() {
* Handle course_created event.
*
* Does the following:
* - create a sharepoint site and associated groups.
* - enable sync on new courses if course sync is "custom", and the option to enable sync on new courses by default is set.
* - create a sharepoint site and associated groups.
*
* @param \core\event\course_created $event The triggered event.
* @return bool Success/Failure.
*/
public static function handle_course_created(\core\event\course_created $event) {
if (\local_o365\utils::is_configured() !== true || \local_o365\rest\sharepoint::is_configured() !== true) {
if (\local_o365\utils::is_configured() !== true) {
return false;
}
$sharepoint = static::construct_sharepoint_api_with_system_user();
if (!empty($sharepoint)) {
$sharepoint->create_course_site($event->objectid);

// Enable team sync for newly created courses if the create teams setting is "custom", and the option to enable sync on
// new courses by default is on.
$syncnewcoursesetting = get_config('local_o365', 'sync_new_course');
if ((get_config('local_o365', 'createteams') === 'oncustom') && $syncnewcoursesetting) {
\local_o365\feature\usergroups\utils::set_course_group_enabled($event->objectid, true, true);
}

if (\local_o365\rest\sharepoint::is_configured() === true) {
$sharepoint = static::construct_sharepoint_api_with_system_user();
if (!empty($sharepoint)) {
$sharepoint->create_course_site($event->objectid);
}
}

return true;
}

/**
Expand Down
21 changes: 18 additions & 3 deletions local/o365/classes/page/acp.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,14 @@ public function mode_usermatch() {
* Endpoint to change Teams customization.
*/
public function mode_usergroupcustom_change() {
$coursedata = json_decode(required_param('coursedata', PARAM_RAW), true);
require_sesskey();

// Save enabled by default on new course settings.
$enabledfornewcourse = required_param('newcourse', PARAM_BOOL);
set_config('sync_new_course', $enabledfornewcourse, 'local_o365');

// Save course settings.
$coursedata = json_decode(required_param('coursedata', PARAM_RAW), true);
foreach ($coursedata as $courseid => $course) {
if (!is_scalar($courseid) || ((string)$courseid !== (string)(int)$courseid)) {
// Non-intlike courseid value. Invalid. Skip.
Expand Down Expand Up @@ -524,7 +529,7 @@ public function mode_usergroupcustom_bulkchange() {
* Teams customization.
*/
public function mode_usergroupcustom() {
global $OUTPUT, $PAGE;
global $CFG, $OUTPUT, $PAGE;

$PAGE->navbar->add(get_string('acp_usergroupcustom', 'local_o365'), new \moodle_url($this->url, ['mode' => 'usergroupcustom']));

Expand Down Expand Up @@ -688,7 +693,10 @@ public function mode_usergroupcustom() {
$js .= ' // Send data to server. '."\n";
$js .= '$.ajax({
url: \''.$endpoint->out(false).'\',
data: {coursedata: JSON.stringify(coursedata)},
data: {
coursedata: JSON.stringify(coursedata),
newcourse: $("input#id_s_local_o365_sync_new_course").prop("checked"),
},
type: "POST",
success: function(data) {
console.log(data);
Expand All @@ -700,6 +708,13 @@ public function mode_usergroupcustom() {
echo \html_writer::script($js);
echo \html_writer::tag('h2', get_string('acp_usergroupcustom', 'local_o365'));

// Option to enable sync by default for new courses.
require_once($CFG->libdir . '/adminlib.php');
$enablefornewcourse = new \admin_setting_configcheckbox('local_o365/sync_new_course',
get_string('acp_usergroupcustom_new_course', 'local_o365'),
get_string('acp_usergroupcustom_new_course_desc', 'local_o365'), '0');
echo $enablefornewcourse->output_html(get_config('local_o365', 'sync_new_course'));

// Bulk Operations
$strbulkenable = get_string('acp_usergroupcustom_bulk_enable', 'local_o365');
$strbulkdisable = get_string('acp_usergroupcustom_bulk_disable', 'local_o365');
Expand Down
2 changes: 2 additions & 0 deletions local/o365/lang/en/local_o365.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
$string['acp_usergroupcustom_bulk'] = 'Bulk Operations';
$string['acp_usergroupcustom_bulk_enable'] = 'Enable All';
$string['acp_usergroupcustom_bulk_disable'] = 'Disable All';
$string['acp_usergroupcustom_new_course'] = 'Enabled by default for new course';
$string['acp_usergroupcustom_new_course_desc'] = 'If enabled, all newly created courses will have sync enabled by default';
$string['acp_maintenance_debugdata'] = 'Generate debug data package';
$string['acp_maintenance_debugdata_desc'] = 'This will generate a package containing various pieces of information about your Moodle and Office 365 environment to assist developers in solving any issues you may have. If requested by a developer, run this tool and send the resulting file download. Note: Although this package does not contain sensitive token data, we ask that you do not post this file publicly or send it to an untrusted party.';
$string['acp_usermatch'] = 'User Matching';
Expand Down
4 changes: 2 additions & 2 deletions local/office365/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2020071502;
$plugin->version = 2020071503;
$plugin->requires = 2020061500;
$plugin->release = '3.9.2';
$plugin->component = 'local_office365';
$plugin->maturity = MATURITY_STABLE;
$plugin->dependencies = [
'auth_oidc' => 2020071501,
'auth_oidc' => 2020071502,
'block_microsoft' => 2020071501,
'local_o365' => 2020071504,
'repository_office365' => 2020071502,
Expand Down

0 comments on commit 20871b1

Please sign in to comment.