mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
MDL-50996 quiz: fix review error with unusual permissions
This commit is contained in:
parent
6d392b3027
commit
857e2a6f8c
3 changed files with 27 additions and 11 deletions
|
@ -788,16 +788,13 @@ class quiz_attempt {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this a student dealing with their own attempt/teacher previewing,
|
* Is this someone dealing with their own attempt or preview?
|
||||||
* or someone with 'mod/quiz:viewreports' reviewing someone elses attempt.
|
|
||||||
*
|
*
|
||||||
* @return bool whether this situation should be treated as someone looking at their own
|
* @return bool true => own attempt/preview. false => reviewing someone elses.
|
||||||
* attempt. The distinction normally only matters when an attempt is being reviewed.
|
|
||||||
*/
|
*/
|
||||||
public function is_own_attempt() {
|
public function is_own_attempt() {
|
||||||
global $USER;
|
global $USER;
|
||||||
return $this->attempt->userid == $USER->id &&
|
return $this->attempt->userid == $USER->id;
|
||||||
(!$this->is_preview_user() || $this->attempt->preview);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -805,7 +802,7 @@ class quiz_attempt {
|
||||||
*/
|
*/
|
||||||
public function is_own_preview() {
|
public function is_own_preview() {
|
||||||
global $USER;
|
global $USER;
|
||||||
return $this->attempt->userid == $USER->id &&
|
return $this->is_own_attempt() &&
|
||||||
$this->is_preview_user() && $this->attempt->preview;
|
$this->is_preview_user() && $this->attempt->preview;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -961,6 +958,11 @@ class quiz_attempt {
|
||||||
if (is_null($this->reviewoptions)) {
|
if (is_null($this->reviewoptions)) {
|
||||||
$this->reviewoptions = quiz_get_review_options($this->get_quiz(),
|
$this->reviewoptions = quiz_get_review_options($this->get_quiz(),
|
||||||
$this->attempt, $this->quizobj->get_context());
|
$this->attempt, $this->quizobj->get_context());
|
||||||
|
if ($this->is_own_preview()) {
|
||||||
|
// It should always be possible for a teacher to review their
|
||||||
|
// own preview irrespective of the review options settings.
|
||||||
|
$this->reviewoptions->attempt = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this->reviewoptions;
|
return $this->reviewoptions;
|
||||||
|
|
||||||
|
@ -1569,7 +1571,19 @@ class quiz_attempt {
|
||||||
*/
|
*/
|
||||||
public function check_file_access($slot, $reviewing, $contextid, $component,
|
public function check_file_access($slot, $reviewing, $contextid, $component,
|
||||||
$filearea, $args, $forcedownload) {
|
$filearea, $args, $forcedownload) {
|
||||||
return $this->quba->check_file_access($slot, $this->get_display_options($reviewing),
|
$options = $this->get_display_options($reviewing);
|
||||||
|
|
||||||
|
// Check permissions - warning there is similar code in review.php and
|
||||||
|
// reviewquestion.php. If you change on, change them all.
|
||||||
|
if ($reviewing && $this->is_own_attempt() && !$options->attempt) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($reviewing && !$this->is_own_attempt() && !$this->is_review_allowed()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->quba->check_file_access($slot, $options,
|
||||||
$component, $filearea, $args, $forcedownload);
|
$component, $filearea, $args, $forcedownload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,8 @@ $accessmanager->setup_attempt_page($PAGE);
|
||||||
|
|
||||||
$options = $attemptobj->get_display_options(true);
|
$options = $attemptobj->get_display_options(true);
|
||||||
|
|
||||||
// Check permissions.
|
// Check permissions - warning there is similar code in reviewquestion.php and
|
||||||
|
// quiz_attempt::check_file_access. If you change on, change them all.
|
||||||
if ($attemptobj->is_own_attempt()) {
|
if ($attemptobj->is_own_attempt()) {
|
||||||
if (!$attemptobj->is_finished()) {
|
if (!$attemptobj->is_finished()) {
|
||||||
redirect($attemptobj->attempt_url(null, $page));
|
redirect($attemptobj->attempt_url(null, $page));
|
||||||
|
@ -91,7 +92,7 @@ if ($options->flags == question_display_options::EDITABLE && optional_param('sav
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work out appropriate title and whether blocks should be shown.
|
// Work out appropriate title and whether blocks should be shown.
|
||||||
if ($attemptobj->is_preview_user() && $attemptobj->is_own_attempt()) {
|
if ($attemptobj->is_own_preview()) {
|
||||||
$strreviewtitle = get_string('reviewofpreview', 'quiz');
|
$strreviewtitle = get_string('reviewofpreview', 'quiz');
|
||||||
navigation_node::override_active_url($attemptobj->start_attempt_url());
|
navigation_node::override_active_url($attemptobj->start_attempt_url());
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,8 @@ $PAGE->set_pagelayout('popup');
|
||||||
$PAGE->set_heading($attemptobj->get_course()->fullname);
|
$PAGE->set_heading($attemptobj->get_course()->fullname);
|
||||||
$output = $PAGE->get_renderer('mod_quiz');
|
$output = $PAGE->get_renderer('mod_quiz');
|
||||||
|
|
||||||
// Check permissions.
|
// Check permissions - warning there is similar code in review.php and
|
||||||
|
// quiz_attempt::check_file_access. If you change on, change them all.
|
||||||
if ($attemptobj->is_own_attempt()) {
|
if ($attemptobj->is_own_attempt()) {
|
||||||
if (!$attemptobj->is_finished()) {
|
if (!$attemptobj->is_finished()) {
|
||||||
echo $output->review_question_not_allowed(get_string('cannotreviewopen', 'quiz'));
|
echo $output->review_question_not_allowed(get_string('cannotreviewopen', 'quiz'));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue