diff --git a/mod/quiz/report/attemptsreport_options.php b/mod/quiz/report/attemptsreport_options.php
index cca3d30465d..ffd4287cc18 100644
--- a/mod/quiz/report/attemptsreport_options.php
+++ b/mod/quiz/report/attemptsreport_options.php
@@ -105,7 +105,7 @@ class mod_quiz_attempts_report_options {
         $this->cm     = $cm;
         $this->course = $course;
 
-        $this->usercanseegrades = quiz_report_should_show_grades($quiz);
+        $this->usercanseegrades = quiz_report_should_show_grades($quiz, context_module::instance($cm->id));
     }
 
     /**
diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php
index 9bfa402fad3..d3e4e998d14 100644
--- a/mod/quiz/report/reportlib.php
+++ b/mod/quiz/report/reportlib.php
@@ -401,9 +401,10 @@ function quiz_no_questions_message($quiz, $cm, $context) {
  * Should the grades be displayed in this report. That depends on the quiz
  * display options, and whether the quiz is graded.
  * @param object $quiz the quiz settings.
+ * @param context $context the quiz context.
  * @return bool
  */
-function quiz_report_should_show_grades($quiz) {
+function quiz_report_should_show_grades($quiz, context $context) {
     if ($quiz->timeclose && time() > $quiz->timeclose) {
         $when = mod_quiz_display_options::AFTER_CLOSE;
     } else {
@@ -413,5 +414,5 @@ function quiz_report_should_show_grades($quiz) {
 
     return quiz_has_grades($quiz) &&
             ($reviewoptions->marks >= question_display_options::MARK_AND_MAX ||
-            has_capability('moodle/grade:viewhidden', $this->context));
+            has_capability('moodle/grade:viewhidden', $context));
 }