From 52a38d359539f7eebf6093c7dad069f44eb9dd44 Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Tue, 19 Nov 2024 21:38:26 -0700 Subject: [PATCH] Add course, make passwords text and few more tweaks. Make password fields for new users text, so they will be saved after hitting add another user or errors appear. Since they are passwords for other users no need to hide them. Remove confirm password and student ID input to make each new user take up a little less space. Also make it so new student users are current (enrolled) in the course, while all other users are observers. --- lib/WeBWorK/ContentGenerator/CourseAdmin.pm | 46 ++++++++----------- .../CourseAdmin/add_course_form.html.ep | 19 +------- 2 files changed, 21 insertions(+), 44 deletions(-) diff --git a/lib/WeBWorK/ContentGenerator/CourseAdmin.pm b/lib/WeBWorK/ContentGenerator/CourseAdmin.pm index f87646c2e5..113e52f233 100644 --- a/lib/WeBWorK/ContentGenerator/CourseAdmin.pm +++ b/lib/WeBWorK/ContentGenerator/CourseAdmin.pm @@ -259,22 +259,15 @@ sub add_course_validate ($c) { } for (1 .. $number_of_additional_users) { - my $userID = trim_spaces($c->param("add_initial_userID_$_")) || ''; - my $password = trim_spaces($c->param("add_initial_password_$_")) || ''; - my $confirmPassword = trim_spaces($c->param("add_initial_confirmPassword_$_")) || ''; + my $userID = trim_spaces($c->param("add_initial_userID_$_")) || ''; - if ($userID ne '') { - unless ($userID =~ /^[\w-.,]*$/) { - push @errors, - $c->maketext( - 'User ID number [_1] may only contain letters, numbers, hyphens, periods, commas, ' - . 'and underscores.', - $_ - ); - } - if ($password ne '' && $password ne $confirmPassword) { - push @errors, $c->maketext('Pasword number [_1] and its password confirmation must match.', $_); - } + unless ($userID =~ /^[\w-.,]*$/) { + push @errors, + $c->maketext( + 'User ID number [_1] may only contain letters, numbers, hyphens, periods, commas, ' + . 'and underscores.', + $_ + ); } } @@ -337,21 +330,21 @@ sub do_add_course ($c) { my $PermissionLevel = $db->getPermissionLevel($userID); my $User = $db->getUser($userID); my $Password = $db->getPassword($userID); - $User->status('O'); # Add admin course user as an observer. + + # Enroll student users, and make all other users observers. + $User->status($PermissionLevel->permission == $ce->{userRoles}{student} ? 'C' : 'O'); push @users, [ $User, $Password, $PermissionLevel ]; } # add additional instructors if desired for (1 .. $number_of_additional_users) { - my $userID = trim_spaces($c->param("add_initial_userID_$_")) // ''; - my $password = trim_spaces($c->param("add_initial_password_$_")) // ''; - my $confirmPassword = trim_spaces($c->param("add_initial_confirmPassword_$_")) // ''; - my $firstName = trim_spaces($c->param("add_initial_firstName_$_")) // ''; - my $lastName = trim_spaces($c->param("add_initial_lastName_$_")) // ''; - my $email = trim_spaces($c->param("add_initial_email_$_")) // ''; - my $studentID = trim_spaces($c->param("add_initial_studentID_$_")) // ''; - my $permissionLevel = trim_spaces($c->param("add_initial_permission_$_")); + my $userID = trim_spaces($c->param("add_initial_userID_$_")) // ''; + my $password = trim_spaces($c->param("add_initial_password_$_")) // ''; + my $firstName = trim_spaces($c->param("add_initial_firstName_$_")) // ''; + my $lastName = trim_spaces($c->param("add_initial_lastName_$_")) // ''; + my $email = trim_spaces($c->param("add_initial_email_$_")) // ''; + my $permissionLevel = $c->param("add_initial_permission_$_"); my $add_user = $c->param("add_initial_user_$_") // 0; if ($userID =~ /\S/) { @@ -360,8 +353,7 @@ sub do_add_course ($c) { first_name => $firstName, last_name => $lastName, email_address => $email, - student_id => $studentID, - status => 'O', + status => $permissionLevel == $ce->{userRoles}{student} ? 'C' : 'O', ); my $Password = $db->newPassword( user_id => $userID, @@ -385,7 +377,7 @@ sub do_add_course ($c) { $db->addUser($User); $db->addPassword($Password); $db->addPermissionLevel($PermissionLevel); - $User->status('O'); + $User->status($permissionLevel == $ce->{userRoles}{student} ? 'C' : 'O'); } } } diff --git a/templates/ContentGenerator/CourseAdmin/add_course_form.html.ep b/templates/ContentGenerator/CourseAdmin/add_course_form.html.ep index a05430dfd8..a822b4b0e7 100644 --- a/templates/ContentGenerator/CourseAdmin/add_course_form.html.ep +++ b/templates/ContentGenerator/CourseAdmin/add_course_form.html.ep @@ -97,20 +97,12 @@ <%= label_for "add_initial_userID_$_" => maketext('User ID') =%>
- <%= password_field "add_initial_password_$_", + <%= text_field "add_initial_password_$_" => '', id => "add_initial_password_$_", placeholder => '', - class => 'form-control', - autocomplete => 'new-password' =%> + class => 'form-control' =%> <%= label_for "add_initial_password_$_" => maketext('Password') =%>
-
- <%= password_field "add_initial_confirmPassword_$_", - id => "add_initial_confirmPassword_$_", - placeholder => '', - class => 'form-control' =%> - <%= label_for "add_initial_confirmPassword_$_" => maketext('Confirm Password') =%> -
<%= select_field "add_initial_permission_$_" => $permissionLevels, id => "add_initial_role_$_", @@ -140,13 +132,6 @@ class => 'form-control' =%> <%= label_for "add_initial_email_$_" => maketext('Email Address') =%>
-
- <%= text_field "add_initial_studentID_$_" => '', - id => "add_initial_studentID_$_", - placeholder => '', - class => 'form-control' =%> - <%= label_for "add_initial_studentID_$_" => maketext('Student ID') =%> -