MDL-85653 qbank_editquestion: Display static status when not editable

This commit is contained in:
Mark Johnson
2026-01-14 15:41:39 +00:00
parent 774796cf77
commit 42cb48db5c
3 changed files with 33 additions and 2 deletions
@@ -92,12 +92,16 @@ class editquestion_helper {
/**
* Get the array of status of the questions.
*
* @param bool $includehidden Include QUESTION_STATUS_HIDDEN in the returned list?
* @return array
*/
public static function get_question_status_list(): array {
public static function get_question_status_list(bool $includehidden = false): array {
$statuslist = [];
$statuslist[question_version_status::QUESTION_STATUS_READY] = get_string('questionstatusready', 'qbank_editquestion');
$statuslist[question_version_status::QUESTION_STATUS_DRAFT] = get_string('questionstatusdraft', 'qbank_editquestion');
if ($includehidden) {
$statuslist[question_version_status::QUESTION_STATUS_HIDDEN] = get_string('questionstatushidden', 'qbank_editquestion');
}
return $statuslist;
}
@@ -39,7 +39,6 @@ class question_status_column extends column_base {
protected function display_content($question, $rowclasses): void {
global $PAGE;
$attributes = [];
if (question_has_capability_on($question, 'edit')
&& $question->status !== question_version_status::QUESTION_STATUS_HIDDEN) {
$options = [];
@@ -54,6 +53,9 @@ class question_status_column extends column_base {
}
echo $PAGE->get_renderer('qbank_editquestion')->render_status_dropdown($options);
$PAGE->requires->js_call_amd('qbank_editquestion/question_status', 'init', [$question->id]);
} else {
$statuslist = editquestion_helper::get_question_status_list(true);
echo $statuslist[$question->status];
}
}
@@ -33,3 +33,28 @@ Feature: Use the qbank base view to test the status change using
And I reload the page
And the field "question_status_dropdown" in the "First question" "table_row" matches value "Ready"
And the field "question_status_dropdown" in the "Second question" "table_row" matches value "Draft"
@javascript
Scenario: Non-editing users see a static output of the status
Given the following "users" exist:
| username | firstname | lastname |
| teacher1 | Teacher | 1 |
And the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| moodle/question:editall | Prevent | editingteacher | System | |
And the following "course enrolments" exist:
| course | user | role |
| C1 | teacher1 | editingteacher |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext | status |
| Test questions | truefalse | Third question | Answer the first question | draft |
| Test questions | truefalse | Fourth question | Answer the first question | hidden |
When I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1"
And I apply question bank filter "Category" with value "Test questions"
And I apply question bank filter "Show hidden questions" with value "Yes"
Then I should see "Test questions"
And "question_status_dropdown" "field" should not exist
And I should see "Ready" in the "First question" "table_row"
And I should see "Ready" in the "Second question" "table_row"
And I should see "Draft" in the "Third question" "table_row"
And I should see "Hidden" in the "Fourth question" "table_row"