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
This commit is contained in:
Andrew Gosali
2025-03-17 10:47:32 +07:00
parent b3931cdb95
commit 61b05eeb97
2 changed files with 11 additions and 0 deletions
+2
View File
@@ -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;
}
@@ -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"