From b55da1c7d9b84ea02e53030c501f4951d24f921f Mon Sep 17 00:00:00 2001 From: DangHieu1407 Date: Thu, 30 Nov 2023 11:18:24 +0700 Subject: [PATCH] StudentQuiz: separate out changestate management #727398 from general delete/edit management --- changestate.php | 1 - renderer.php | 32 +++++++++++++++------------- tests/behat/state_visibility.feature | 3 +-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/changestate.php b/changestate.php index 506fb87b..c050e235 100644 --- a/changestate.php +++ b/changestate.php @@ -111,7 +111,6 @@ if (preg_match('!^q([0-9]+)$!', $key, $matches)) { $key = $matches[1]; $questionlist .= $key.','; - question_require_capability_on((int)$key, 'edit'); $question = new stdClass(); $question->name = ''; if (questions_in_use([$key])) { diff --git a/renderer.php b/renderer.php index 8fb1e426..55cefe20 100755 --- a/renderer.php +++ b/renderer.php @@ -1238,22 +1238,24 @@ public function render_control_buttons($catcontext, $hasquestionincategory, $add $output .= html_writer::empty_tag('input', $params); } + + if (has_capability('mod/studentquiz:changestate', $this->page->context)) { + $output .= html_writer::empty_tag('input', [ + 'class' => 'btn btn-secondary', + 'type' => 'submit', + 'name' => 'approveselected', + 'formaction' => $changestateurl, + 'value' => get_string('state_toggle', 'studentquiz'), + 'form' => 'questionsubmit', + 'data-action' => 'toggle', + 'data-togglegroup' => 'qbank', + 'data-toggle' => 'action', + 'disabled' => true, + 'formmethod' => 'post', + ]); + } + if ($caneditall) { - if (has_capability('mod/studentquiz:changestate', $this->page->context)) { - $output .= html_writer::empty_tag('input', [ - 'class' => 'btn btn-secondary', - 'type' => 'submit', - 'name' => 'approveselected', - 'formaction' => $changestateurl, - 'value' => get_string('state_toggle', 'studentquiz'), - 'form' => 'questionsubmit', - 'data-action' => 'toggle', - 'data-togglegroup' => 'qbank', - 'data-toggle' => 'action', - 'disabled' => true, - 'formmethod' => 'post', - ]); - } $output .= html_writer::empty_tag('input', [ 'class' => 'btn btn-secondary', 'type' => 'submit', diff --git a/tests/behat/state_visibility.feature b/tests/behat/state_visibility.feature index 34813781..7736bb89 100644 --- a/tests/behat/state_visibility.feature +++ b/tests/behat/state_visibility.feature @@ -270,11 +270,10 @@ Feature: Question states and visibility And I should see "This question cannot be deleted because it has been approved." @javascript - Scenario: The teacher have the 'changestate' capability. + Scenario: A non-editing teacher only needs the changestate capability to approve questions. Given the following "permission overrides" exist: | capability | permission | role | contextlevel | reference | | mod/studentquiz:changestate | Allow | teacher | Course | C1 | - | mod/studentquiz:manage | Allow | teacher | Course | C1 | When I am on the "StudentQuiz Test 1" "mod_studentquiz > View" page logged in as "teacher1" And I click on "Create new question" "button" And I set the field "item_qtype_truefalse" to "1"