MDL-20355 teachers may not see overview of all students in course because they might not have access in all their courses - please use profile instead; merged from MOODLE_19_STABLE

This commit is contained in:
skodak 2009-09-26 18:50:08 +00:00
parent 9c2d5353a8
commit 02b5087e14

View File

@ -30,10 +30,11 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
require_capability('gradereport/overview:view', $context);
if (empty($userid)) {
require_capability('moodle/grade:viewall', $context);
require_capability('moodle/grade:viewall', $systemcontext);
} else {
if (!$DB->get_record('user', array('id'=>$userid, 'deleted'=>0)) or isguestuser($userid)) {
@ -42,12 +43,16 @@ if (empty($userid)) {
}
$access = false;
if (has_capability('moodle/grade:viewall', $context)) {
if (has_capability('moodle/grade:viewall', $systemcontext)) {
//ok - can view all course grades
$access = true;
} else if ($userid == $USER->id and has_capability('moodle/grade:viewall', $context)) {
//ok - can view any own grades
$access = true;
} else if ($userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) {
//ok - can view own grades
//ok - can view own course grades
$access = true;
} else if (has_capability('moodle/grade:viewall', get_context_instance(CONTEXT_USER, $userid)) and $course->showgrades) {
@ -72,7 +77,8 @@ $USER->grade_last_report[$course->id] = 'overview';
//first make sure we have proper final grades - this must be done before constructing of the grade tree
grade_regrade_final_grades($courseid);
if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all student reports
if (has_capability('moodle/grade:viewall', $systemcontext)) { //Admins will see all student reports
// please note this would be extremely slow if we wanted to implement this properly for all teachers
$groupmode = groups_get_course_groupmode($course); // Groups are being used
$currentgroup = groups_get_course_group($course, true);
@ -122,7 +128,7 @@ if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all
}
}
}
} else { //Students will see just their own report
} else { //Non-admins will see just their own report
// Create a report instance
$report = new grade_report_overview($userid, $gpr, $context);
@ -137,4 +143,4 @@ if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all
echo $OUTPUT->footer();
?>