Skip to content

Commit

Permalink
allow customization of admin course ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Jordan committed Jan 4, 2024
1 parent 2b193de commit 412f927
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 20 deletions.
10 changes: 10 additions & 0 deletions conf/site.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ $server_root_url = '';
# Be sure to use single quotes for the address or the @ sign will be interpreted as an array.
$webwork_server_admin_email = '';

# The following is the name of the admin course where admin level users can create
# courses, delete courses, and more. It is named 'admin' by default but for security,
# you may want to change to something that cannot be guessed. While installing WeBWorK,
# leave this as 'admin'. Once everything is running well, use the 'admin' course to
# create a new course to serve as the admin course. You may need to copy all archives
# from the 'admin' course into this new course. Then change $admin_course_id to the ID
# of the new course and restart webwork2. You may then also want to archive and delete
# the original 'admin' course.
$admin_course_id = 'admin';

# 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
# empty, but still not what you want. Similar things happen with % and $
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojolicious/WeBWorK.pm
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ sub startup ($app) {
$cg_r->get('/')->to('Home#go')->name('root');

# The course admin route is set up here because of its special stash value.
$cg_r->any('/admin')->to('CourseAdmin#go', courseID => 'admin')->name('course_admin');
$cg_r->any("/$ce->{admin_course_id}")->to('CourseAdmin#go', courseID => $ce->{admin_course_id})
->name('course_admin');

setup_content_generator_routes($cg_r);

Expand Down
2 changes: 1 addition & 1 deletion lib/WeBWorK.pm
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async sub dispatch ($c) {
return (0, 'This course does not exist.')
unless (-e $ce->{courseDirs}{root}
|| -e "$ce->{webwork_courses_dir}/admin/archives/$routeCaptures{courseID}.tar.gz");
|| -e "$ce->{webwork_courses_dir}/$ce->{admin_course_id}/archives/$routeCaptures{courseID}.tar.gz");
return (0, 'This course has been archived and closed.') unless -e $ce->{courseDirs}{root};
debug("...we can create a database object...\n");
Expand Down
2 changes: 1 addition & 1 deletion lib/WeBWorK/Authz.pm
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ sub hasPermissions {
# Elevate all permissions greater than a student in the admin course to the
# create_and_delete_courses level. This way a user either has access to all
# or only student level permissions tools in the admin course.
if (defined($ce->{courseName}) && $ce->{courseName} eq 'admin') {
if (defined($ce->{courseName}) && $ce->{courseName} eq $ce->{admin_course_id}) {
my $admin_permlevel = $userRoles->{ $permissionLevels->{create_and_delete_courses} };
$role_permlevel = $admin_permlevel
if $role_permlevel > $userRoles->{student} && $role_permlevel < $admin_permlevel;
Expand Down
5 changes: 3 additions & 2 deletions lib/WeBWorK/ContentGenerator/CourseAdmin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ sub do_add_course ($c) {
for my $userID ($db->listUsers) {
if ($userID eq $add_initial_userID) {
$c->addbadmessage($c->maketext(
'User "[_1]" will not be copied from admin course as it is the initial instructor.', $userID
'User "[_1]" will not be copied from [_2] course as it is the initial instructor.', $userID,
$ce->{admin_course_id}
));
next;
}
Expand Down Expand Up @@ -1264,7 +1265,7 @@ sub do_unarchive_course ($c) {
unarchiveCourse(
newCourseID => $new_courseID,
oldCourseID => $unarchive_courseID =~ s/\.tar\.gz$//r,
archivePath => "$ce->{webworkDirs}{courses}/admin/archives/$unarchive_courseID",
archivePath => "$ce->{webworkDirs}{courses}/$ce->{admin_course_id}/archives/$unarchive_courseID",
ce => $ce,
);

Expand Down
6 changes: 3 additions & 3 deletions lib/WeBWorK/Utils/CourseManagement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Lists the courses which have been archived (end in .tar.gz).

sub listArchivedCourses {
my ($ce) = @_;
my $archivesDir = "$ce->{webworkDirs}{courses}/admin/archives";
my $archivesDir = "$ce->{webworkDirs}{courses}/$ce->{admin_course_id}/archives";
surePathToFile($ce->{webworkDirs}{courses}, "$archivesDir/test"); # Ensure archives directory exists.
return grep {m/\.tar\.gz$/} readDirectory($archivesDir);
}
Expand Down Expand Up @@ -754,7 +754,7 @@ sub archiveCourse {

# tmp_archive_path is used as the target of the tar.gz operation.
# After this is done the final tar.gz file is moved either to the admin course archives directory
# course/admin/archives or the supplied archive_path option if it is present.
# course/$ce->{admin_course_id}/archives or the supplied archive_path option if it is present.
# This prevents us from tarring a directory to which we have just added a file
# see bug #2022 -- for error messages on some operating systems
my $uuidStub = create_uuid_as_string();
Expand All @@ -765,7 +765,7 @@ sub archiveCourse {
if (defined $options{archive_path} && $options{archive_path} =~ /\S/) {
$archive_path = $options{archive_path};
} else {
$archive_path = "$ce->{webworkDirs}{courses}/admin/archives/$courseID.tar.gz";
$archive_path = "$ce->{webworkDirs}{courses}/$ce->{admin_course_id}/archives/$courseID.tar.gz";
surePathToFile($ce->{webworkDirs}{courses}, $archive_path);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/WeBWorK/Utils/Routes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ PLEASE FOR THE LOVE OF GOD UPDATE THIS IF YOU CHANGE THE ROUTES BELOW!!!
root /
course_admin /admin -> logout, options, instructor_tools
course_admin /$ce->{admin_course_id} -> logout, options, instructor_tools
render_rpc /render_rpc
instructor_rpc /instructor_rpc
Expand Down Expand Up @@ -158,7 +158,7 @@ my %routeParameters = (
course_admin => {
title => x('Course Administration'),
module => 'CourseAdmin',
path => '/admin'
path => '/$ce->{admin_course_id}'
},

render_rpc => {
Expand Down
3 changes: 2 additions & 1 deletion lib/WebworkWebservice/CourseActions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ sub createCourse {
die "Course actions disabled by configuration.\n" unless $admin_ce->{webservices}{enableCourseActions};

# Only users from the admin course with appropriate permissions are allowed to create a course.
die "Course creation allowed only for admin course users.\n" unless $admin_ce->{courseName} eq 'admin';
die "Course creation allowed only for admin course users.\n"
unless $admin_ce->{courseName} eq $admin_ce->{admin_course_id};

die "Course ID cannot exceed $admin_ce->{maxCourseIdLength} characters.\n"
if length($params->{name}) > $admin_ce->{maxCourseIdLength};
Expand Down
3 changes: 2 additions & 1 deletion templates/ContentGenerator/Base/admin_links.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
<li class="list-group-item nav-item"><%= $makelink->('options') %></li>
<li><hr class="site-nav-separator"></li>
% if ($authz->hasPermissions($userID, 'create_and_delete_courses')) {
% my $admin_pattern = qr/$ce->{admin_course_id}$/;
<li class="list-group-item nav-item">
<%= $makelink->(
'set_list',
text => maketext('Course Listings'),
active => !param('subDisplay') && $c->url_for =~ /admin$/ ? 1 : 0
active => !param('subDisplay') && $c->url_for =~ $admin_pattern ? 1 : 0
) %>
</li>
% for (
Expand Down
4 changes: 2 additions & 2 deletions templates/ContentGenerator/Base/links.html.ep
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% use WeBWorK::Utils qw(jitar_id_to_seq);
%
% if ($ce->{courseName} eq 'admin') {
% if ($ce->{courseName} eq $ce->{admin_course_id}) {
<%= include 'ContentGenerator/Base/admin_links' =%>
% next;
% }
Expand Down Expand Up @@ -77,7 +77,7 @@
<li class="list-group-item nav-item"><%= $makelink->('options') %></li>
% }
%
% unless ($restricted_navigation || $courseID eq 'admin') {
% unless ($restricted_navigation || $courseID eq $ce->{admin_course_id}) {
<li class="list-group-item nav-item"><%= $makelink->('grades') %></li>
% }
%
Expand Down
2 changes: 1 addition & 1 deletion templates/ContentGenerator/CourseAdmin.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
% my @courseIDs = listCourses($ce);
<ol>
% for (sort { lc($a) cmp lc($b) } listCourses($ce)) {
% next if $_ eq 'admin' || $_ eq 'modelCourse';
% next if $_ eq 'modelCourse';
<li><%= link_to $_ => 'set_list' => { courseID => $_ } =%></li>
% }
</ol>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<%= maketext('To copy the templates and html folders from an existing course, select the course below.') =%>
</div>
<div class="row mb-3">
% my @existingCourses = sort { lc($a) cmp lc($b) } grep { $_ ne stash('courseID') } listCourses($ce);
% my @existingCourses = sort { lc($a) cmp lc($b) } listCourses($ce);
% unshift(@existingCourses, sort { lc($a) cmp lc($b) } @{ $ce->{modelCoursesForCopy} });
%
<%= label_for add_templates_course => maketext('Copy from:'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
% if ($all_tables_ok && $directories_ok) {
% # No missing tables, missing fields, or directories
% # Warn about overwriting an existing archive
% my $archive_path = "$ce2->{webworkDirs}{courses}/admin/archives/$archive_courseID.tar.gz";
% my $archive_path = "$ce2->{webworkDirs}{courses}/$ce2->{admin_course_id}/archives/$archive_courseID.tar.gz";
% if (-e $archive_path && -w $archive_path) {
<p class="text-danger fw-bold">
<%= maketext(
Expand Down
5 changes: 3 additions & 2 deletions templates/ContentGenerator/Home.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
%
% my $coursesDir = $ce->{webworkDirs}{courses};
% my @courseIDs = listCourses($ce);
% my $admin_course_id = $ce->{admin_course_id};
%
<p><%= maketext('Welcome to WeBWorK!') %></p>
%
% if ((grep { $_ eq 'admin' } @courseIDs) && !-f "$coursesDir/admin/hide_directory") {
% if ((grep { $_ eq $admin_course_id } @courseIDs) && !-f "$coursesDir/$admin_course_id/hide_directory") {
<p><%= link_to maketext('Course Administration') => url_for('course_admin') =%></p>
% }
%
<h2><%= maketext('Courses') %></h2>
%
<ul class="courses-list">
% for my $courseID (sort { lc($a) cmp lc($b) } @courseIDs) {
% next if $courseID eq 'admin'; # Already shown above.
% next if $courseID eq $admin_course_id; # Already shown above.
% next if -f "$coursesDir/$courseID/hide_directory";
<li>
<%= link_to $courseID =~ s/_/ /gr => url_for('set_list', courseID => $courseID) =%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
unarchive_text => maketext('Unpack Archive')
},
%button =%>
% unless ($c->{courseName} eq 'admin') {
% unless ($c->{courseName} eq $c->ce->{admin_course_id}) {
<%= submit_button maketext('Archive Course'), id => 'ArchiveCourse', %button =%>
% }
<div class="d-none d-md-block" style="height: 10px"></div>
Expand Down

0 comments on commit 412f927

Please sign in to comment.