Skip to content

Commit 271833f

Browse files
committed
Make Caliper an optionally loaded plugin that interfaces with webwork2 via hooks.
This means that the Caliper code does not need to be directly in the primary webwork2 code, and those that don't use Caliper don't have to even have it checking to see if it is enabled. Just leave the `Mojolicious::WeBWorK::Plugin::Caliper` plugin commented out in `webwork2.mojolicious.yml`. If you want to allow the usage of Caliper on your server, then uncomment that plugin. Caliper can be configured per course in `course.conf` files if the plugin is enabled. This `hook` approach is also extendable. Other plugins, even those not directly in the webwork2 repository could utilize these hooks. The hooks added in this pull request are when user logs in or out, when an answer is submitted in a regular assignment, and when a page change, preview, or submission occurs in a test. Additional hooks could also be added for further extendability with plugins in the future. The `$caliper{base_url}` option no longer exists. Those using Caliper just need to make sure that the `$server_root_url` and `$webwork_url` are set correctly in `site.conf`. The point is that anyone using webwork2 should do that anyway, so the `$caliper{base_url}` setting was redundant. The Caliper packages are heavily updated. The packages all use signatures. Instead of passing both the course environment and database handle everywhere, just pass the controller which has both of those. In addition, doing so gives access to do things better. For example, the environment variable usage (`HTTP_X_FORWARDED_FOR`, `REMOTE_ADDR`, `HTTP_CLIENT_IP`, `HTTP_USER_AGENT`, and `HTTP_HOST` in `Caliper/Entity.pm` and `HTTP_REFERER` in `Caliper/Event.pm`) was clearly broken and not working since the switch to Mojolicious. Since the controller is now available in those places the things those environment variables used to provide with modperl and apache can now be obtained from the controller. `Mojo::UserAgent` is used instead of `HTTP::Async`. This is the only place that the outdated and unmaintained `HTTP::Async` package is used. So drop that dependency. The UUIDs used now use `create_uuid_as_string` from the `UUID::Tiny` package, instead of the `Data::UUID` package and essentially `Data::UUID->new->create_str`. This is done for two reasons. First, this is the only use of this dependency. So that is another dependency not needed by webwork2. Second, the Caliper specification recommends using version 4 UUIDs and `Data::UUID` does not generate version 4 UUIDs, but `UUID::Tiny` does. The problem source is no longer sent in Caliper events. That really should never have been done. That is a large amount of data and is not needed. This means that even those that do not use Caliper have to endure the additional server load required to transmit that back from the rendering process to the main process. It also makes the Caliper events much larger in size than they should be. The source file is still sent and that really should be all that is needed. The source can be looked up in the file. Other than not sending the problem source, everything else sent by the Caliper implementation is the same. So the implementation still meets the 1EdTech Caliper specification as much as it did before (the problem source is certainly not something the specification insists on or is even considered in the specification). See https://www.imsglobal.org/spec/caliper/v1p2.
1 parent c1a3ac1 commit 271833f

16 files changed

Lines changed: 553 additions & 678 deletions

File tree

Dockerfile

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ RUN apt-get update \
109109
libgd-perl \
110110
libhtml-scrubber-perl \
111111
libhtml-template-perl \
112-
libhttp-async-perl \
113112
libio-compress-perl \
114113
libiterator-perl \
115114
libiterator-util-perl \
@@ -133,7 +132,6 @@ RUN apt-get update \
133132
libnet-ip-perl \
134133
libnet-ldap-perl \
135134
libnet-oauth-perl \
136-
libossp-uuid-perl \
137135
libpadwalker-perl \
138136
libpandoc-wrapper-perl \
139137
libpath-class-perl \
@@ -231,18 +229,18 @@ COPY --from=base /opt/base/pg $APP_ROOT/pg
231229
RUN echo "PATH=$PATH:$APP_ROOT/webwork2/bin" >> /root/.bashrc \
232230
&& mkdir /run/webwork2 /etc/ssl/local \
233231
&& cd $APP_ROOT/webwork2/ \
234-
&& chown www-data DATA ../courses logs tmp /etc/ssl/local /run/webwork2 \
235-
&& chmod -R u+w DATA ../courses logs tmp /run/webwork2 /etc/ssl/local \
232+
&& chown www-data DATA ../courses logs tmp /etc/ssl/local /run/webwork2 \
233+
&& chmod -R u+w DATA ../courses logs tmp /run/webwork2 /etc/ssl/local \
236234
&& echo "en_US ISO-8859-1\nen_US.UTF-8 UTF-8" > /etc/locale.gen \
237-
&& /usr/sbin/locale-gen \
238-
&& echo "locales locales/default_environment_locale select en_US.UTF-8\ndebconf debconf/frontend select Noninteractive" > /tmp/preseed.txt \
239-
&& debconf-set-selections /tmp/preseed.txt \
235+
&& /usr/sbin/locale-gen \
236+
&& echo "locales locales/default_environment_locale select en_US.UTF-8\ndebconf debconf/frontend select Noninteractive" > /tmp/preseed.txt \
237+
&& debconf-set-selections /tmp/preseed.txt \
240238
&& rm -f /etc/localtime /etc/timezone && echo "Etc/UTC" > /etc/timezone \
241-
&& dpkg-reconfigure -f noninteractive tzdata \
239+
&& dpkg-reconfigure -f noninteractive tzdata \
242240
&& cd $WEBWORK_ROOT/htdocs \
243-
&& npm install \
241+
&& npm install \
244242
&& cd $PG_ROOT/htdocs \
245-
&& npm install
243+
&& npm install
246244

247245
# ==================================================================
248246
# Phase 7 - Final setup and prepare docker-entrypoint.sh

DockerfileStage1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ RUN apt-get update \
7171
libgd-perl \
7272
libhtml-scrubber-perl \
7373
libhtml-template-perl \
74-
libhttp-async-perl \
7574
libio-compress-perl \
7675
libiterator-perl \
7776
libiterator-util-perl \
@@ -94,7 +93,6 @@ RUN apt-get update \
9493
libnet-ip-perl \
9594
libnet-ldap-perl \
9695
libnet-oauth-perl \
97-
libossp-uuid-perl \
9896
libpadwalker-perl \
9997
libpandoc-wrapper-perl \
10098
libpath-class-perl \

