Skip to content

Commit

Permalink
MDL-42643 course: Member in same group should only loginas
Browse files Browse the repository at this point in the history
If course groupmode is set to SEPARATEGROUPS, and user doesn't have
site:accessallgroups capability than only allow user to loginas if
current user is in same group as loginas user
  • Loading branch information
Rajesh Taneja authored and danpoltawski committed Jan 7, 2014
1 parent a4720e0 commit 8b2dca7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions course/loginas.php
Expand Up @@ -60,6 +60,23 @@
print_error('usernotincourse');
}
$context = $coursecontext;

// Check if course has SEPARATEGROUPS and user is part of that group.
if (groups_get_course_groupmode($course) == SEPARATEGROUPS &&
!has_capability('moodle/site:accessallgroups', $context)) {
$samegroup = false;
if ($groups = groups_get_all_groups($course->id, $USER->id)) {
foreach ($groups as $group) {
if (groups_is_member($group->id, $userid)) {
$samegroup = true;
break;
}
}
}
if (!$samegroup) {
print_error('nologinas');
}
}
}

/// Login as this user and return to course home page.
Expand Down

0 comments on commit 8b2dca7

Please sign in to comment.