Skip to content

Commit

Permalink
make config option to hide new courses a trinary option
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Jordan committed Jan 20, 2024
1 parent 44df111 commit 9ae0f4c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
18 changes: 13 additions & 5 deletions conf/site.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,19 @@ $server_root_url = '';
$webwork_server_admin_email = '';

# When new courses are created using the admin course, this setting controls
# whether or not they will be hidden. This applies to courses created using
# "Add Courses" as well as to courses created using "Unarchive Courses" when
# a new ID is given to the unarchived course. (If it is not given a new ID,
# its hidden status is preserved.)
$hide_new_courses = 0;
# whether or not they will be hidden. Setting this to anything other than
# "hidden" or "visible" (or leaving it unset) means that courses created using
# "Add Courses" are not hidden, and all unarchived courses have whatever hidden
# status they had when archived.
# Setting this to "hidden" means that courses created using "Add Courses" and
# courses created using "Unarchive Courses" with a new course ID will be hidden.
# Unarchived courses that keep their original name will keep their hidden
# status.
# Setting this to "visible" means that courses created using "Add Courses" and
# courses created using "Unarchive Courses" with a new course ID will be visible.
# Unarchived courses that keep their original name will keep their hidden
# status.
#$new_courses_hidden_status = 'hidden';

# password strings (or any other string allowing special characters) should be specified inside single quotes
# otherwise a string such as "someone@nowhere" will interpolate the contents of the array @nowhere -- which is probably
Expand Down
16 changes: 10 additions & 6 deletions lib/WeBWorK/Utils/CourseManagement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ sub addCourse {
"Failed to create $courseDirName directory '$courseDir': $!. You will have to create this directory manually.\n";
}

# hide the course?
# hide the new course?

if ($ce->{hide_new_courses}) {
if (defined $ce->{new_courses_hidden_status} && $ce->{new_courses_hidden_status} eq 'hidden') {
my $hideDirFile = "$ce->{webworkDirs}{courses}/$courseID/hide_directory";
open(my $HIDEFILE, '>', $hideDirFile);
print $HIDEFILE 'Place a file named "hide_directory" in a course or other directory and it will not show up '
Expand Down Expand Up @@ -990,17 +990,21 @@ sub unarchiveCourse {
"Failed to create html_temp directory '$tmpDir': $!. You will have to create this directory manually.\n";
}

# If the course was given a new name, honor $ce->{hide-new-courses}
if (defined $newCourseID && $newCourseID ne $currCourseID) {
# If the course was given a new name, honor $ce->{new_courses_hidden_status}
if (defined $newCourseID
&& $newCourseID ne $currCourseID
&& defined $ce->{new_courses_hidden_status}
&& $ce->{new_courses_hidden_status} =~ /^(hidden|visible)$/)
{
my $hideDirFile = "$ce->{webworkDirs}{courses}/$currCourseID/hide_directory";
if ($ce->{hide_new_courses} && !(-f $hideDirFile)) {
if ($ce->{new_courses_hidden_status} eq 'hidden' && !(-f $hideDirFile)) {
open(my $HIDEFILE, '>', $hideDirFile);
print $HIDEFILE
'Place a file named "hide_directory" in a course or other directory and it will not show up '
. 'in the courses list on the WeBWorK home page. It will still appear in the '
. 'Course Administration listing.';
close $HIDEFILE;
} elsif (!$ce->{hide_new_courses} && -f $hideDirFile) {
} elsif ($ce->{new_courses_hidden_status} eq 'visible' && -f $hideDirFile) {
unlink $hideDirFile;
}
}
Expand Down

0 comments on commit 9ae0f4c

Please sign in to comment.