Skip to content

Commit a032bd4

Browse files
committed
when updating courses, check for standard sylminks
1 parent b9aa3b8 commit a032bd4

File tree

7 files changed

+203
-60
lines changed

7 files changed

+203
-60
lines changed

conf/defaults.config

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,43 @@ $webworkURLs{AuthorHelpURL} ='https://webwork.maa.org/wiki/Category:Au
360360
# <link rel="stylesheet" type="text/css" href="<!--#url type="webwork" name="htdocs"-->/css/math.css"/>
361361

362362
################################################################################
363-
# Defaults for course-specific locations (directories and URLs)
363+
# Problem library options
364+
################################################################################
365+
#
366+
# The problemLibrary configuration data should now be set in localOverrides.conf
367+
368+
# For configuration instructions, see:
369+
# https://webwork.maa.org/wiki/Open_Problem_Library
370+
# The directory containing the open problem library files.
371+
# Set the root to "" if no problem
372+
373+
#RE-CONFIGURE problemLibrary values in localOverrides.conf
374+
# if these defaults are not correct.
375+
#################################################
376+
$problemLibrary{root} = "/opt/webwork/libraries/webwork-open-problem-library/OpenProblemLibrary";
377+
$contribLibrary{root} = "/opt/webwork/libraries/webwork-open-problem-library/Contrib";
378+
$problemLibrary{version} = "2.5";
379+
###########################################################
380+
381+
# Problem Library SQL database connection information
382+
$problemLibrary_db = {
383+
dbsource => $database_dsn,
384+
user => $database_username,
385+
passwd => $database_password,
386+
storage_engine => 'MYISAM',
387+
};
388+
389+
$problemLibrary{tree} = 'library-directory-tree.json';
390+
391+
# These flags control if statistics on opl problems are shown in the library
392+
# browser. If you want to include local statistics you will need to
393+
# run webwork2/bin/update-OPL-statistics on a regular basis.
394+
$problemLibrary{showLibraryLocalStats} = 1;
395+
# This flag controls whether global statistics will be displayed
396+
$problemLibrary{showLibraryGlobalStats} = 1;
397+
398+
################################################################################
399+
# Defaults for course-specific locations (directories, URLs, and links)
364400
################################################################################
365401

366402
# The root directory of the current course. (The ID of the current course is
@@ -412,6 +448,12 @@ $courseDirs{tmpEditFileDir} = "$courseDirs{templates}/tmpEdit";
412448
# mail merge status directory
413449
$courseDirs{mailmerge} = "$courseDirs{DATA}/mailmerge";
414450

451+
# course links that are regulated by webwork2
452+
$courseLinks{Library} = [$problemLibrary{root}, "$courseDirs{templates}/Library"];
453+
$courseLinks{Contrib} = [$contribLibrary{root}, "$courseDirs{templates}/Contrib"];
454+
$courseLinks{capaLibrary} = ["$contribLibrary{root}/CAPA", "$courseDirs{templates}/capaLibrary"];
455+
$courseLinks{Student_Orientation} = ["$webworkDirs{assets}/pg/Student_Orientation", "$courseDirs{templates}/Student_Orientation"];
456+
415457
################################################################################
416458
# System-wide files
417459
################################################################################
@@ -589,42 +631,6 @@ $default_status = "Enrolled";
589631

590632
$maxCourseIdLength = 40;
591633

592-
################################################################################
593-
# Problem library options
594-
################################################################################
595-
#
596-
# The problemLibrary configuration data should now be set in localOverrides.conf
597-
598-
# For configuration instructions, see:
599-
# https://webwork.maa.org/wiki/Open_Problem_Library
600-
# The directory containing the open problem library files.
601-
# Set the root to "" if no problem
602-
603-
#RE-CONFIGURE problemLibrary values in localOverrides.conf
604-
# if these defaults are not correct.
605-
#################################################
606-
$problemLibrary{root} = "/opt/webwork/libraries/webwork-open-problem-library/OpenProblemLibrary";
607-
$contribLibrary{root} = "/opt/webwork/libraries/webwork-open-problem-library/Contrib";
608-
$problemLibrary{version} = "2.5";
609-
###########################################################
610-
611-
# Problem Library SQL database connection information
612-
$problemLibrary_db = {
613-
dbsource => $database_dsn,
614-
user => $database_username,
615-
passwd => $database_password,
616-
storage_engine => 'MYISAM',
617-
};
618-
619-
$problemLibrary{tree} = 'library-directory-tree.json';
620-
621-
# These flags control if statistics on opl problems are shown in the library
622-
# browser. If you want to include local statistics you will need to
623-
# run webwork2/bin/update-OPL-statistics on a regular basis.
624-
$problemLibrary{showLibraryLocalStats} = 1;
625-
# This flag controls whether global statistics will be displayed
626-
$problemLibrary{showLibraryGlobalStats} = 1;
627-
628634
################################################################################
629635
# Logs
630636
################################################################################

