From 7312083c6fb425111fd88876823c00e1abde7367 Mon Sep 17 00:00:00 2001 From: Patryk Mroczko Date: Fri, 5 Jun 2026 15:00:20 +0200 Subject: [PATCH] Add option to exclude group owners from cohort sync --- local/o365/classes/feature/cohortsync/main.php | 4 +++- local/o365/lang/en/local_o365.php | 2 ++ local/o365/settings.php | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/local/o365/classes/feature/cohortsync/main.php b/local/o365/classes/feature/cohortsync/main.php index 39c3e4314..ef6263596 100644 --- a/local/o365/classes/feature/cohortsync/main.php +++ b/local/o365/classes/feature/cohortsync/main.php @@ -274,9 +274,11 @@ public function get_group_owners_and_members(string $groupoid) { return false; } + $excludeowners = (bool) get_config('local_o365', 'cohortsync_excludeowners'); + try { $memberrecords = $this->graphclient->get_transitive_group_members($groupoid); - $ownerrecords = $this->graphclient->get_group_owners($groupoid); + $ownerrecords = $excludeowners ? [] : $this->graphclient->get_group_owners($groupoid); } catch (moodle_exception $e) { if (strpos($e->getMessage(), utils::RESOURCE_NOT_EXIST_ERROR) !== false) { $DB->delete_records('local_o365_objects', ['objectid' => $groupoid]); diff --git a/local/o365/lang/en/local_o365.php b/local/o365/lang/en/local_o365.php index 304632272..0d9b7779f 100644 --- a/local/o365/lang/en/local_o365.php +++ b/local/o365/lang/en/local_o365.php @@ -370,6 +370,8 @@ $string['settings_cohortsync_linktext'] = 'Manage Cohort sync'; $string['settings_cohortsync_details'] = 'Review and manage synchronization between Moodle Cohorts and Microsoft Groups.'; $string['settings_cohortsync_title'] = 'Cohort sync'; +$string['settings_cohortsync_excludeowners'] = 'Exclude group owners from cohort sync'; +$string['settings_cohortsync_excludeowners_desc'] = 'When enabled, only group members are synchronised to Moodle cohorts. Group owners are excluded. Existing cohort members who are owners will be removed on the next sync run.'; // Settings in the "Team / group names" section of the "Sync settings" tab. $string['settings_secthead_team_group_name'] = 'Team / group names'; diff --git a/local/o365/settings.php b/local/o365/settings.php index 9b6816b1f..90604d32a 100644 --- a/local/o365/settings.php +++ b/local/o365/settings.php @@ -473,6 +473,10 @@ $desc )); + $label = new lang_string('settings_cohortsync_excludeowners', 'local_o365'); + $desc = new lang_string('settings_cohortsync_excludeowners_desc', 'local_o365'); + $syncsettings->add(new admin_setting_configcheckbox('local_o365/cohortsync_excludeowners', $label, $desc, '0')); + // Course request section. $label = new lang_string('settings_secthead_course_request', 'local_o365'); $desc = new lang_string('settings_secthead_course_request_desc', 'local_o365');