diff --git a/auth/cas/auth.php b/auth/cas/auth.php index d94c3965..4c40f683 100644 --- a/auth/cas/auth.php +++ b/auth/cas/auth.php @@ -240,6 +240,32 @@ class auth_plugin_cas extends auth_plugin_ldap { return null; } + /** + * FIXME: migrate to the new Moodle 3.5 auth_cas + * + * Sync roles for this user. + * + * @param object $user The user to sync (without system magic quotes). + */ + function sync_roles($user) { + $iscreator = $this->iscreator($user->username); + if ($iscreator === null) { + return; // Nothing to sync - creators not configured + } + + if ($roles = get_archetype_roles('coursecreator')) { + $creatorrole = array_shift($roles); // We can only use one, let's use the first one + $systemcontext = context_system::instance(); + + if ($iscreator) { // Following calls will not create duplicates + role_assign($creatorrole->id, $user->id, $systemcontext->id, $this->roleauth); + } else { + // Unassign only if previously assigned by this plugin! + role_unassign($creatorrole->id, $user->id, $systemcontext->id, $this->roleauth); + } + } + } + /** * Returns true if user should be coursecreator. *