From 25bce5c526cddf3c21896817e9c7bf113c455ad4 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 17 Aug 2021 20:12:27 +0800 Subject: [PATCH 1/4] MDL-49202 core_grades: perform same action on items in form When you click on 'Edit' then 'Hide' on a grade item like an assignment it also hides the grades. However, If you use the 'hidden' option on the 'Edit settings' page it just hides that item and doesn't hide grades as well. We want them to be consistent. --- grade/edit/tree/item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grade/edit/tree/item.php b/grade/edit/tree/item.php index 64ddf7f7d8c..45757d25377 100644 --- a/grade/edit/tree/item.php +++ b/grade/edit/tree/item.php @@ -190,7 +190,7 @@ if ($mform->is_cancelled()) { if ($item->cancontrolvisibility) { // Update hiding flag. - $gradeitem->set_hidden($hide, false); + $gradeitem->set_hidden($hide, true); } $gradeitem->set_locktime($locktime); // Locktime first - it might be removed when unlocking. From 0e68c5817f811f28f310eb359ec94ce59afabec9 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 17 Aug 2021 20:13:34 +0800 Subject: [PATCH 2/4] MDL-49202 core_grades: perform same action on categories in form When you click on 'Edit' then 'Hide' on a grade item like a course category that contains many grade items, the course and the grade items are set to hidden. However, if you use the 'hidden' option on the 'Edit settings' page it only hides that item and none of the items (assignment etc) under that course category. We want them to be consistent. --- grade/edit/tree/lib.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/grade/edit/tree/lib.php b/grade/edit/tree/lib.php index bcc79b43822..8e1be55d653 100644 --- a/grade/edit/tree/lib.php +++ b/grade/edit/tree/lib.php @@ -683,11 +683,15 @@ class grade_edit_tree { $gradeitem->grademin, $gradeitem->grademax, 'gradebook'); } - // Update hiding flag. - if ($hiddenuntil) { - $gradeitem->set_hidden($hiddenuntil, false); - } else { - $gradeitem->set_hidden($hidden, false); + // Only update the category's 'hidden' status if it has changed. Leaving a category as 'unhidden' (checkbox left + // unmarked) and submitting the form without this conditional check will result in displaying any grade items that + // are in the category, including those that were previously 'hidden'. + if (($gradecategory->get_hidden() != $hiddenuntil) || ($gradecategory->get_hidden() != $hidden)) { + if ($hiddenuntil) { + $gradecategory->set_hidden($hiddenuntil, true); + } else { + $gradecategory->set_hidden($hidden, true); + } } $gradeitem->set_locktime($locktime); // Locktime first - it might be removed when unlocking. From 757f872b72bfb1c750d4ae1f31333cee07452379 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 17 Aug 2021 20:12:53 +0800 Subject: [PATCH 3/4] MDL-49202 core_grades: add Behat tests --- .../behat/grade_item_form_unhide.feature | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 grade/tests/behat/grade_item_form_unhide.feature diff --git a/grade/tests/behat/grade_item_form_unhide.feature b/grade/tests/behat/grade_item_form_unhide.feature new file mode 100644 index 00000000000..f0680033ed6 --- /dev/null +++ b/grade/tests/behat/grade_item_form_unhide.feature @@ -0,0 +1,123 @@ +@core @core_grades +Feature: Teacher can unhide grades on the edit page allowing students to view their grades + In order to show the grades of an activity to a student + As a teacher + I need to unhide an activity on the edit page + + Background: + Given the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "activities" exist: + | activity | course | idnumber | name | intro | assignfeedback_comments_enabled | + | assign | C1 | assign1 | Test assignment name | Test assignment description | 1 | + And I am on the "Test assignment name" "assign activity" page logged in as teacher1 + And I navigate to "View all submissions" in current page administration + And I click on "Grade" "link" in the "Student 1" "table_row" + And I set the following fields to these values: + | Grade out of 100 | 50 | + | Feedback comments | I'm the teacher feedback | + And I press "Save changes" + And I am on "Course 1" course homepage + And I log out + And I am on the "Test assignment name" "assign activity" page logged in as student1 + And I should see "50.00" + And I should see "I'm the teacher feedback" in the "Feedback comments" "table_row" + And I log out + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "Setup > Gradebook setup" in the course gradebook + + @javascript + Scenario: Hiding the activity using the drop-down hide link and then unhiding the activity using the edit settings form page + Given I click on "Edit" "link" in the "Test assignment name" "table_row" + And I click on "Hide" "link" in the "Test assignment name" "table_row" + And I log out + And I am on the "Test assignment name" "assign activity" page logged in as student1 + And I should not see "50.00" + And I should not see "I'm the teacher feedback" + And I log out + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "Setup > Gradebook setup" in the course gradebook + And I click on "Edit" "link" in the "Test assignment name" "table_row" + And I click on "Edit settings" "link" in the "Test assignment name" "table_row" + And the field "Hidden" matches value "1" + And I set the field "Hidden" to "0" + And I press "Save changes" + And I log out + And I am on the "Test assignment name" "assign activity" page logged in as student1 + Then I should see "50.00" + And I should see "I'm the teacher feedback" in the "Feedback comments" "table_row" + + @javascript + Scenario: Hiding the activity using the edit settings form page and then unhiding the activity using the drop-down show link + Given I click on "Edit" "link" in the "Test assignment name" "table_row" + And I click on "Edit settings" "link" in the "Test assignment name" "table_row" + And I set the field "Hidden" to "1" + And I press "Save changes" + And I log out + And I am on the "Test assignment name" "assign activity" page logged in as student1 + And I should not see "50.00" + And I should not see "I'm the teacher feedback" + And I log out + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "Setup > Gradebook setup" in the course gradebook + And I click on "Edit" "link" in the "Test assignment name" "table_row" + And I click on "Show" "link" in the "Test assignment name" "table_row" + And I log out + And I am on the "Test assignment name" "assign activity" page logged in as student1 + Then I should see "50.00" + And I should see "I'm the teacher feedback" in the "Feedback comments" "table_row" + + @javascript + Scenario: Hiding the category using the drop-down hide link and then unhiding the category using the edit settings form page + Given I click on "Edit" "link" in the "Course 1" "table_row" + And I click on "Hide" "link" in the "Course 1" "table_row" + And I log out + And I am on the "Test assignment name" "assign activity" page logged in as student1 + And I should not see "50.00" + And I should not see "I'm the teacher feedback" + And I log out + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "Setup > Gradebook setup" in the course gradebook + And I click on "Edit" "link" in the "Course 1" "table_row" + And I click on "Edit settings" "link" in the "Course 1" "table_row" + And the field "Hidden" matches value "1" + And I set the field "Hidden" to "0" + And I press "Save changes" + And I log out + And I am on the "Test assignment name" "assign activity" page logged in as student1 + Then I should see "50.00" + And I should see "I'm the teacher feedback" in the "Feedback comments" "table_row" + + @javascript + Scenario: Hiding the category using the edit settings form page and then unhiding the category using the drop-down show link + Given I click on "Edit" "link" in the "Course 1" "table_row" + And I click on "Edit settings" "link" in the "Course 1" "table_row" + And I set the field "Hidden" to "1" + And I press "Save changes" + And I log out + And I am on the "Test assignment name" "assign activity" page logged in as student1 + And I should not see "50.00" + And I should not see "I'm the teacher feedback" + And I log out + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "Setup > Gradebook setup" in the course gradebook + And I click on "Edit" "link" in the "Course 1" "table_row" + And I click on "Show" "link" in the "Course 1" "table_row" + And I log out + And I am on the "Test assignment name" "assign activity" page logged in as student1 + Then I should see "50.00" + And I should see "I'm the teacher feedback" in the "Feedback comments" "table_row" From 9a0d63383a401018ab3fa5c5b531d434b7f4de0a Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 19 Aug 2021 17:06:49 +0800 Subject: [PATCH 4/4] MDL-49202 core: fix failing unit tests See MDL-72377. --- grade/tests/external/create_gradecategories_test.php | 2 +- lib/tests/grades_externallib_test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/grade/tests/external/create_gradecategories_test.php b/grade/tests/external/create_gradecategories_test.php index dfde44b8e5f..553df7c71c3 100644 --- a/grade/tests/external/create_gradecategories_test.php +++ b/grade/tests/external/create_gradecategories_test.php @@ -85,7 +85,7 @@ class create_gradecategories_testcase extends \externallib_advanced_testcase { 'display' => GRADE_DISPLAY_TYPE_LETTER, // Hack. This must be -2 to use the default setting. 'decimals' => 3, - 'hiddenuntil' => time(), + 'hiddenuntil' => 0, 'locktime' => time(), 'weightoverride' => 1, 'aggregationcoef2' => 20, diff --git a/lib/tests/grades_externallib_test.php b/lib/tests/grades_externallib_test.php index 01807e63e51..b0a5e33b45c 100644 --- a/lib/tests/grades_externallib_test.php +++ b/lib/tests/grades_externallib_test.php @@ -579,7 +579,7 @@ class core_grades_external_testcase extends externallib_advanced_testcase { 'display' => GRADE_DISPLAY_TYPE_LETTER, // Hack. This must be -2 to use the default setting. 'decimals' => 3, - 'hiddenuntil' => time(), + 'hiddenuntil' => 0, 'locktime' => time(), 'weightoverride' => 1, 'aggregationcoef2' => 20,