lib/WeBWorK/ContentGenerator/CourseAdmin.pm

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use WeBWorK::Utils::CourseManagement qw(addCourse renameCourse retitleCourse del
2020
unarchiveCourse initNonNativeTables);
2121
use WeBWorK::Utils::Logs qw(writeLog);
2222
use WeBWorK::Utils::CourseDBIntegrityCheck;
23-
use WeBWorK::Utils::CourseDirectoryIntegrityCheck qw(checkCourseDirectories updateCourseDirectories);
23+
use WeBWorK::Utils::CourseDirectoryIntegrityCheck qw(checkCourseDirectories checkCourseLinks updateCourseDirectories);
2424
use WeBWorK::DB;
2525

2626
sub pre_header_initialize ($c) {
@@ -504,8 +504,9 @@ sub rename_course_confirm ($c) {
504504
($tables_ok, $dbStatus) = $CIchecker->checkCourseTables($rename_oldCourseID);
505505
}
506506

507-
# Check directories
507+
# Check directories and links
508508
my ($directories_ok, $directory_report) = checkCourseDirectories($ce2);
509+
my ($links_ok, $link_report) = checkCourseLinks($ce2);
509510

510511
return $c->include(
511512
'ContentGenerator/CourseAdmin/rename_course_confirm',
@@ -514,6 +515,8 @@ sub rename_course_confirm ($c) {
514515
dbStatus => $dbStatus,
515516
directory_report => $directory_report,
516517
directories_ok => $directories_ok,
518+
link_report => $link_report,
519+
links_ok => $links_ok,
517520
rename_oldCourseTitle => $rename_oldCourseTitle,
518521
change_course_title_str => $change_course_title_str,
519522
rename_oldCourseInstitution => $rename_oldCourseInstitution,
@@ -967,9 +970,10 @@ sub archive_course_confirm ($c) {
967970
($tables_ok, $dbStatus) = $CIchecker->checkCourseTables($archive_courseID);
968971
}
969972

970-
# Update and check directories.
973+
# Update and check directories and links.
971974
my $dir_update_messages = $c->param('upgrade_course_tables') ? updateCourseDirectories($ce2) : [];
972975
my ($directories_ok, $directory_report) = checkCourseDirectories($ce2);
976+
my ($links_ok, $link_report) = checkCourseLinks($ce2);
973977

974978
return $c->include(
975979
'ContentGenerator/CourseAdmin/archive_course_confirm',
@@ -980,6 +984,8 @@ sub archive_course_confirm ($c) {
980984
dir_update_messages => $dir_update_messages,
981985
directory_report => $directory_report,
982986
directories_ok => $directories_ok,
987+
link_report => $link_report,
988+
links_ok => $links_ok,
983989
archive_courseID => $archive_courseID,
984990
archive_courseIDs => \@archive_courseIDs
985991
);
@@ -1408,7 +1414,7 @@ sub upgrade_course_confirm ($c) {
14081414
);
14091415
}
14101416

1411-
# Report on directory status
1417+
# Report on directory and link status
14121418
my ($directories_ok, $directory_report) = checkCourseDirectories($ce2);
14131419
push(@$course_output, $c->tag('div', class => 'mb-2', $c->maketext('Directory structure:')));
14141420
push(
@@ -1439,6 +1445,35 @@ sub upgrade_course_confirm ($c) {
14391445
)
14401446
);
14411447

1448+
my ($links_ok, $link_report) = checkCourseLinks($ce2);
1449+
push(@$course_output, $c->tag('div', class => 'mb-2', $c->maketext('Link structure:')));
1450+
push(
1451+
@$course_output,
1452+
$c->tag(
1453+
'ul',
1454+
$c->c(
1455+
map {
1456+
$c->tag(
1457+
'li',
1458+
$c->c("$_->[0]: ",
1459+
$c->tag('span', class => $_->[3] ? 'text-success' : 'text-danger', $_->[2]))
1460+
->join('')
1461+
)
1462+
} @$link_report
1463+
)->join('')
1464+
)
1465+
);
1466+
push(
1467+
@$course_output,
1468+
$links_ok ? $c->tag('p', class => 'text-success mb-0', $c->maketext('Link structure is ok')) : $c->tag(
1469+
'p',
1470+
class => 'text-danger mb-0',
1471+
$c->maketext(
1472+
'Link structure is missing links, or the webserver lacks sufficient privileges, or links point to the wrong place.'
1473+
)
1474+
)
1475+
);
1476+
14421477
push(@$status_output, $c->tag('div', class => 'border border-dark rounded p-2 mb-2', $course_output->join('')));
14431478
}
14441479

@@ -1539,9 +1574,10 @@ sub do_upgrade_course ($c) {
15391574
);
15401575
}
15411576

1542-
# Add missing directories and prepare report on directory status
1577+
# Add missing directories/links and prepare report on directory/link status
15431578
my $dir_update_messages = updateCourseDirectories($ce2); # Needs more error messages
15441579
my ($directories_ok, $directory_report) = checkCourseDirectories($ce2);
1580+
my ($links_ok, $link_report) = checkCourseLinks($ce2);
15451581

15461582
# Show status
15471583
my $course_report = $c->c;
@@ -1552,7 +1588,7 @@ sub do_upgrade_course ($c) {
15521588

15531589
push(@$course_report, @$db_report);
15541590

1555-
# Show report on directory status
1591+
# Show report on directory and link status
15561592
push(
15571593
@$course_report,
15581594
$c->tag('div', class => 'mb-2', $c->maketext('Directory structure:')),
@@ -1593,6 +1629,45 @@ sub do_upgrade_course ($c) {
15931629
'Directory structure is missing directories or the webserver lacks sufficient privileges.')
15941630
)
15951631
);
1632+
push(
1633+
@$course_report,
1634+
$c->tag('div', class => 'mb-2', $c->maketext('Link structure:')),
1635+
$c->tag(
1636+
'ul',
1637+
$c->c(
1638+
map {
1639+
$c->tag(
1640+
'li',
1641+
$c->c("$_->[0]: ",
1642+
$c->tag('span', class => $_->[3] ? 'text-success' : 'text-danger', $_->[2]))
1643+
->join('')
1644+
)
1645+
} @$link_report
1646+
)->join('')
1647+
),
1648+
#$c->tag(
1649+
# 'ul',
1650+
# $c->c(
1651+
# map {
1652+
# $c->tag(
1653+
# 'li',
1654+
# $c->tag(
1655+
# 'span',
1656+
# class => $_->[1] ? 'text-success' : 'text-danger',
1657+
# $_->[0]
1658+
# )
1659+
# )
1660+
# } @$dir_update_messages
1661+
# )->join('')
1662+
#),
1663+
$links_ok ? $c->tag('p', class => 'text-success mb-0', $c->maketext('Link structure is ok')) : $c->tag(
1664+
'p',
1665+
class => 'text-danger mb-0',
1666+
$c->maketext(
1667+
'Link structure is missing links, or the webserver lacks sufficient privileges, or links point to the wrong place.'
1668+
)
1669+
)
1670+
);
15961671
push(@$output, $c->tag('div', class => 'border border-dark rounded p-2 mb-2', $course_report->join('')));
15971672
}
15981673

