diff --git a/mod/assignment/type/upload/assignment.class.php b/mod/assignment/type/upload/assignment.class.php index 6e24785c809..f6844498021 100644 --- a/mod/assignment/type/upload/assignment.class.php +++ b/mod/assignment/type/upload/assignment.class.php @@ -102,29 +102,44 @@ class assignment_upload extends assignment_base { function view_feedback($submission=NULL) { - global $USER, $CFG, $DB, $OUTPUT; + global $USER, $CFG, $DB, $OUTPUT, $PAGE; require_once($CFG->libdir.'/gradelib.php'); + require_once("$CFG->dirroot/grade/grading/lib.php"); if (!$submission) { /// Get submission for this assignment - $submission = $this->get_submission($USER->id); + $userid = $USER->id; + $submission = $this->get_submission($userid); + } else { + $userid = $submission->userid; } if (empty($submission->timemarked)) { /// Nothing to show, so print nothing return; } + // Check the user can submit + $canviewfeedback = ($userid == $USER->id && has_capability('mod/assignment:submit', $this->context, $USER->id, false)); + // If not then check if the user still has the view cap and has a previous submission + $canviewfeedback = $canviewfeedback || (!empty($submission) && $submission->userid == $USER->id && has_capability('mod/assignment:view', $this->context)); + // Or if user can grade (is a teacher or admin) + $canviewfeedback = $canviewfeedback || has_capability('mod/assignment:grade', $this->context); - $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $USER->id); + if (!$canviewfeedback) { + // can not view or submit assignments -> no feedback + return; + } + + $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid); $item = $grading_info->items[0]; - $grade = $item->grades[$USER->id]; + $grade = $item->grades[$userid]; if ($grade->hidden or $grade->grade === false) { // hidden or error return; } if ($grade->grade === null and empty($grade->str_feedback)) { // No grade to show yet - if ($this->count_responsefiles($USER->id)) { // but possibly response files are present + if ($this->count_responsefiles($userid)) { // but possibly response files are present echo $OUTPUT->heading(get_string('responsefiles', 'assignment'), 3); - $responsefiles = $this->print_responsefiles($USER->id, true); + $responsefiles = $this->print_responsefiles($userid, true); echo $OUTPUT->box($responsefiles, 'generalbox boxaligncenter'); } return; @@ -158,12 +173,14 @@ class assignment_upload extends assignment_base { echo '