Skip to content

Commit 10abd79

Browse files
committed
Add warning when view open test of user and can submit answers.
Viewing an open gateway test while acting as a student with the permission to submit answers for that student is dangerous since the user's answers will be saved over the student's answers. In this case, give a warning to the user about the danger and suggest they disable the permission to submit answers as students before viewing the open test version, unless they plan to submit answers for that student. The warning will only appear when they first view the test version unless they back out of the test version loosing the hidden `submit_for_student_ok` parameter.
1 parent 8a50103 commit 10abd79

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

lib/WeBWorK/ContentGenerator/GatewayQuiz.pm

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ async sub pre_header_initialize ($c) {
545545
$authz->hasPermissions($userID, 'record_answers_when_acting_as_student')
546546
|| $authz->hasPermissions($userID, 'create_new_set_version_when_acting_as_student')
547547
)
548-
&& $c->param('createnew_ok')
548+
&& $c->param('submit_for_student_ok')
549549
)
550550
)
551551
)
@@ -618,15 +618,16 @@ async sub pre_header_initialize ($c) {
618618
. 'the "Create New Test Version" button below. Alternatively, click "Cancel".',
619619
$effectiveUserID
620620
);
621-
$c->{invalidVersionCreation} = 1;
621+
$c->{invalidVersionCreation} = 1;
622+
$c->{confirmSubmitForStudent} = 1;
622623

623624
} elsif ($effectiveUserID ne $userID) {
624625
$c->{invalidSet} = $c->maketext(
625626
'You are acting as user [_1], and do not have the permission to create a new test version '
626627
. 'when acting as another user.',
627628
$effectiveUserID
628629
);
629-
$c->{invalidVersionCreation} = 2;
630+
$c->{invalidVersionCreation} = 1;
630631

631632
} elsif (($maxAttemptsPerVersion == 0 || $currentNumAttempts < $maxAttemptsPerVersion)
632633
&& $c->submitTime < $set->due_date() + $ce->{gatewayGracePeriod})
@@ -659,6 +660,23 @@ async sub pre_header_initialize ($c) {
659660
{
660661
if (between($set->open_date(), $set->due_date() + $ce->{gatewayGracePeriod}, $c->submitTime)) {
661662
$versionIsOpen = 1;
663+
664+
# If acting as another user, then the user has permissions to record answers for the
665+
# student which is dangerous for open test versions. Give a warning unless the user
666+
# has already confirmed they understand the risk.
667+
if ($effectiveUserID ne $userID && !$c->param('submit_for_student_ok')) {
668+
$c->{invalidSet} = $c->maketext(
669+
'You are trying to view an open test version for [_1] and have the permission to submit '
670+
. 'answers for that user. This is dangerous, as your answers can overwrite the '
671+
. q/student's answers as you move between test pages, preview, or check answers. /
672+
. 'If you are planing to submit answers for this student, click "View Test Version" '
673+
. 'below to continue. If you only want to view the test version, click "Cancel" '
674+
. 'below, then disable the permission to record answers when acting as a student '
675+
. 'before viewing open test versions.',
676+
$effectiveUserID
677+
);
678+
$c->{confirmSubmitForStudent} = 1;
679+
}
662680
}
663681
}
664682
}

templates/ContentGenerator/GatewayQuiz.html.ep

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,33 @@
6868
% # If the set or problem is invalid, then show that information and exit.
6969
% if ($c->{invalidSet}) {
7070
<div class="alert alert-danger mb-2">
71-
<div class="mb-2">
72-
% if ($c->{invalidVersionCreation}) {
73-
<%= maketext(
74-
'The selected test ([_1]) is not a valid test for [_2] (acted as by [_3]).',
75-
$setID, $effectiveUserID, $userID
76-
) =%>
77-
% } else {
78-
<%= maketext(
79-
'The selected test ([_1]) is not a valid test for [_2].',
80-
$setID, $effectiveUserID
81-
) =%>
82-
% }
83-
</div>
71+
% if (!$c->{confirmSubmitForStudent} || $c->{invalidVersionCreation}) {
72+
<div class="mb-2">
73+
% if ($c->{invalidVersionCreation}) {
74+
<%= maketext(
75+
'The selected test ([_1]) is not a valid test for [_2] (acted as by [_3]).',
76+
$setID, $effectiveUserID, $userID
77+
) =%>
78+
% } else {
79+
<%= maketext(
80+
'The selected test ([_1]) is not a valid test for [_2].',
81+
$setID, $effectiveUserID
82+
) =%>
83+
% }
84+
</div>
85+
% }
8486
<div><%= $c->{invalidSet} %></div>
85-
% if ($c->{invalidVersionCreation} && $c->{invalidVersionCreation} == 1) {
87+
% if ($c->{confirmSubmitForStudent}) {
8688
<div class="mt-3">
87-
<%= link_to maketext('Create New Test Version') => $c->systemLink(
89+
<%= link_to $c->{invalidVersionCreation}
90+
? maketext('Create New Test Version') : maketext('View Test Version') => $c->systemLink(
8891
url_for,
89-
params => { effectiveUser => $effectiveUserID, user => $userID, createnew_ok => 1 }
92+
params => { effectiveUser => $effectiveUserID, user => $userID, submit_for_student_ok => 1 }
9093
),
9194
class => 'btn btn-primary'
9295
=%>
9396
<%= link_to maketext('Cancel') => $c->systemLink(
94-
url_for('problem_list', setID => $setID),
97+
url_for('problem_list', setID => $setID =~ s/,v\d+$//r),
9598
params => { effectiveUser => $effectiveUserID, user => $userID }
9699
),
97100
class => 'btn btn-primary'
@@ -410,6 +413,10 @@
410413
<%= hidden_field newPage => '' =%>
411414
<%= hidden_field currentPage => $pageNumber =%>
412415
% }
416+
% # Keep track that a user has confirmed it is okay to submit for a student.
417+
% if (param('submit_for_student_ok')) {
418+
<%= hidden_field submit_for_student_ok => 1 =%>
419+
% }
413420
%
414421
% # Set up links between problems and, for multi-page tests, pages.
415422
% for my $i (0 .. $#$pg_results) {

0 commit comments

Comments
 (0)