lib/WeBWorK/Utils/CourseDirectoryIntegrityCheck.pm

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use warnings;
1313

1414
use Mojo::File qw(path);
1515

16-
our @EXPORT_OK = qw(checkCourseDirectories updateCourseDirectories);
16+
our @EXPORT_OK = qw(checkCourseDirectories checkCourseLinks updateCourseDirectories);
1717

1818
# Developer note: This file should not format messages in html. Instead return an array of tuples. Each tuple should
1919
# contain the message components, and the last element of the tuple should be 0 or 1 to indicate failure or success
@@ -48,6 +48,29 @@ sub checkCourseDirectories {
4848
return ($directories_ok, \@results);
4949
}
5050

51+
sub checkCourseLinks {
52+
my $ce = shift;
53+
54+
my @results;
55+
my $links_ok = 1;
56+
57+
for my $link (sort keys %{ $ce->{courseLinks} }) {
58+
my ($path, $label) = @{ $ce->{courseLinks}{$link} };
59+
60+
my $isLink = (-l $label ? 1 : 0);
61+
my $status = -e $label ? (-r $label ? 'r' : '-') . (-w _ ? 'w' : '-') . (-x _ ? 'x' : '-') : 'missing';
62+
my $goodPath = path($label)->realpath eq $path;
63+
64+
# All links should be readable and executable, not writeable.
65+
my $good = $isLink && ($status eq 'r-x') && $goodPath;
66+
$links_ok = 0 if !$good;
67+
68+
push @results, [ $link, $path, $label, $good ];
69+
}
70+
71+
return ($links_ok, \@results);
72+
}
73+
5174
=head2 updateCourseDirectories
5275
5376
Usage: C<< updateCourseDirectories($ce) >>

