diff --git a/lib/WeBWorK/ContentGenerator/CourseAdmin.pm b/lib/WeBWorK/ContentGenerator/CourseAdmin.pm index b8274bbf95..2205d09f69 100644 --- a/lib/WeBWorK/ContentGenerator/CourseAdmin.pm +++ b/lib/WeBWorK/ContentGenerator/CourseAdmin.pm @@ -240,9 +240,6 @@ sub add_course_validate ($c) { my $add_initial_userID = trim_spaces($c->param('add_initial_userID')) || ''; my $add_initial_password = trim_spaces($c->param('add_initial_password')) || ''; my $add_initial_confirmPassword = trim_spaces($c->param('add_initial_confirmPassword')) || ''; - my $add_initial_firstName = trim_spaces($c->param('add_initial_firstName')) || ''; - my $add_initial_lastName = trim_spaces($c->param('add_initial_lastName')) || ''; - my $add_initial_email = trim_spaces($c->param('add_initial_email')) || ''; my $add_dbLayout = trim_spaces($c->param('add_dbLayout')) || ''; my @errors; @@ -260,25 +257,11 @@ sub add_course_validate ($c) { push @errors, $c->maketext('Course ID cannot exceed [_1] characters.', $ce->{maxCourseIdLength}); } - if ($add_initial_userID ne '') { - if ($add_initial_password eq '') { - push @errors, $c->maketext('You must specify a password for the initial instructor.'); - } - if ($add_initial_confirmPassword eq '') { - push @errors, $c->maketext('You must confirm the password for the initial instructor.'); - } - if ($add_initial_password ne $add_initial_confirmPassword) { - push @errors, $c->maketext('The password and password confirmation for the instructor must match.'); - } - if ($add_initial_firstName eq '') { - push @errors, $c->maketext('You must specify a first name for the initial instructor.'); - } - if ($add_initial_lastName eq '') { - push @errors, $c->maketext('You must specify a last name for the initial instructor.'); - } - if ($add_initial_email eq '') { - push @errors, $c->maketext('You must specify an email address for the initial instructor.'); - } + if ($add_initial_userID ne '' + && $add_initial_password ne '' + && $add_initial_password ne $add_initial_confirmPassword) + { + push @errors, $c->maketext('The password and password confirmation for the instructor must match.'); } if ($add_dbLayout eq '') { @@ -310,6 +293,8 @@ sub do_add_course ($c) { my $add_initial_firstName = trim_spaces($c->param('add_initial_firstName')) // ''; my $add_initial_lastName = trim_spaces($c->param('add_initial_lastName')) // ''; my $add_initial_email = trim_spaces($c->param('add_initial_email')) // ''; + my $add_initial_studentID = trim_spaces($c->param('add_initial_studentID')) // ''; + my $add_initial_user = $c->param('add_initial_user') // 0; my $copy_from_course = trim_spaces($c->param('copy_from_course')) // ''; @@ -322,25 +307,28 @@ sub do_add_course ($c) { my @users; # copy users from current (admin) course if desired - if ($c->param('add_admin_users')) { - for my $userID ($db->listUsers) { - if ($userID eq $add_initial_userID) { - $c->addbadmessage($c->maketext( - 'User "[_1]" will not be copied from [_2] course as it is the initial instructor.', $userID, - $ce->{admin_course_id} - )); - next; - } - my $PermissionLevel = $db->newPermissionLevel(); - $PermissionLevel->user_id($userID); - $PermissionLevel->permission($ce->{userRoles}{admin}); - my $User = $db->getUser($userID); - my $Password = $db->getPassword($userID); - $User->status('O'); # Add admin user as an observer. - - push @users, [ $User, $Password, $PermissionLevel ] - if $authz->hasPermissions($userID, 'create_and_delete_courses'); + for my $userID ($c->param('add-admin-users')) { + unless ($db->existsUser($userID)) { + $c->addbadmessage($c->maketext( + 'User "[_1]" will not be copied from [_2] course as it does not exist.', $userID, + $ce->{admin_course_id} + )); + next; } + if ($userID eq $add_initial_userID) { + $c->addbadmessage($c->maketext( + 'User "[_1]" will not be copied from [_2] course as it is the initial instructor.', $userID, + $ce->{admin_course_id} + )); + next; + } + + my $PermissionLevel = $db->getPermissionLevel($userID); + my $User = $db->getUser($userID); + my $Password = $db->getPassword($userID); + $User->status('O'); # Add admin user as an observer. + + push @users, [ $User, $Password, $PermissionLevel ]; } # add initial instructor if desired @@ -349,19 +337,35 @@ sub do_add_course ($c) { user_id => $add_initial_userID, first_name => $add_initial_firstName, last_name => $add_initial_lastName, - student_id => $add_initial_userID, + student_id => $add_initial_studentID, email_address => $add_initial_email, status => 'O', ); my $Password = $db->newPassword( user_id => $add_initial_userID, - password => cryptPassword($add_initial_password), + password => $add_initial_password ? cryptPassword($add_initial_password) : '', ); my $PermissionLevel = $db->newPermissionLevel( user_id => $add_initial_userID, permission => '10', ); push @users, [ $User, $Password, $PermissionLevel ]; + + # Add initial user to admin course if asked. + if ($add_initial_user) { + if ($db->existsUser($add_initial_userID)) { + $c->addbadmessage($c->maketext( + 'User "[_1]" will not be added to [_2] course as it already exists.', $add_initial_userID, + $ce->{admin_course_id} + )); + } else { + $User->status('D'); # By default don't allow user to login. + $db->addUser($User); + $db->addPassword($Password); + $db->addPermissionLevel($PermissionLevel); + $User->status('O'); + } + } } push @{ $courseOptions{PRINT_FILE_NAMES_FOR} }, map { $_->[0]->user_id } @users; diff --git a/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm b/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm index 723e922758..1b0c86a2d1 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm @@ -113,8 +113,9 @@ sub initialize ($c) { 'user_id' ); - # Filter out users who don't get included in email - @Users = grep { $ce->status_abbrev_has_behavior($_->status, "include_in_email") } @Users; + # Filter out users who don't get included in email unless in the admin course. + @Users = grep { $ce->status_abbrev_has_behavior($_->status, "include_in_email") } @Users + unless $ce->{courseName} eq $ce->{admin_course_id}; # Cache the user records for later use. $c->{ra_user_records} = \@Users; diff --git a/templates/ContentGenerator/CourseAdmin/add_course_form.html.ep b/templates/ContentGenerator/CourseAdmin/add_course_form.html.ep index 5d258f7ab9..1601558a99 100644 --- a/templates/ContentGenerator/CourseAdmin/add_course_form.html.ep +++ b/templates/ContentGenerator/CourseAdmin/add_course_form.html.ep @@ -39,13 +39,14 @@
<%= maketext('Select sets below to assign them to the newly-created users.') %>
- % param('assignSets', undef); - <%= select_field assignSets => [ map { [ format_set_name_display($_) => $_ ] } $db->listGlobalSets ], - size => 10, multiple => undef, class => 'form-select w-auto mb-2' =%> + % unless ($ce->{courseName} eq $ce->{admin_course_id}) { +<%= maketext('Select sets below to assign them to the newly-created users.') %>
+ % param('assignSets', undef); + <%= select_field assignSets => [ map { [ format_set_name_display($_) => $_ ] } $db->listGlobalSets ], + size => 10, multiple => undef, class => 'form-select w-auto mb-2' =%> + % }<%= submit_button maketext('Add Users'), name => 'addStudents', class => 'btn btn-primary' =%>
<% end =%> diff --git a/templates/HelpFiles/AdminAddCourse.html.ep b/templates/HelpFiles/AdminAddCourse.html.ep index 90414aa727..1c4940b51a 100644 --- a/templates/HelpFiles/AdminAddCourse.html.ep +++ b/templates/HelpFiles/AdminAddCourse.html.ep @@ -22,13 +22,15 @@ . 'on the course home page.') =%>- <%= maketext('The WeBWorK administrators need to be added to the course in order for them to access the course. ' - . 'Unchecking this option will make it so WeBWorK administrators cannot directly login to the course.') =%> + <%= maketext('Select which users in the admin course to copy over to the newly created course. The WeBWorK ' + . 'administrators need to be added to the course in order for them to access the course. Unselecting ' + . 'them will make it so WeBWorK administrators cannot directly login to the course.') =%>
- <%= maketext('Enter the details of the course instructor to be added when the course is created. This user ' - . 'will also be added to the admin course with the username "userID_courseID" so you can manage and ' - . 'email the instructors of the courses on the server.') =%> + <%= maketext('Enter the details of a new course instructor to be added when the course is created. The only ' + . 'required field is the user ID of the this user. Optionally, you can add this user to the administration ' + . 'course, so you can copy this user when creating future courses, or manage and email course instructors. ' + . 'The instructor will be added as a "Dropped" user so they cannot login to the administration course.') =%>
<%= maketext('You may choose a course to copy components from. Select the course and which components to copy. '