From 161adc3c742e6d7084ec50910bd34286ef4fac25 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Thu, 6 Apr 2023 18:19:25 -0500 Subject: [PATCH] Update user information in cached list when saving a user in the Classlist Editor. Since the database is not queried to retrieve updated information after actions are performed the data for saved users needs to be updated in the cached lists so that the updated information is displayed when the templates are loaded later. This fixes #1933. Also fix sorting that was also broken in #1888. The fallback methods are needed in order for sorting to work correctly in case the first three do not sort thing properly. Currently, if you load the page with users that do not have the information that the first three methods sort on, then the users end up in a different order each time you load the page. For example, if using the default sort and users do not have first or last names. --- lib/WeBWorK/ContentGenerator/Instructor/UserList.pm | 11 +++++++++-- .../Instructor/UserList/user_list.html.ep | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/WeBWorK/ContentGenerator/Instructor/UserList.pm b/lib/WeBWorK/ContentGenerator/Instructor/UserList.pm index e557919b2c..a38c4a35c5 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/UserList.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/UserList.pm @@ -238,13 +238,17 @@ sub pre_header_initialize ($c) { my $secondarySortSub = SORT_SUBS()->{ $c->{secondarySortField} }; my $ternarySortSub = SORT_SUBS()->{ $c->{ternarySortField} }; - $c->{allUserIDs} = [ keys %allUsers ]; + $c->{allUserIDs} = [ keys %allUsers ]; + + # Always have a definite sort order in case the first three sorts don't determine things. $c->{sortedUserIDs} = [ map { $_->user_id } - sort { &$primarySortSub || &$secondarySortSub || &$ternarySortSub } + sort { &$primarySortSub || &$secondarySortSub || &$ternarySortSub || byLastName || byFirstName || byUserID } grep { $c->{visibleUserIDs}{ $_->user_id } } (values %allUsers) ]; + for (@{ $c->{sortedUserIDs} }) { $c->log->info($_); } + return; } @@ -511,6 +515,9 @@ sub save_edit_handler ($c) { $db->putUser($User); $db->putPermissionLevel($PermissionLevel); + + $User->{permission} = $PermissionLevel->permission; + $c->{allUsers}{$userID} = $User; } if (defined $c->param('prev_visible_users')) { diff --git a/templates/ContentGenerator/Instructor/UserList/user_list.html.ep b/templates/ContentGenerator/Instructor/UserList/user_list.html.ep index c42223351b..4c236d7d16 100644 --- a/templates/ContentGenerator/Instructor/UserList/user_list.html.ep +++ b/templates/ContentGenerator/Instructor/UserList/user_list.html.ep @@ -73,7 +73,7 @@ <%= include 'ContentGenerator/Instructor/UserList/user_row', user => $c->{allUsers}{$_}, userSelected => exists $c->{selectedUserIDs}{$_}, - editable => exists $c->{userIsEditable}{$_} + editable => exists $c->{userIsEditable}{$_} =%> % }