Permalink
Browse files

MDL-42643 course: Member in same group should only loginas

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...
1 parent a4720e0 commit 8b2dca7427ae36eb1b3cdbc867462c5d1d28cbeb @rajeshtaneja rajeshtaneja committed with danpoltawski Nov 20, 2013
Showing with 17 additions and 0 deletions.
  1. +17 −0 course/loginas.php
View
@@ -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.

0 comments on commit 8b2dca7

Please sign in to comment.