From c28bfbef24cf61fc8710e89ed0e0944707191f6c Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 26 Jan 2017 18:53:16 +0000 Subject: [PATCH] MDL-57587 question file access: fix regression caused by MDL-53744 --- question/type/gapselect/questionbase.php | 2 +- question/type/match/question.php | 2 +- question/type/multichoice/question.php | 2 +- question/type/questionbase.php | 9 ++++++++- question/type/upgrade.txt | 6 ++++++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/question/type/gapselect/questionbase.php b/question/type/gapselect/questionbase.php index 180a448f542..76a3882a87b 100644 --- a/question/type/gapselect/questionbase.php +++ b/question/type/gapselect/questionbase.php @@ -321,7 +321,7 @@ abstract class qtype_gapselect_question_base extends question_graded_automatical public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) { if ($component == 'question' && in_array($filearea, array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'))) { - return $this->check_combined_feedback_file_access($qa, $options, $filearea); + return $this->check_combined_feedback_file_access($qa, $options, $filearea, $args); } else if ($component == 'question' && $filearea == 'hint') { return $this->check_hint_file_access($qa, $options, $args); diff --git a/question/type/match/question.php b/question/type/match/question.php index b373fba6cd2..41130100daf 100644 --- a/question/type/match/question.php +++ b/question/type/match/question.php @@ -342,7 +342,7 @@ class qtype_match_question extends question_graded_automatically_with_countback } else if ($component == 'question' && in_array($filearea, array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'))) { - return $this->check_combined_feedback_file_access($qa, $options, $filearea); + return $this->check_combined_feedback_file_access($qa, $options, $filearea, $args); } else if ($component == 'question' && $filearea == 'hint') { return $this->check_hint_file_access($qa, $options, $args); diff --git a/question/type/multichoice/question.php b/question/type/multichoice/question.php index 2c5e17cdbab..09b949355c4 100644 --- a/question/type/multichoice/question.php +++ b/question/type/multichoice/question.php @@ -113,7 +113,7 @@ abstract class qtype_multichoice_base extends question_graded_automatically { public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) { if ($component == 'question' && in_array($filearea, array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'))) { - return $this->check_combined_feedback_file_access($qa, $options, $filearea); + return $this->check_combined_feedback_file_access($qa, $options, $filearea, $args); } else if ($component == 'question' && $filearea == 'answer') { $answerid = reset($args); // Itemid is answer id. diff --git a/question/type/questionbase.php b/question/type/questionbase.php index 879381e91dc..b6a4b8972ae 100644 --- a/question/type/questionbase.php +++ b/question/type/questionbase.php @@ -668,11 +668,18 @@ abstract class question_graded_automatically extends question_with_responses * @param question_attempt $qa the question attempt being displayed. * @param question_display_options $options the options that control display of the question. * @param string $filearea the name of the file area. + * @param array $args the remaining bits of the file path. * @return bool whether access to the file should be allowed. */ - protected function check_combined_feedback_file_access($qa, $options, $filearea) { + protected function check_combined_feedback_file_access($qa, $options, $filearea, $args = null) { $state = $qa->get_state(); + if ($args === null) { + debugging('You must pass $args as the fourth argument to check_combined_feedback_file_access.', + DEBUG_DEVELOPER); + $args = array($this->id); // Fake it for now, so the rest of this method works. + } + if (!$state->is_finished()) { $response = $qa->get_last_qt_data(); if (!$this->is_gradable_response($response)) { diff --git a/question/type/upgrade.txt b/question/type/upgrade.txt index 470629c4b26..6a74061f0d1 100644 --- a/question/type/upgrade.txt +++ b/question/type/upgrade.txt @@ -1,5 +1,11 @@ This files describes API changes for question type plugins. +=== 3.1.5, 3.2.2, 3.3 === + +* If you are using check_combined_feedback_file_access in your check_file_access method, + then you must now pass $args as the 4th argument, so the correct permission checks + can be performed. If you don't, you will get a developer debug notice. + === 3.1 === * The following functions, previously used (exclusively) by upgrade steps are not available -- 2.43.0