Skip to content

Commit

Permalink
MDL-57587 question file access: fix regression caused by MDL-53744
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Jan 26, 2017
1 parent 5130953 commit c28bfbe
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion question/type/gapselect/questionbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public function classify_response(array $response) {
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);
Expand Down
2 changes: 1 addition & 1 deletion question/type/match/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function check_file_access($qa, $options, $component, $filearea, $args, $

} 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);
Expand Down
2 changes: 1 addition & 1 deletion question/type/multichoice/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public abstract function is_choice_selected($response, $value);
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.
Expand Down
9 changes: 8 additions & 1 deletion question/type/questionbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,18 @@ public function get_right_answer_summary() {
* @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)) {
Expand Down
6 changes: 6 additions & 0 deletions question/type/upgrade.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c28bfbe

Please sign in to comment.