From a63f5972020923d935fb0b0e27ab49b058b39f0f Mon Sep 17 00:00:00 2001 From: David Watson <14983002+watson8@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:40:26 +0100 Subject: [PATCH] CTP-3783 adapt behat to commit c1132f6 --- classes/controllers/feedback_controller.php | 10 ++- classes/models/outstanding_marking.php | 7 --- datatables/js/edit_datatables.js | 63 ++++++++++--------- tests/behat/behat_mod_coursework.php | 10 ++- tests/behat/feedback_collisions.feature | 45 ++++++++----- ...back_final_feedback_double_marking.feature | 54 +++++++++++----- ...eedback_multiple_assessor_feedback.feature | 2 +- version.php | 2 +- 8 files changed, 120 insertions(+), 73 deletions(-) diff --git a/classes/controllers/feedback_controller.php b/classes/controllers/feedback_controller.php index ff1a50ec..5198524e 100644 --- a/classes/controllers/feedback_controller.php +++ b/classes/controllers/feedback_controller.php @@ -116,8 +116,14 @@ protected function new_feedback() { } $ability = new ability(user::find($USER), $this->coursework); - $ability->require_can('new', $teacherfeedback); - + if (!$ability->can('new', $teacherfeedback)) { + if ($this->params['ajax']) { + echo json_encode(['success' => false, 'message' => $ability->get_last_message()]); + die(); + } else { + throw new access_denied($this->coursework, $ability->get_last_message()); + } + } $this->check_stage_permissions($this->params['stage_identifier']); $urlparams = []; diff --git a/classes/models/outstanding_marking.php b/classes/models/outstanding_marking.php index 3c615e1e..426da502 100644 --- a/classes/models/outstanding_marking.php +++ b/classes/models/outstanding_marking.php @@ -24,13 +24,6 @@ class outstanding_marking { - private $dayinsecs; - - public function __construct() { - - $this->day_in_secs = 86400; - } - /** * @param $cwkrecord * @param $userid diff --git a/datatables/js/edit_datatables.js b/datatables/js/edit_datatables.js index 4c4becc9..063996d3 100644 --- a/datatables/js/edit_datatables.js +++ b/datatables/js/edit_datatables.js @@ -727,41 +727,44 @@ $(document).ready(function () { }).done(function(response) { response = $.parseJSON(response); var modalbody = $('#modal-grading').find('.modal-body'); - modalbody.html(response.formhtml); - var filemanager = modalbody.find('.filemanager'); - if (response.filemanageroptions && filemanager.length) { - var elementid = filemanager.attr('id'); - var clientid = elementid.substr(12); - if (clientid) { - response.filemanageroptions.client_id = clientid; - M.form_filemanager.init(Y, response.filemanageroptions); + // Careful as not all requests return a response.success value. Only if it's false, show error. + if ((response.success ?? true) === false && (response.message ?? null)) { + modalbody.html(response.message); + } else { + modalbody.html(response.formhtml); + var filemanager = modalbody.find('.filemanager'); + if (response.filemanageroptions && filemanager.length) { + var elementid = filemanager.attr('id'); + var clientid = elementid.substr(12); + if (clientid) { + response.filemanageroptions.client_id = clientid; + M.form_filemanager.init(Y, response.filemanageroptions); + } } - } - if (response.editoroptions) { - require(['editor_tiny/editor'], (Tiny) => { - Tiny.setupForElementId({ - elementId: 'id_feedbackcomment', - options: JSON.parse(response.editoroptions), + if (response.editoroptions) { + require(['editor_tiny/editor'], (Tiny) => { + Tiny.setupForElementId({ + elementId: 'id_feedbackcomment', + options: JSON.parse(response.editoroptions), + }); }); - }); - } - - if (response.commentoptions) { - M.util.js_pending('gradingform_guide/comment_chooser'); - require(['gradingform_guide/comment_chooser'], function(amd) { - $(".remark").each( function (i,ele) { - buttonele = $(ele).find(".commentchooser"); - textele = $(ele).find(".markingguideremark"); - - buttonid = $(buttonele).attr("id"); - textid = $(textele).attr("id"); + } - amd.initialise(1, buttonid, textid, response.commentoptions) ; - M.util.js_complete('gradingform_guide/comment_chooser'); + if (response.commentoptions) { + M.util.js_pending('gradingform_guide/comment_chooser'); + require(['gradingform_guide/comment_chooser'], function(amd) { + $(".remark").each( function (i,ele) { + buttonele = $(ele).find(".commentchooser"); + textele = $(ele).find(".markingguideremark"); + buttonid = $(buttonele).attr("id"); + textid = $(textele).attr("id"); + amd.initialise(1, buttonid, textid, response.commentoptions); + M.util.js_complete('gradingform_guide/comment_chooser'); - }) + }) - }); + }); + } } }); var cell_td = $(this).closest('td'); diff --git a/tests/behat/behat_mod_coursework.php b/tests/behat/behat_mod_coursework.php index c64df538..7a73fb5b 100644 --- a/tests/behat/behat_mod_coursework.php +++ b/tests/behat/behat_mod_coursework.php @@ -1992,7 +1992,7 @@ public function there_is_final_feedback() { } /** - * @Given /^there is final feedback from the other teacher$/ + * @Given /^there is final feedback from the other teacher with grade 45$/ */ public function there_is_final_feedback_from_the_other_teacher() { $generator = $this->get_coursework_generator(); @@ -2169,7 +2169,7 @@ public function i_should_see_the_final_single_grade_on_the_page($grade = 56) { } /** - * @Given /^I have an assessor feedback$/ + * @Given /^I have an assessor feedback at grade 67$/ */ public function i_have_an_assessor_feedback() { /** @@ -2191,6 +2191,10 @@ public function i_have_an_assessor_feedback() { * @param string $expectedvalue */ public function i_should_see_the_grade_comment_in_the_form_on_the_page($expectedvalue = 'New comment here') { + // Since commit c1132f6, feedback comments editing has happened from AJAX form. + // Tests were not updated for this so add a wait to enable form to load before we check. + $this->wait_for_pending_js(); + $this->wait_for_seconds(2); $commentfield = $this->find('css', '#feedback_comment'); if ($commentfield->getValue() != $expectedvalue) { throw new ExpectationException("Expected comment $expectedvalue got " . $commentfield->getValue(), $this->getSession()); @@ -2250,6 +2254,8 @@ public function i_should_see_the_rubric_grade_on_the_page() { * @throws Behat\Mink\Exception\ElementNotFoundException */ public function i_grade_the_submission_using_the_simple_form($grade = 56, $withoutcomments=false) { + $this->wait_for_pending_js(); + $this->wait_for_seconds(2); $nodeelement = $this->getSession()->getPage()->findById('feedback_grade'); if ($nodeelement) { $nodeelement->selectOption($grade); diff --git a/tests/behat/feedback_collisions.feature b/tests/behat/feedback_collisions.feature index 83130de6..252e44ce 100644 --- a/tests/behat/feedback_collisions.feature +++ b/tests/behat/feedback_collisions.feature @@ -13,39 +13,52 @@ Feature: Collisions: two people try to create feedback at the same time And the student has a submission And the submission is finalised - Scenario: Single marker: If I submit feedback and it's already been given then the form should reload with a warning + @javascript + Scenario: Single marker: If I submit feedback and it's already been given then the form should show a warning Given there is a teacher And there is another teacher And I am logged in as the other teacher And the coursework is set to single marker When I visit the coursework page + And I have an assessor feedback at grade 67 And I click the new single final feedback button for the student - And I have an assessor feedback - When I grade the submission using the simple form - Then I should be on the create feedback page - And I should see "has already submitted" - Then I should see the grade comment in the form on the page - And I should see the grade in the form on the page + And I should see "Allocatable already has feedback for this stage" + @javascript Scenario: Multiple marker: If I submit feedback and it's already been given then it should be given a new stage_identifier Given there is a teacher And there is another teacher And I am logged in as the other teacher And the coursework is set to double marker + And I have an assessor feedback at grade 67 When I visit the coursework page - And I click on the new feedback button for assessor 1 - And I have an assessor feedback - When I grade the submission using the simple form - Then I should be on the coursework page + # Expand the row. + When I click on ".details-control" "css_element" + And I wait until the page is ready + And I wait "2" seconds + And I click on "New feedback" "link" + And I wait until the page is ready + And I wait "1" seconds + And I set the field "Grade" to "56" + And I set the field "Comment" to "Some comment 1" + And I wait "2" seconds + And I click on "Save and finalise" "button" + And I should see "Your data has been saved." + @javascript Scenario: Multiple marker: If I submit feedback and it's already been given by all teachers then it should fail Given there is a teacher And there is another teacher And I am logged in as a manager And the coursework is set to double marker When I visit the coursework page - And I click on the new feedback button for assessor 1 - And I have an assessor feedback - And there is final feedback from the other teacher - When I grade the submission using the simple form - Then I should be on the create feedback page + And I have an assessor feedback at grade 67 + And there is final feedback from the other teacher with grade 45 + # Expand the row. + When I click on ".details-control" "css_element" + And I wait until the page is ready + And I wait "2" seconds + And I click on "New feedback" "link" + And I wait until the page is ready + And I wait "2" seconds + And I should see "Allocatable already has feedback for this stage" diff --git a/tests/behat/feedback_final_feedback_double_marking.feature b/tests/behat/feedback_final_feedback_double_marking.feature index e040c80d..7ee1e3b9 100644 --- a/tests/behat/feedback_final_feedback_double_marking.feature +++ b/tests/behat/feedback_final_feedback_double_marking.feature @@ -1,4 +1,4 @@ -@mod @mod_coursework +@mod @mod_coursework @mod_coursework_feedback_final_feedback_double_marking Feature: Adding and editing final feedback In order to provide students with a fair final grade that combines the component grades @@ -15,42 +15,68 @@ Feature: Adding and editing final feedback And the student has a submission And the submission is finalised + @javascript Scenario: Setting the final feedback grade Given there are feedbacks from both teachers And I am logged in as a manager And I visit the coursework page When I click the new multiple final feedback button for the student - When I grade the submission using the simple form - Then I should be on the coursework page - And I should see the final grade on the multiple marker page + # Form loaded and sent by AJAX now so wait for it to load. + And I wait until the page is ready + And I wait "1" seconds + And I set the field "Grade" to "57" + And I set the field "Comment" to "Some comment 1" + And I wait "2" seconds + And I click on "Save and finalise" "button" + And I should see "Your data has been saved." + Then I visit the coursework page + And I should see the final grade as 57 on the multiple marker page + @javascript Scenario: Setting the final feedback comment Given there are feedbacks from both teachers And I am logged in as a manager And I visit the coursework page When I click the new multiple final feedback button for the student - When I grade the submission using the simple form - Then I should be on the coursework page + # Form loaded and sent by AJAX now so wait for it to load. + And I wait until the page is ready + And I wait "1" seconds + And I set the field "Grade" to "58" + And I set the field "Comment" to "Some comment 2" + And I wait "2" seconds + And I click on "Save and finalise" "button" + And I should see "Your data has been saved." + Then I visit the coursework page When I click the edit final feedback button - Then I should see the grade comment in the form on the page - And I should see the grade in the form on the page + And I wait until the page is ready + And I wait "1" seconds + And the field "Grade" matches value "58" + And the field "Comment" matches value "Some comment 2" + @javascript Scenario: I can be both an initial assessor and the manager who agrees grades And managers do not have the manage capability Given I am logged in as a manager And there are feedbacks from both me and another teacher And I visit the coursework page When I click the new multiple final feedback button for the student - And I grade the submission using the simple form - Then I should be on the coursework page + And I wait until the page is ready + And I wait "1" seconds + And I set the field "Grade" to "59" + And I set the field "Comment" to "Some comment 3" + And I wait "2" seconds + And I click on "Save and finalise" "button" + And I should see "Your data has been saved." + @javascript Scenario: Editing final feedback from others And managers do not have the manage capability Given I am logged in as a manager And there are feedbacks from both me and another teacher - And there is final feedback from the other teacher + And there is final feedback from the other teacher with grade 45 When I visit the coursework page When I click the edit final feedback button - And I should see the other teacher's final grade in the form on the page - And I grade the submission using the simple form - Then I should be on the coursework page + And I wait until the page is ready + And I wait "2" seconds + And I wait until the page is ready + And the field "Grade" matches value "45" diff --git a/tests/behat/feedback_multiple_assessor_feedback.feature b/tests/behat/feedback_multiple_assessor_feedback.feature index 165c0110..36291270 100644 --- a/tests/behat/feedback_multiple_assessor_feedback.feature +++ b/tests/behat/feedback_multiple_assessor_feedback.feature @@ -48,7 +48,7 @@ Feature: Multiple assessors simple grading form Scenario: Grade comments can be edited Given I am logged in as a teacher And the submission is finalised - And I have an assessor feedback + And I have an assessor feedback at grade 67 And I visit the coursework page And I click on the edit feedback icon Then I should see the grade comment in the form on the page diff --git a/version.php b/version.php index 3c38c530..058ac426 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ $plugin->component = 'mod_coursework'; -$plugin->version = 2024091600; // If version == 0 then module will not be installed +$plugin->version = 2024100701; // If version == 0 then module will not be installed $plugin->requires = 2023100400; // Requires this Moodle version $plugin->cron = 300; // Period for cron to check this module (secs).