Skip to content

Commit

Permalink
Add course, make passwords text and few more tweaks.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
somiaj committed Nov 23, 2024
1 parent 6de5027 commit 52a38d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 44 deletions.
46 changes: 19 additions & 27 deletions lib/WeBWorK/ContentGenerator/CourseAdmin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
$_
);
}
}

Expand Down Expand Up @@ -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/) {
Expand All @@ -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,
Expand All @@ -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');
}
}
}
Expand Down
19 changes: 2 additions & 17 deletions templates/ContentGenerator/CourseAdmin/add_course_form.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,12 @@
<%= label_for "add_initial_userID_$_" => maketext('User ID') =%>
</div>
<div class="form-floating mb-1">
<%= 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') =%>
</div>
<div class="form-floating mb-1">
<%= password_field "add_initial_confirmPassword_$_",
id => "add_initial_confirmPassword_$_",
placeholder => '',
class => 'form-control' =%>
<%= label_for "add_initial_confirmPassword_$_" => maketext('Confirm Password') =%>
</div>
<div class="form-floating mb-1">
<%= select_field "add_initial_permission_$_" => $permissionLevels,
id => "add_initial_role_$_",
Expand Down Expand Up @@ -140,13 +132,6 @@
class => 'form-control' =%>
<%= label_for "add_initial_email_$_" => maketext('Email Address') =%>
</div>
<div class="form-floating mb-1">
<%= text_field "add_initial_studentID_$_" => '',
id => "add_initial_studentID_$_",
placeholder => '',
class => 'form-control' =%>
<%= label_for "add_initial_studentID_$_" => maketext('Student ID') =%>
</div>
</div>
</div>
<div class="form-check mb-3">
Expand Down

0 comments on commit 52a38d3

Please sign in to comment.