lib/WeBWorK/Utils/CourseManagement.pm

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ use constant { # constants describing the comparison of two hashes.
4747
};
4848
################################################################################
4949

50-
# checkCourseTables
51-
# updateCourseTables
52-
# checkCourseDirectories
53-
5450
=head1 FUNCTIONS
5551
5652
=over

templates/ContentGenerator/CourseAdmin/archive_course_confirm.html.ep

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,27 @@
7474
<%= maketext('Directory structure is missing directories or the webserver lacks sufficient privileges.') =%>
7575
</p>
7676
% }
77+
% # Report on links
78+
<h3>Link structure</h3>
79+
<ul>
80+
% for (@$link_report) {
81+
<li><%= $_->[0] %>: <span class="<%= $_->[3] ? 'text-success' : 'text-danger' %>"><%= $_->[2] %></span></li>
82+
% }
83+
</ul>
84+
<ul>
85+
% for (@$dir_update_messages) {
86+
<li><span class="<%= $_->[1] ? 'text-success' : 'text-danger' %>"><%= $_->[0] %></span></li>
87+
% }
88+
</ul>
89+
% if ($links_ok) {
90+
<p class="text-success"><%= maketext('Link structure is ok') %></p>
91+
% } else {
92+
<p class="text-danger fw-bold">
93+
<%= maketext(
94+
'Link structure is missing links, or the webserver lacks sufficient privileges, '
95+
. 'or links point to the wrong place.') =%>
96+
</p>
97+
% }
7798
<hr>
7899
% if ($all_tables_ok && param('delete_course')) {
79100
<p class="text-danger fw-bold">
@@ -92,8 +113,8 @@
92113
<%= hidden_field archive_courseIDs => $_ =%>
93114
% }
94115
%
95-
% if ($all_tables_ok && $directories_ok) {
96-
% # No missing tables, missing fields, or directories
116+
% if ($all_tables_ok && $directories_ok && $links_ok) {
117+
% # No missing tables, missing fields, missing directories, or missing/bad links
97118
% # Warn about overwriting an existing archive
98119
% my $archive_path = "$ce2->{webworkDirs}{courses}/$ce2->{admin_course_id}/archives/$archive_courseID.tar.gz";
99120
% if (-e $archive_path && -w $archive_path) {
@@ -115,7 +136,7 @@
115136
% }
116137
<%= submit_button maketext('Archive'), name => 'confirm_archive_course', class => 'btn btn-primary' =%>
117138
</div>
118-
% } elsif ($directories_ok) {
139+
% } elsif ($directories_ok && $links_ok) {
119140
<div class="d-flex justify-content-center gap-2">
120141
<%= submit_button maketext(q{Don't Archive}),
121142
name => 'decline_archive_course', class => 'btn btn-primary' =%>
@@ -124,12 +145,12 @@
124145
</div>
125146
% } else {
126147
<div class="text-center alert alert-danger p-1 mb-2">
127-
<%= maketext('Directory structure needs to be repaired manually before archiving.') =%>
148+
<%= maketext('Directory and/or link structure needs to be repaired manually before archiving.') =%>
128149
</div>
129150
<div class="d-flex justify-content-center gap-2">
130151
<%= submit_button maketext(q{Don't Archive}),
131152
name => 'decline_archive_course', class => 'btn btn-primary' =%>
132-
<%= submit_button maketext('Attempt to upgrade directories'),
153+
<%= submit_button maketext('Attempt to upgrade directories and links'),
133154
name => 'upgrade_course_tables', class => 'btn btn-primary' =%>
134155
</div>
135156
% }

0 commit comments

Comments
 (0)