mirror of
https://github.com/moodle/moodle.git
synced 2025-08-09 19:06:41 +02:00
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
This commit is contained in:
parent
883ea035af
commit
c783a874f0
1 changed files with 17 additions and 0 deletions
|
@ -58,6 +58,23 @@ if (has_capability('moodle/user:loginas', $systemcontext)) {
|
||||||
print_error('usernotincourse');
|
print_error('usernotincourse');
|
||||||
}
|
}
|
||||||
$context = $coursecontext;
|
$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.
|
// Login as this user and return to course home page.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue