Skip to content

Commit 0ee6cea

Browse files
committed
cleanup
1 parent de9ea6a commit 0ee6cea

3 files changed

Lines changed: 28 additions & 21 deletions

File tree

lib/RenderApp/Controller/Render.pm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ sub parseRequest {
1717
$originIP ||= $c->tx->remote_address || 'unknown-origin';
1818

1919
if ($ENV{STRICT_JWT} && !(defined $params{problemJWT} || defined $params{sessionJWT})) {
20-
$c->exception('Not allowed to request problems with raw data.', 403);
21-
return;
20+
return $c->exception('Not allowed to request problems with raw data.', 403);
2221
}
2322

2423
# protect against DOM manipulation
2524
if (defined $params{submitAnswers} && defined $params{previewAnswers}) {
2625
$c->log->error('Simultaneous submit and preview! JWT: ', $params{problemJWT} // {});
27-
$c->exception('Malformed request.', 400);
28-
return;
26+
return $c->exception('Malformed request.', 400);
2927
}
3028

3129
# TODO: ensure showCorrectAnswers does not appear without showCorrectAnswersButton

lib/WeBWorK/FormatRenderedProblem.pm

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,19 @@ sub formatRenderedProblem {
266266
sub jsonResponse {
267267
my ($rh_result, $inputs_ref, @extra_files) = @_;
268268
return {
269-
($inputs_ref->{isInstructor} ? (answers => $rh_result->{answers}) : ()),
269+
(
270+
$inputs_ref->{isInstructor}
271+
? (
272+
answers => $rh_result->{answers},
273+
inputs => $inputs_ref,
274+
pgcore => {
275+
persist => $rh_result->{PERSISTENCE_HASH},
276+
persist_up => $rh_result->{PERSISTENCE_HASH_UPDATED},
277+
pgah => $rh_result->{PG_ANSWERS_HASH}
278+
}
279+
)
280+
: ()
281+
),
270282
(
271283
$inputs_ref->{includeTags}
272284
? (tags => $rh_result->{tags}, raw_metadata_text => $rh_result->{raw_metadata_text})

lib/WeBWorK/RenderProblem.pm

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ sub process_pg_file {
107107
#######################################################################
108108

109109
sub process_problem {
110-
my ($problem, $inputs_ref) = @_;
110+
my ($problem, $inputs_ref) = @_;
111111

112-
my $source = $problem->{problem_contents};
113-
my $file_path = $inputs_ref->{sourceFilePath} || $inputs_ref->{problemSourceURL};
112+
my $source = $problem->{problem_contents};
113+
my $file_path = $inputs_ref->{sourceFilePath} || $inputs_ref->{problemSourceURL};
114114
my ($raw_metadata_text, $problemUUID);
115115

116116
# TODO: include problemUUID from problemSourceURL and skip this if present
@@ -153,7 +153,7 @@ sub process_problem {
153153
if ($inputs_ref->{previewAnswers}) {
154154
# if this is a preview, leave session unmodified, and no answerJWT
155155
$return_object->{sessionJWT} = $inputs_ref->{sessionJWT};
156-
} else {
156+
} elsif ($inputs_ref->{problemJWT}) {
157157
my ($sessionJWT, $answerJWT) = generateJWTs($return_object, $inputs_ref);
158158
$return_object->{sessionJWT} = $sessionJWT;
159159
$return_object->{answerJWT} = $answerJWT;
@@ -251,10 +251,10 @@ sub standaloneRenderer {
251251
flags => $pg->{flags},
252252
};
253253
if (ref($pg->{pgcore}) eq 'PGcore') {
254-
$ret->{internal_debug_messages} = $pg->{pgcore}->get_internal_debug_messages();
255-
$ret->{warning_messages} = $pg->{pgcore}->get_warning_messages();
256-
$ret->{debug_messages} = $pg->{pgcore}->get_debug_messages();
257-
$ret->{resources} = [ keys %{ $pg->{pgcore}{PG_alias}{resource_list} } ];
254+
$ret->{internal_debug_messages} = $pg->{pgcore}->get_internal_debug_messages();
255+
$ret->{warning_messages} = $pg->{pgcore}->get_warning_messages();
256+
$ret->{debug_messages} = $pg->{pgcore}->get_debug_messages();
257+
# $ret->{resources} = [ keys %{ $pg->{pgcore}{PG_alias}{resource_list} } ];
258258
$ret->{PERSISTENCE_HASH_UPDATED} = $pg->{pgcore}{PERSISTENCE_HASH_UPDATED};
259259
$ret->{PERSISTENCE_HASH} = $pg->{pgcore}{PERSISTENCE_HASH};
260260
$ret->{PG_ANSWERS_HASH} = {
@@ -267,10 +267,10 @@ sub standaloneRenderer {
267267
keys %{ $pg->{pgcore}{PG_ANSWERS_HASH} }
268268
};
269269
# TODO: replace resources after PG merges #1046
270-
# $ret->{resource_list} = {
271-
# map { $_ => $pg->{pgcore}{PG_alias}{resource_list}{$_}{uri} }
272-
# keys %{ $pg->{pgcore}{PG_alias}{resource_list} }
273-
# };
270+
$ret->{resources} = {
271+
map { $_ => $pg->{pgcore}{PG_alias}{resource_list}{$_}{uri} }
272+
keys %{ $pg->{pgcore}{PG_alias}{resource_list} }
273+
};
274274
} else {
275275
$ret->{internal_debug_messages} = ['Problem failed during render - no PGcore received.'];
276276
}
@@ -319,11 +319,8 @@ sub generateJWTs {
319319
}
320320

321321
# store the current answer/response state for each entry
322-
foreach my $ans (keys %{ $scoreHash->{answers} }) {
323-
# TODO: Anything else we want to add to sessionHash?
322+
foreach my $ans (@{ $pg->{flags}{KEPT_EXTRA_ANSWERS} }) {
324323
$sessionHash->{$ans} = $inputs_ref->{$ans};
325-
$sessionHash->{ 'MaThQuIlL_' . $ans } = $inputs_ref->{ 'MaThQuIlL_' . $ans }
326-
if ($inputs_ref->{ 'MaThQuIlL_' . $ans });
327324

328325
# More restructuring -- confirm with LibreTexts
329326
# $scoreHash->{$ans}{student} = { map {exists $answers{$ans}{$_} ? ($studentKeys{$_} => $answers{$ans}{$_}) : ()} keys %studentKeys };

0 commit comments

Comments
 (0)