Skip to content

Commit 02ac4c8

Browse files
authored
Merge pull request #2295 from Alex-Jordan/custom-admin
allow customization of admin course ID
2 parents a20d534 + 7ad3968 commit 02ac4c8

File tree

17 files changed

+39
-24
lines changed

17 files changed

+39
-24
lines changed

bin/update-OPL-statistics.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ BEGIN
111111
print "\n";
112112
}
113113

114-
next if $courseID eq 'admin' || $courseID eq 'modelCourse';
114+
next if $courseID eq $ce->{admin_course_id} || $courseID eq 'modelCourse';
115115

116116
# we extract the identifying information of the problem,
117117
# the status, attempted flag, number of attempts.

bin/upgrade_admin_db.pl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ BEGIN
3131
##########################
3232
# update admin course
3333
##########################
34-
my $upgrade_courseID = 'admin';
35-
36-
my $ce = WeBWorK::CourseEnvironment->new({
34+
my $ce = WeBWorK::CourseEnvironment->new({ webwork_dir => $ENV{WEBWORK_ROOT} });
35+
my $upgrade_courseID = $ce->{admin_course_id};
36+
$ce = WeBWorK::CourseEnvironment->new({
3737
webwork_dir => $ENV{WEBWORK_ROOT},
3838
courseName => $upgrade_courseID,
3939
});

conf/site.conf.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ $server_root_url = '';
6868
# Be sure to use single quotes for the address or the @ sign will be interpreted as an array.
6969
$webwork_server_admin_email = '';
7070

71+
# The following is the name of the admin course where admin level users can create
72+
# courses, delete courses, and more. It is named 'admin' by default but for security,
73+
# you may want to change to something that cannot be guessed. While installing WeBWorK,
74+
# leave this as 'admin'. Once everything is running well, use the 'admin' course to
75+
# create a new course to serve as the admin course. You may need to copy all archives
76+
# from the 'admin' course into this new course. Then change $admin_course_id to the ID
77+
# of the new course and restart webwork2. You may then also want to archive and delete
78+
# the original 'admin' course.
79+
$admin_course_id = 'admin';
80+
7181
# password strings (or any other string allowing special characters) should be specified inside single quotes
7282
# otherwise a string such as "someone@nowhere" will interpolate the contents of the array @nowhere -- which is probably
7383
# empty, but still not what you want. Similar things happen with % and $

lib/Mojolicious/WeBWorK.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ sub startup ($app) {
249249
$cg_r->get('/')->to('Home#go')->name('root');
250250

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

254255
setup_content_generator_routes($cg_r);
255256

lib/WeBWorK.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ async sub dispatch ($c) {
197197
198198
return (0, 'This course does not exist.')
199199
unless (-e $ce->{courseDirs}{root}
200-
|| -e "$ce->{webwork_courses_dir}/admin/archives/$routeCaptures{courseID}.tar.gz");
200+
|| -e "$ce->{webwork_courses_dir}/$ce->{admin_course_id}/archives/$routeCaptures{courseID}.tar.gz");
201201
return (0, 'This course has been archived and closed.') unless -e $ce->{courseDirs}{root};
202202
203203
debug("...we can create a database object...\n");

lib/WeBWorK/Authz.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ sub hasPermissions {
263263
# Elevate all permissions greater than a student in the admin course to the
264264
# create_and_delete_courses level. This way a user either has access to all
265265
# or only student level permissions tools in the admin course.
266-
if (defined($ce->{courseName}) && $ce->{courseName} eq 'admin') {
266+
if (defined($ce->{courseName}) && $ce->{courseName} eq $ce->{admin_course_id}) {
267267
my $admin_permlevel = $userRoles->{ $permissionLevels->{create_and_delete_courses} };
268268
$role_permlevel = $admin_permlevel
269269
if $role_permlevel > $userRoles->{student} && $role_permlevel < $admin_permlevel;

lib/WeBWorK/ContentGenerator/CourseAdmin.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ sub do_add_course ($c) {
322322
for my $userID ($db->listUsers) {
323323
if ($userID eq $add_initial_userID) {
324324
$c->addbadmessage($c->maketext(
325-
'User "[_1]" will not be copied from admin course as it is the initial instructor.', $userID
325+
'User "[_1]" will not be copied from [_2] course as it is the initial instructor.', $userID,
326+
$ce->{admin_course_id}
326327
));
327328
next;
328329
}
@@ -1264,7 +1265,7 @@ sub do_unarchive_course ($c) {
12641265
unarchiveCourse(
12651266
newCourseID => $new_courseID,
12661267
oldCourseID => $unarchive_courseID =~ s/\.tar\.gz$//r,
1267-
archivePath => "$ce->{webworkDirs}{courses}/admin/archives/$unarchive_courseID",
1268+
archivePath => "$ce->{webworkDirs}{courses}/$ce->{admin_course_id}/archives/$unarchive_courseID",
12681269
ce => $ce,
12691270
);
12701271

lib/WeBWorK/Utils/CourseManagement.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Lists the courses which have been archived (end in .tar.gz).
132132

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

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

lib/WeBWorK/Utils/Routes.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PLEASE FOR THE LOVE OF GOD UPDATE THIS IF YOU CHANGE THE ROUTES BELOW!!!
2626
2727
root /
2828
29-
course_admin /admin -> logout, options, instructor_tools
29+
course_admin /$ce->{admin_course_id} -> logout, options, instructor_tools
3030
3131
render_rpc /render_rpc
3232
instructor_rpc /instructor_rpc
@@ -160,7 +160,7 @@ my %routeParameters = (
160160
course_admin => {
161161
title => x('Course Administration'),
162162
module => 'CourseAdmin',
163-
path => '/admin'
163+
path => '/$ce->{admin_course_id}'
164164
},
165165

166166
render_rpc => {

lib/WebworkWebservice/CourseActions.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ sub createCourse {
4040
die "Course actions disabled by configuration.\n" unless $admin_ce->{webservices}{enableCourseActions};
4141

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

4546
die "Course ID cannot exceed $admin_ce->{maxCourseIdLength} characters.\n"
4647
if length($params->{name}) > $admin_ce->{maxCourseIdLength};

0 commit comments

Comments
 (0)