From ce5ce5ab3e06cc7383f0ab1a1339262bd981bf31 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Fri, 19 May 2023 14:44:40 -0500 Subject: [PATCH 1/2] Make renaming a course or unarchiving a course to a new name work again. This was using the old four argument form of the CourseEnvironment constructor. I missed that in #1985. To test this rename a course or unarchive a course to a new name. On the current release candidate branch you will get an error. With this pull request it will work. Note that if you test this on the release candidate branch and rename a course, the course directory will be renamed. So you will need to manually rename that back to what it was. The database tables will still be under the old course name. If you attempt to unarchive to a new name, then the course directory will be created with the new name, but the database tables will not be. So you will need to manually delete that new course directory. --- lib/WeBWorK/Utils/CourseManagement.pm | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/WeBWorK/Utils/CourseManagement.pm b/lib/WeBWorK/Utils/CourseManagement.pm index dcefd4ddaa..f3466e82bb 100644 --- a/lib/WeBWorK/Utils/CourseManagement.pm +++ b/lib/WeBWorK/Utils/CourseManagement.pm @@ -505,11 +505,7 @@ sub renameCourse { } # get new course environment - my $newCE = $oldCE->new( - $oldCE->{webworkDirs}->{root}, - $oldCE->{webworkURLs}->{root}, - $oldCE->{pg}->{directories}->{root}, $newCourseID, - ); + my $newCE = $oldCE->new({ courseName => $newCourseID }); # find the course dirs that still exist in their original locations # (i.e. are not subdirs of $courseDir) From 8f1cb043f11809b77ffa9a29cd685f3067e3a203 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Tue, 23 May 2023 06:02:54 -0500 Subject: [PATCH 2/2] Add a check for course name validity when unarchiving a course to a new name. --- lib/WeBWorK/ContentGenerator/CourseAdmin.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/WeBWorK/ContentGenerator/CourseAdmin.pm b/lib/WeBWorK/ContentGenerator/CourseAdmin.pm index d8a07e5867..15a7ed8d6c 100644 --- a/lib/WeBWorK/ContentGenerator/CourseAdmin.pm +++ b/lib/WeBWorK/ContentGenerator/CourseAdmin.pm @@ -1233,6 +1233,10 @@ sub unarchive_course_validate ($c) { push @errors, $c->maketext('Course ID cannot exceed [_1] characters.', $ce->{maxCourseIdLength}); } + unless ($courseID =~ /^[\w-]*$/) { # regex copied from CourseAdministration.pm + push @errors, $c->maketext('Course ID may only contain letters, numbers, hyphens, and underscores.'); + } + return @errors; }