From abbb55eadf24fa2a97fcb2e048f6eab02eae27b0 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Fri, 1 Apr 2022 15:24:16 +1100 Subject: [PATCH] MDL-74302 mod_quiz: Users with preview cap should see prevent messages --- mod/quiz/tests/behat/preview.feature | 1 + mod/quiz/view.php | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mod/quiz/tests/behat/preview.feature b/mod/quiz/tests/behat/preview.feature index 4616e22c2b3..2ada3f291e6 100644 --- a/mod/quiz/tests/behat/preview.feature +++ b/mod/quiz/tests/behat/preview.feature @@ -69,6 +69,7 @@ Feature: Preview a quiz as a teacher | TF1 | 1 | | | TF2 | 1 | 3.0 | When I am on the "Quiz 2" "mod_quiz > View" page logged in as "admin" + And I should see "This quiz is not currently available" And I press "Preview quiz" Then I should see "if this were a real attempt, you would be blocked" in the ".alert-warning" "css_element" diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 6cf361c6296..fd43e720f63 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -229,14 +229,18 @@ if (!$viewobj->quizhasquestions) { } } - // If this is not a preview and, so far, we think a button should be printed, so check if they will be - // allowed to access it. - if (!$canpreview && $viewobj->buttontext) { + // Users who can preview the quiz should be able to see all messages for not being able to access the quiz. + if ($canpreview) { + $viewobj->preventmessages = $viewobj->accessmanager->prevent_access(); + } else if ($viewobj->buttontext) { + // If, so far, we think a button should be printed, so check if they will be allowed to access it. if (!$viewobj->moreattempts) { $viewobj->buttontext = ''; - } else if ($canattempt - && $viewobj->preventmessages = $viewobj->accessmanager->prevent_access()) { - $viewobj->buttontext = ''; + } else if ($canattempt) { + $viewobj->preventmessages = $viewobj->accessmanager->prevent_access(); + if ($viewobj->preventmessages) { + $viewobj->buttontext = ''; + } } } }