]> git.mjollnir.org Git - moodle.git/commitdiff
when unassign users in course, if user has no more course:view capability left, he...
authortoyomoyo <toyomoyo>
Fri, 27 Jul 2007 05:43:05 +0000 (05:43 +0000)
committertoyomoyo <toyomoyo>
Fri, 27 Jul 2007 05:43:05 +0000 (05:43 +0000)
lib/accesslib.php

index 5a12b611fe5af9e7a449c3b6af31521e136a178d..0fa6664edb0fa58cd9dd1a8a2c1c9646b8a115e6 100755 (executable)
@@ -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);