Skip to content

Commit

Permalink
Update user information in cached list when saving a user in the Clas…
Browse files Browse the repository at this point in the history
…slist 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 openwebwork#1933.

Also fix sorting that was also broken in openwebwork#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.
  • Loading branch information
drgrice1 committed Apr 6, 2023
1 parent 18441be commit 161adc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions lib/WeBWorK/ContentGenerator/Instructor/UserList.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}{$_}
=%>
% }
</tbody>
Expand Down

0 comments on commit 161adc3

Please sign in to comment.