bin/check_modules.pl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ =head1 DESCRIPTION
129129
ubuntu => 'libdata-structure-util-perl'
130130
}
131131
},
132-
'Data::UUID' => {
133-
package => {
134-
ubuntu => 'libossp-uuid-perl',
135-
rhel => 'perl-Data-UUID'
136-
}
137-
},
138132
'Date::Format' => {
139133
package => {
140134
ubuntu => 'libtimedate-perl',
@@ -283,11 +277,6 @@ =head1 DESCRIPTION
283277
rhel => 'perl-HTML-Parser'
284278
}
285279
},
286-
'HTTP::Async' => {
287-
package => {
288-
ubuntu => 'libhttp-async-perl'
289-
}
290-
},
291280
'IO::File' => {
292281
package => {
293282
ubuntu => 'perl-base',

conf/localOverrides.conf.dist

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -721,28 +721,35 @@ $mail{feedbackRecipients} = [
721721
# Webwork Caliper
722722
################################################################################
723723

724-
# enable/disable Caliper for install
725-
#$caliper{enabled} = 0;
726-
# base_url should ideally be hard coded to a persistent url pointing to the webwork root
727-
# (important to keep it consistent over time)
728-
#$caliper{base_url} = 'https://webwork.elearning.ubc.ca/webwork2/';
729-
# LRS endpoint
730-
#$caliper{host} = 'http://caliper.example.host.org/api/endpoint';
724+
# Set this to 1 to enable Caliper. Note that the
725+
# Mojolicious::WeBWorK::Plugin::Caliper plugin must also be enabled in
726+
# conf/webwork2.mojolicous.yml in order for this to work, and all of the
727+
# $caliper settings below must be uncommented and set except the
728+
# $caliper{custom_actor_generator}. Note that this and all of the settings below
729+
# can also be configured per course in the course.conf files.
730+
$caliper{enabled} = 0;
731+
732+
# LRS endpoint to which the Caliper telemetry data will be sent.
733+
#$caliper{host} = 'https://caliper.example.host.org/api/endpoint';
734+
731735
# LRS endpoint Bearer API key
732736
#$caliper{api_key} = '1234567890abcdefg';
733-
# log file for caliper errors
734-
#$caliper{errorlog} = $webworkDirs{logs} . "/caliper_errors.log";
735-
# customized Caliper actor. Useful if persistent identifiers for students are available in WebWork
736-
# $caliper{custom_actor_generator} = sub {
737-
# my ($ce, $db, $user) = @_;
738-
# # set caliper id as needed
739-
# my $caliper_id = 'http://www.ubc.ca/' . $user->user_id();
740-
# return {
741-
# 'id' => $caliper_id,
742-
# 'type' => 'Person',
743-
# 'name' => $user->first_name() . " " . $user->last_name(),
744-
# };
745-
# };
737+
738+
# Log file for caliper errors
739+
#$caliper{errorlog} = "$webworkDirs{logs}/caliper_errors.log";
740+
741+
# Custom Caliper actor generator. This is useful if persistent identifiers for
742+
# students are available in WebWork.
743+
#$caliper{custom_actor_generator} = sub {
744+
# my ($ce, $db, $user) = @_;
745+
# # set caliper id as needed
746+
# my $caliper_id = 'http://yourschool.edu/' . $user->user_id;
747+
# return {
748+
# id => $caliper_id,
749+
# type => 'Person',
750+
# name => $user->first_name . ' ' . $user->last_name,
751+
# };
752+
#};
746753

747754
###############################################################################
748755
# Test settings

conf/webwork2.mojolicious.dist.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,8 @@ hardcopy:
259259
# external websites with usernames and passwords embedded in them such as for
260260
# PreTeXt textbooks.
261261
allow_unsecured_rpc: 0
262+
263+
plugins:
264+
# Uncomment the following to enable Caliper. Also set the Caliper settings in
265+
# localOverrides.conf (or per course in course.conf files).
266+
#- Mojolicious::WeBWorK::Plugin::Caliper: {}

lib/Caliper/Actor.pm

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,25 @@
11
package Caliper::Actor;
2-
3-
##### Library Imports #####
4-
use strict;
5-
use warnings;
6-
use WeBWorK::CourseEnvironment;
7-
use WeBWorK::DB;
8-
use Data::Dumper;
2+
use Mojo::Base -signatures;
93

104
use Caliper::ResourceIri;
115

12-
sub generate_anonymous_actor {
6+
sub generate_default_actor ($c, $user) {
137
return {
14-
'id' => 'http://purl.imsglobal.org/caliper/Person',
15-
'type' => 'Person',
8+
id => Caliper::ResourceIri->new($c->ce)->actor_homepage($user->user_id),
9+
type => 'Person',
10+
name => $user->first_name . ' ' . $user->last_name
1611
};
1712
}
1813

19-
sub generate_default_actor {
20-
my ($ce, $db, $user) = @_;
21-
my $resource_iri = Caliper::ResourceIri->new($ce);
22-
23-
return {
24-
'id' => $resource_iri->actor_homepage($user->user_id()),
25-
'type' => 'Person',
26-
'name' => $user->first_name() . " " . $user->last_name(),
27-
};
28-
}
14+
sub generate_actor ($c, $user_id) {
15+
return { id => 'http://purl.imsglobal.org/caliper/Person', type => 'Person' } unless defined $user_id;
2916

30-
sub generate_actor {
31-
my ($ce, $db, $user_id) = @_;
17+
my $user = $c->db->getUser($user_id);
3218

33-
if (!defined($user_id)) {
34-
return Caliper::Entity::generate_anonymous_actor();
35-
} else {
36-
my $user = $db->getUser($user_id);
19+
return $c->ce->{caliper}{custom_actor_generator}($c->ce, $c->db, $user)
20+
if ref $c->ce->{caliper}{custom_actor_generator} eq 'CODE';
3721

38-
if (defined($ce->{caliper}{custom_actor_generator})) {
39-
return $ce->{caliper}{custom_actor_generator}($ce, $db, $user);
40-
} else {
41-
return generate_default_actor($ce, $db, $user);
42-
}
43-
}
22+
return generate_default_actor($c, $user);
4423
}
4524

4625
1;

0 commit comments

Comments
 (0)