Browse files

MDL-10256, when user is unassigned a role in course, if user has no c…

…ourse:view, user will be removed from all groups in course
  • Loading branch information...
1 parent 3fcf436 commit 50ae935fd60a0ccbe693c119bd5a73358d5bb109 toyomoyo committed Jul 27, 2007
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/accesslib.php
@@ -2292,9 +2292,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);

0 comments on commit 50ae935

Please sign in to comment.