Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 = defined $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',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably over check everything, but sure we don't need to deal with $c->{setID} being the empty string here (and similar below)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fixed now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to ever check $c->{setID} ne '' because that really cannot happen in this module.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the $c->{setID} is set from the route stash value, and it cannot be the empty string.

problemID => $c->{problemID} // 1
),
params => {
displayMode => $displayMode,
problemSeed => $problemSeed,
Expand Down Expand Up @@ -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 = defined $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},
Expand Down Expand Up @@ -1247,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
%
<div>
<div class="row align-items-center mb-2">
Expand Down