@@ -46,7 +46,7 @@ use warnings;
4646use Carp qw/ croak/ ;
4747
4848use WeBWorK::Utils::DateTime qw( before) ;
49- use WeBWorK::Utils::Sets qw( is_restricted ) ;
49+ use WeBWorK::Utils::Sets qw( restricted_set_message ) ;
5050use WeBWorK::Authen::Proctor;
5151use Net::IP;
5252use Scalar::Util qw( weaken) ;
@@ -414,34 +414,35 @@ sub checkSet {
414414 # Cache the set for future use as needed. This should probably be more sophisticated than this.
415415 $self -> {merged_set } = $set ;
416416
417+ # Save restricted set messages to show to instructors if they exist.
418+ my $canViewUnopened = $self -> hasPermissions($userName , " view_unopened_sets" );
419+ my @restrictedSetMessages ;
420+
417421 # Now we know that the set is assigned to the appropriate user.
418- # Check to see if the user is trying to access a set that is not open.
419- if (
420- before($set -> open_date)
421- && !$self -> hasPermissions($userName , " view_unopened_sets" )
422- && !(
423- defined $set -> assignment_type
424- && $set -> assignment_type =~ / gateway/
425- && $node_name eq ' problem_list'
426- && $db -> countSetVersions($effectiveUserName , $set -> set_id)
427- )
428- )
429- {
430- return $c -> maketext(" Requested set '[_1]' is not yet open." , $setName );
431- }
422+ # $c->{viewSetCheck} is used to configure what is shown on ProblemSet page.
432423
433424 # Check to make sure that the set is visible, and that the user is allowed to view hidden sets.
434425 my $visible = $set && $set -> visible ne ' 0' && $set -> visible ne ' 1' ? 1 : $set -> visible;
435426 if (!$visible && !$self -> hasPermissions($userName , " view_hidden_sets" )) {
427+ $c -> {viewSetCheck } = ' hidden' ;
428+ return $c -> maketext(" Requested set '[_1]' is not available." , $setName );
429+ }
430+
431+ # Check to see if the user is trying to access a set that is not open.
432+ if (before($set -> open_date) && !$canViewUnopened ) {
433+ $c -> {viewSetCheck } = ' not-open' ;
436434 return $c -> maketext(" Requested set '[_1]' is not available yet." , $setName );
437435 }
438436
439437 # Check to see if conditional release conditions have been met.
440- if ($ce -> {options }{enableConditionalRelease }
441- && is_restricted($db , $set , $effectiveUserName )
442- && !$self -> hasPermissions($userName , " view_unopened_sets" ))
443- {
444- return $c -> maketext(" The prerequisite conditions have not been met for set '[_1]'." , $setName );
438+ my $conditional_msg = restricted_set_message($c , $set , ' conditional' );
439+ if ($conditional_msg ) {
440+ if ($canViewUnopened ) {
441+ push (@restrictedSetMessages , $conditional_msg );
442+ } else {
443+ $c -> {viewSetCheck } = ' restricted' ;
444+ return $conditional_msg ;
445+ }
445446 }
446447
447448 # Check to be sure that gateways are being sent to the correct content generator.
@@ -474,25 +475,27 @@ sub checkSet {
474475
475476 # Check for ip restrictions.
476477 my $badIP = $self -> invalidIPAddress($set );
477- return $badIP if $badIP ;
478-
479- # If LTI grade passback is enabled and set to 'homework' mode then we need to make sure that there is a sourcedid
480- # for this set before students access it.
481- my $LTIGradeMode = $ce -> {LTIGradeMode } // ' ' ;
482-
483- if ($LTIGradeMode eq ' homework' && !$self -> hasPermissions($userName , " view_unopened_sets" )) {
484- my $LMS =
485- $ce -> {LTI }{ $ce -> {LTIVersion } }{LMS_url }
486- ? $c -> link_to($ce -> {LTI }{ $ce -> {LTIVersion } }{LMS_name } => $ce -> {LTI }{ $ce -> {LTIVersion } }{LMS_url })
487- : $ce -> {LTI }{ $ce -> {LTIVersion } }{LMS_name };
488- return $c -> b($c -> maketext(
489- ' You must use your Learning Management System ([_1]) to access this set. '
490- . ' Try logging in to the Learning Management System and visiting the set from there.' ,
491- $LMS
492- ))
493- unless $set -> lis_source_did || ($ce -> {LTIVersion } eq ' v1p3' && $ce -> {LTI }{v1p3 }{ignoreMissingSourcedID });
478+ if ($badIP ) {
479+ if ($self -> hasPermissions($userName , ' view_ip_restricted_sets' )) {
480+ push (@restrictedSetMessages , $badIP );
481+ } else {
482+ $c -> {viewSetCheck } = ' restricted' ;
483+ return $badIP ;
484+ }
485+ }
486+
487+ # Check for lis_source_did if LTI grade passback is 'homework'.
488+ my $lti_msg = restricted_set_message($c , $set , ' lti' );
489+ if ($lti_msg ) {
490+ if ($canViewUnopened ) {
491+ push (@restrictedSetMessages , $lti_msg );
492+ } else {
493+ $c -> {viewSetCheck } = ' restricted' ;
494+ return $lti_msg ;
495+ }
494496 }
495497
498+ $c -> {restrictedSetMessages } = \@restrictedSetMessages if @restrictedSetMessages ;
496499 return 0;
497500}
498501
@@ -514,8 +517,7 @@ sub invalidIPAddress {
514517 return 0
515518 if (!defined ($set -> restrict_ip)
516519 || $set -> restrict_ip eq ' '
517- || $set -> restrict_ip eq ' No'
518- || $self -> hasPermissions($userName , ' view_ip_restricted_sets' ));
520+ || $set -> restrict_ip eq ' No' );
519521
520522 my $clientIP = new Net::IP($c -> tx-> remote_address);
521523
@@ -530,7 +532,9 @@ sub invalidIPAddress {
530532 # if there are no addresses in the locations, return an error that
531533 # says this
532534 return $c -> maketext(
533- " Client ip address [_1] is not allowed to work this assignment, because the assignment has ip address restrictions and there are no allowed locations associated with the restriction. Contact your professor to have this problem resolved." ,
535+ ' Client ip address [_1] is not allowed to work this assignment, because the assignment has ip address '
536+ . ' restrictions and there are no allowed locations associated with the restriction. Contact your '
537+ . ' professor to have this problem resolved.' ,
534538 $clientIP -> ip()
535539 ) if (!@restrictAddresses );
536540
@@ -552,17 +556,13 @@ sub invalidIPAddress {
552556 # this is slightly complicated by having to check relax_restrict_ip
553557 my $badIP = ' ' ;
554558 if ($restrictType eq ' RestrictTo' && !$inRestrict ) {
555- $badIP =
556- " Client ip address "
557- . $clientIP -> ip()
558- . " is not in the list of addresses from "
559- . " which this assignment may be worked." ;
559+ $badIP = $c -> maketext(
560+ ' Client ip address [_1] is not in the list of addresses from which this assignment may be worked.' ,
561+ $clientIP -> ip());
560562 } elsif ($restrictType eq ' DenyFrom' && $inRestrict ) {
561- $badIP =
562- " Client ip address "
563- . $clientIP -> ip()
564- . " is in the list of addresses from "
565- . " which this assignment may not be worked." ;
563+ $badIP = $c -> maketext(
564+ ' Client ip address [_1] is in the list of addresses from which this assignment may not be worked.' ,
565+ $clientIP -> ip());
566566 } else {
567567 return 0;
568568 }
0 commit comments