Skip to content

Fix classlist exporting with users that do not have passwords. #2705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion htdocs/js/UserList/userlist.js
Original file line number Diff line number Diff line change
@@ -113,7 +113,10 @@
e.preventDefault();
e.stopPropagation();
show_errors(['select_user_err_msg'], [export_select]);
} else if (export_select_target?.value === 'new' && export_filename.value === '') {
} else if (
export_select_target?.value === 'new' &&
(export_filename.value === '' || /\//.test(export_filename.value))
) {
e.preventDefault();
e.stopPropagation();
show_errors(['export_file_err_msg'], [export_filename, export_select_target]);
32 changes: 15 additions & 17 deletions lib/WeBWorK/ContentGenerator/Instructor/UserList.pm
Original file line number Diff line number Diff line change
@@ -726,31 +726,29 @@ sub importUsersFromCSV ($c, $fileName, $replaceExisting, $fallbackPasswordSource
}

sub exportUsersToCSV ($c, $fileName, @userIDsToExport) {
my $ce = $c->ce;
my $db = $c->db;
my $dir = $ce->{courseDirs}->{templates};
my $ce = $c->ce;
my $db = $c->db;

die $c->maketext("illegal character in input: '/'") if $fileName =~ m|/|;
die $c->maketext(q{illegal character in input: '/'}) if $fileName =~ m|/|;

my @records;

my @Users = $db->getUsers(@userIDsToExport);
my @Passwords = $db->getPasswords(@userIDsToExport);
my @PermissionLevels = $db->getPermissionLevels(@userIDsToExport);
foreach my $i (0 .. $#userIDsToExport) {
my $User = $Users[$i];
my $Password = $Passwords[$i];
my $PermissionLevel = $PermissionLevels[$i];
next unless defined $User;
my %record = (
defined $PermissionLevel ? $PermissionLevel->toHash : (),
defined $Password ? $Password->toHash : (),
$User->toHash,
my @users = $db->getUsers(@userIDsToExport);
my %passwords = map { $_->user_id => $_ } $db->getPasswords(@userIDsToExport);
my %permissionLevels = map { $_->user_id => $_ } $db->getPermissionLevels(@userIDsToExport);

for my $user (@users) {
my $password = $passwords{ $user->user_id };
my $permissionLevel = $permissionLevels{ $user->user_id };
my %record = (
defined $permissionLevel ? $permissionLevel->toHash : (),
defined $password ? $password->toHash : (),
$user->toHash,
);
push @records, \%record;
}

write_classlist("$dir/$fileName", @records);
write_classlist("$ce->{courseDirs}{templates}/$fileName", @records);

return;
}
Original file line number Diff line number Diff line change
@@ -34,6 +34,6 @@
</div>
</div>
<div id="export_file_err_msg" class="alert alert-danger p-1 d-inline-flex d-none">
<%= maketext('Please input file name to export to.') %>
<%= maketext('Please input a file name to export to that does not contain forward slashes.') %>
</div>
</div>