Skip to content

Commit

Permalink
Wait for render completion before saving tmp file when clicking "Chec…
Browse files Browse the repository at this point in the history
…k Answers" in the PG editor.

It seems that if the problem rendering request does not complete before
the request to save the temporary file is sent, the streams can get
crossed.  We all know how bad that is!

This seems to only occur when proxying hypnotoad in some way or another.
Somehow hypnotoad manages to keep the streams straight when proxying is
not involved.

Also, don't add the `passwd` and `key` to the form when rendering via
the `render_rpc` endpoint unless cookies are disabled for the request,
and in the case that `session_management_via` is "session_cookie" don't
add the key to the form.

This fixes issue openwebwork#2394.
  • Loading branch information
drgrice1 committed Apr 13, 2024
1 parent eaf3bd6 commit 7a9a4e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions htdocs/js/PGProblemEditor/pgproblemeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
if (!problemForm) return;

for (const button of problemForm.querySelectorAll('input[type="submit"]')) {
button.addEventListener('click', (e) => {
button.addEventListener('click', async (e) => {
e.preventDefault();

// FormData does not support the characters in raw problem source. URLSearchParams does.
Expand All @@ -327,7 +327,7 @@
requestData.set(button.name, button.value);
requestData.set('set_id', document.getElementsByName('hidden_set_id')[0]?.value ?? 'Unknown Set');

renderProblem(requestData);
await renderProblem(requestData);

saveTempFile();
});
Expand Down
12 changes: 8 additions & 4 deletions templates/RPCRenderFormats/default.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
% }
%== $LTIGradeMessage
%
% if (stash->{disable_cookies}) {
%= hidden_field disableCookies => $disableCookies
%= hidden_field passwd => $passwd
% }
% if (stash->{disable_cookies} || $ce->{session_management_via} ne 'session_cookie') {
%= hidden_field key => $key
% }
%= hidden_field user => $user
%= hidden_field sourceFilePath => $sourceFilePath
%= hidden_field problemSource => $problemSource
%= hidden_field rawProblemSource => $rawProblemSource
Expand All @@ -77,11 +85,7 @@
%= hidden_field psvn => $psvn
%= hidden_field fileName => $fileName
%= hidden_field courseID => $courseID
%= hidden_field user => $user
%= hidden_field passwd => $passwd
%= hidden_field disableCookies => $disableCookies
%= hidden_field displayMode => $displayMode
%= hidden_field key => $key
%= hidden_field outputformat => $formatName
%= hidden_field theme => $theme
%= hidden_field language => $formLanguage
Expand Down

0 comments on commit 7a9a4e6

Please sign in to comment.