From 6820a674f359c79a2e570fc0adf8086e1cbdee01 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Mon, 26 Oct 2026 05:56:39 -0500 Subject: [PATCH 1/2] Fix the problem editor "Open in new window" redirects when there is no set. When the problem editor is opened without a set (for example from the File Manager's "Edit" action), viewing or saving with "Open in new window" checked called `getGlobalSet` with an undefined set id and failed with "argument 1 must contain a set_id". Now the set is only looked up if there is a set id, and the redirect goes to problem 1 of the `Undefined_Set` in that case, as is already done for blank and sample problems. Co-Authored-By: Claude Opus 5.5 --- .../Instructor/PGProblemEditor.pm | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm b/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm index 069d5c6294..3e89d9a408 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm @@ -758,13 +758,17 @@ sub view_handler ($c) { if ($c->{file_type} eq 'problem' || $c->{file_type} eq 'source_path_for_problem_file') { # Redirect to Problem.pm or GatewayQuiz.pm. # We need to know if the set is a gateway set to determine the redirect. - my $globalSet = $c->db->getGlobalSet($c->{setID}); + my $globalSet = $c->{setID} ? $c->db->getGlobalSet($c->{setID}) : undef; $c->authen->flash(status_message => $c->{status_message}->join('')); $c->reply_with_redirect($c->systemLink( defined $globalSet && $globalSet->assignment_type =~ /gateway/ - ? $c->url_for('gateway_quiz', setID => 'Undefined_Set') - : $c->url_for('problem_detail', setID => $c->{setID}, problemID => $c->{problemID}), + ? $c->url_for('gateway_quiz', setID => 'Undefined_Set') + : $c->url_for( + 'problem_detail', + setID => $c->{setID} // 'Undefined_Set', + problemID => $c->{problemID} // 1 + ), params => { displayMode => $displayMode, problemSeed => $problemSeed, @@ -995,13 +999,17 @@ sub save_handler ($c) { if ($c->{file_type} eq 'problem' || $c->{file_type} eq 'source_path_for_problem_file') { # Redirect to Problem.pm or GatewayQuiz.pm. # We need to know if the set is a gateway set to determine the redirect. - my $globalSet = $c->db->getGlobalSet($c->{setID}); + my $globalSet = $c->{setID} ? $c->db->getGlobalSet($c->{setID}) : undef; $c->authen->flash(status_message => $c->{status_message}->join('')); $c->reply_with_redirect($c->systemLink( defined $globalSet && $globalSet->assignment_type =~ /gateway/ - ? $c->url_for('gateway_quiz', setID => 'Undefined_Set') - : $c->url_for('problem_detail', setID => $c->{setID}, problemID => $c->{problemID}), + ? $c->url_for('gateway_quiz', setID => 'Undefined_Set') + : $c->url_for( + 'problem_detail', + setID => $c->{setID} // 'Undefined_Set', + problemID => $c->{problemID} // 1 + ), params => { displayMode => $c->{displayMode}, problemSeed => $c->{problemSeed}, From a372dd072b344aa16281271ba8e3b5e86e96feab Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Mon, 26 Oct 2026 15:54:30 -0500 Subject: [PATCH 2/2] Make the PG problem editor work with a set named "0". Currently most of the checks in the editor will not work for a set named "0" as they are usually just `if $setID`. So switch the checks to `if defined $setId` instead. --- .../ContentGenerator/Instructor/PGProblemEditor.pm | 10 +++++----- .../Instructor/PGProblemEditor/save_as_form.html.ep | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm b/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm index 3e89d9a408..2a9f1cc9e6 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm @@ -318,7 +318,7 @@ sub initialize ($c) { $c->stash->{hardcopyThemesAvailable} = $hardcopyThemesAvailable; $c->{prettyProblemNumber} = $c->{problemID} // ''; - $c->{set} = $c->db->getGlobalSet($c->{setID}) if $c->{setID}; + $c->{set} = $c->db->getGlobalSet($c->{setID}) if defined $c->{setID}; $c->{prettyProblemNumber} = join('.', jitar_id_to_seq($c->{prettyProblemNumber})) if $c->{set} && $c->{set}->assignment_type eq 'jitar'; @@ -354,7 +354,7 @@ sub page_title ($c) { return $c->maketext('Course Information for course [_1]', $c->stash('courseID')) if $c->{file_type} eq 'course_info'; - if ($setID) { + if (defined $setID) { my $set = $c->db->getGlobalSet($setID); if ($set && $set->assignment_type eq 'jitar') { $problemID = join('.', jitar_id_to_seq($problemID)); @@ -758,7 +758,7 @@ sub view_handler ($c) { if ($c->{file_type} eq 'problem' || $c->{file_type} eq 'source_path_for_problem_file') { # Redirect to Problem.pm or GatewayQuiz.pm. # We need to know if the set is a gateway set to determine the redirect. - my $globalSet = $c->{setID} ? $c->db->getGlobalSet($c->{setID}) : undef; + my $globalSet = defined $c->{setID} ? $c->db->getGlobalSet($c->{setID}) : undef; $c->authen->flash(status_message => $c->{status_message}->join('')); $c->reply_with_redirect($c->systemLink( @@ -999,7 +999,7 @@ sub save_handler ($c) { if ($c->{file_type} eq 'problem' || $c->{file_type} eq 'source_path_for_problem_file') { # Redirect to Problem.pm or GatewayQuiz.pm. # We need to know if the set is a gateway set to determine the redirect. - my $globalSet = $c->{setID} ? $c->db->getGlobalSet($c->{setID}) : undef; + my $globalSet = defined $c->{setID} ? $c->db->getGlobalSet($c->{setID}) : undef; $c->authen->flash(status_message => $c->{status_message}->join('')); $c->reply_with_redirect($c->systemLink( @@ -1255,7 +1255,7 @@ sub save_as_handler ($c) { $c->shortPath($outputFilePath) )); $c->addgoodmessage($c->maketext('No changes have been made to set [_1]', $c->{setID})) - if $c->{setID} && $c->{setID} ne 'Undefined_Set'; + if defined $c->{setID} && $c->{setID} ne 'Undefined_Set'; } else { $c->addbadmessage($c->maketext('Unknown saveMode: [_1].', $saveMode)); return; diff --git a/templates/ContentGenerator/Instructor/PGProblemEditor/save_as_form.html.ep b/templates/ContentGenerator/Instructor/PGProblemEditor/save_as_form.html.ep index a73b1e715b..975ad36aaa 100644 --- a/templates/ContentGenerator/Instructor/PGProblemEditor/save_as_form.html.ep +++ b/templates/ContentGenerator/Instructor/PGProblemEditor/save_as_form.html.ep @@ -22,7 +22,7 @@ % % # Don't add to or replace problems in sets or replace set/hardcopy headers if the set is the Undefined_Set or % # if the problem is the blank_problem or a sample problem. -% my $fileIsAssociatedWithSet = $c->{setID} && $c->{setID} ne 'Undefined_Set' && !$isTemplate; +% my $fileIsAssociatedWithSet = defined $c->{setID} && $c->{setID} ne 'Undefined_Set' && !$isTemplate; %