From 35274646791693a6022d62217c5db62de6efa833 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Fri, 27 Jul 2007 05:43:05 +0000 Subject: [PATCH] when unassign users in course, if user has no more course:view capability left, he should be removed from all groups in course --- lib/accesslib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index 5a12b611fe5..0fa6664edb0 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2290,9 +2290,9 @@ function role_unassign($roleid=0, $userid=0, $groupid=0, $contextid=0, $enrol=NU /// now handle metacourse role unassigment and removing from goups if in course context if (!empty($context) and $context->contextlevel == CONTEXT_COURSE) { - //remove from groups when user has no role - $roles = get_user_roles($context, $ra->userid, true); - if (empty($roles)) { + // remove from groups when user has no capability to view course + // this may be slow, but this is the proper way of doing it + if (!has_capability('moodle/course:view', $context, $ra->userid)) { if ($groups = get_groups($context->instanceid, $ra->userid)) { foreach ($groups as $group) { delete_records('groups_members', 'groupid', $group->id, 'userid', $ra->userid);