From fff9d0b1fbec9262620a606c1ce061f9d877af57 Mon Sep 17 00:00:00 2001 From: Andrew Gosali Date: Wed, 20 Nov 2024 14:40:54 +0700 Subject: [PATCH] MDL-83591 grade: fix issue when item is already deleted The deleted grade is causing the error while using its id that was previously saved in the session variable --- grade/report/singleview/index.php | 2 ++ grade/report/singleview/tests/behat/singleview.feature | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/grade/report/singleview/index.php b/grade/report/singleview/index.php index 50fc0f5bc31..4d5aeecd05d 100644 --- a/grade/report/singleview/index.php +++ b/grade/report/singleview/index.php @@ -107,6 +107,7 @@ switch ($itemtype) { // display the user select zero state. if (is_null($itemid) || !array_key_exists($itemid, grade_report::get_gradable_users($courseid, $currentgroup))) { $itemtype = 'user_select'; + unset($SESSION->gradereport_singleview["useritem-{$context->id}"]); } break; case 'grade_select': @@ -129,6 +130,7 @@ switch ($itemtype) { // The item id (grade item id) cannot be defined, display the grade select zero state. if (is_null($itemid) || !array_key_exists($itemid, $gtree->get_items())) { $itemtype = 'grade_select'; + unset($SESSION->gradereport_singleview["gradeitem-{$context->id}"]); } break; } diff --git a/grade/report/singleview/tests/behat/singleview.feature b/grade/report/singleview/tests/behat/singleview.feature index 9b0583f5940..ad9bea8fcf1 100644 --- a/grade/report/singleview/tests/behat/singleview.feature +++ b/grade/report/singleview/tests/behat/singleview.feature @@ -237,6 +237,9 @@ Feature: We can use Single view When I navigate to "View > Single view" in the course gradebook Then I should see "Search for a user to view all their grades" in the "region-main" "region" And I should not see "Gronya,Beecham" in the "region-main" "region" + # edge case coverage: to ensure session variable not causing error upon second visit + And I reload the page + And I should see "Search for a user to view all their grades" in the "region-main" "region" Scenario: Teacher does not see his last viewed user report if that user is no longer enrolled in the course. Given I navigate to "View > Single view" in the course gradebook @@ -247,6 +250,9 @@ Feature: We can use Single view When I am on the "Course 1" "grades > Single view > View" page Then I should see "Search for a user to view all their grades" in the "region-main" "region" And I should not see "Gronya,Beecham" in the "region-main" "region" + # edge case coverage: to ensure session variable not causing error upon second visit + And I reload the page + And I should see "Search for a user to view all their grades" in the "region-main" "region" Scenario: Teacher does not see his last viewed grade item report if the item no longer exists in the course. Given I navigate to "View > Single view" in the course gradebook @@ -258,3 +264,6 @@ Feature: We can use Single view When I navigate to "View > Single view" in the course gradebook Then I should see "Select a grade item above" in the "region-main" "region" And I should not see "Test grade item" in the "region-main" "region" + # edge case coverage: to ensure session variable not causing error upon second visit + And I reload the page + And I should see "Select a grade item above" in the "region-main" "region"