Skip to content

Commit

Permalink
StudentQuiz: separate out changestate management #727398
Browse files Browse the repository at this point in the history
from general delete/edit management
  • Loading branch information
DangHieu1407 committed Nov 30, 2023
1 parent 904a6dd commit 968ad7d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
1 change: 0 additions & 1 deletion changestate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down
32 changes: 17 additions & 15 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions tests/behat/state_visibility.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 968ad7d

Please sign in to comment.