[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm /lonnet/perl lonnet.pm
raeburn
raeburn at source.lon-capa.org
Mon Apr 13 12:30:33 EDT 2015
raeburn Mon Apr 13 16:30:33 2015 EDT
Modified files:
/loncom/interface lonnavmaps.pm
/loncom/lonnet/perl lonnet.pm
Log:
- Listing resources in a folder for which the interval parameter is set, in
order to test for content blocking for other resources in a course needs
to not recurse.
-------------- next part --------------
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.504 loncom/interface/lonnavmaps.pm:1.505
--- loncom/interface/lonnavmaps.pm:1.504 Thu Dec 11 01:56:34 2014
+++ loncom/interface/lonnavmaps.pm Mon Apr 13 16:30:28 2015
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.504 2014/12/11 01:56:34 raeburn Exp $
+# $Id: lonnavmaps.pm,v 1.505 2015/04/13 16:30:28 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
@@ -2927,7 +2927,7 @@
will be returned (useful for maps), unless the multiple parameter has
been included, in which case all instances are returned in an array.
-=item * B<retrieveResources>(map, filterFunc, recursive, bailout, showall):
+=item * B<retrieveResources>(map, filterFunc, recursive, bailout, showall, noblockcheck):
The map is a specification of a map to retreive the resources from,
either as a url or as an object. The filterFunc is a reference to a
@@ -2936,13 +2936,18 @@
be. If recursive is true, the map will be recursively examined,
otherwise it will not be. If bailout is true, the function will return
as soon as it finds a resource, if false it will finish. If showall is
-true it will not hide maps that contain nothing but one other map. By
-default, the map is the top-level map of the course, filterFunc is a
-function that always returns 1, recursive is true, bailout is false,
-showall is false. The resources will be returned in a list containing
-the resource objects for the corresponding resources, with B<no
-structure information> in the list; regardless of branching,
-recursion, etc., it will be a flat list.
+true it will not hide maps that contain nothing but one other map. The
+noblockcheck arg is propagated to become the sixth arg in the call to
+lonnet::allowed when checking a resource's availability during collection
+of resources using the iterator. noblockcheck needs to be true if
+retrieveResources() was called by a routine that itself was called by
+lonnet::allowed, in order to avoid recursion. By default the map
+is the top-level map of the course, filterFunc is a function that
+always returns 1, recursive is true, bailout is false, showall is
+false. The resources will be returned in a list containing the
+resource objects for the corresponding resources, with B<no structure
+information> in the list; regardless of branching, recursion, etc.,
+it will be a flat list.
Thus, this is suitable for cases where you don't want the structure,
just a list of all resources. It is also suitable for finding out how
@@ -3009,6 +3014,7 @@
my $bailout = shift;
if (!defined($bailout)) { $bailout = 0; }
my $showall = shift;
+ my $noblockcheck = shift
# Create the necessary iterator.
if (!ref($map)) { # assume it's a url of a map.
$map = $self->getResourceByUrl($map);
@@ -3038,7 +3044,7 @@
# Run down the iterator and collect the resources.
my $curRes;
- while ($curRes = $it->next()) {
+ while ($curRes = $it->next(undef,$noblockcheck)) {
if (ref($curRes)) {
if (!&$filterFunc($curRes)) {
next;
@@ -3189,7 +3195,14 @@
resource objects will be references, and any non-references will
be the tokens described above.
-Also note there is some old code floating around that trys to track
+The next() routine can take two (optional) arguments:
+closeAllPages - if true will not recurse down a .page
+noblockcheck - passed to browsePriv() for passing as sixth arg to
+call to lonnet::allowed. This needs to be set if retrieveResources
+was already called from another routine called within lonnet::allowed,
+so as to prevent recursion.
+
+Also note there is some old code floating around that triess to track
the depth of the iterator to see when it's done; do not copy that
code. It is difficult to get right and harder to understand than
this. They should be migrated to this new style.
@@ -3365,6 +3378,7 @@
sub next {
my $self = shift;
my $closeAllPages=shift;
+ my $noblockcheck = shift;
if ($self->{FINISHED}) {
return END_ITERATOR();
}
@@ -3514,7 +3528,7 @@
# If this is a blank resource, don't actually return it.
# Should you ever find you need it, make sure to add an option to the code
# that you can use; other things depend on this behavior.
- my $browsePriv = $self->{HERE}->browsePriv();
+ my $browsePriv = $self->{HERE}->browsePriv($noblockcheck);
if (!$self->{HERE}->src() ||
(!($browsePriv eq 'F') && !($browsePriv eq '2')) ) {
return $self->next($closeAllPages);
@@ -5657,12 +5671,14 @@
sub browsePriv {
my $self = shift;
+ my $noblockcheck = shift;
if (defined($self->{BROWSE_PRIV})) {
return $self->{BROWSE_PRIV};
}
$self->{BROWSE_PRIV} = &Apache::lonnet::allowed('bre',$self->src(),
- $self->symb());
+ $self->symb(),undef,
+ undef,$noblockcheck);
}
=pod
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1280 loncom/lonnet/perl/lonnet.pm:1.1281
--- loncom/lonnet/perl/lonnet.pm:1.1280 Thu Apr 9 17:46:54 2015
+++ loncom/lonnet/perl/lonnet.pm Mon Apr 13 16:30:32 2015
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.1280 2015/04/09 17:46:54 raeburn Exp $
+# $Id: lonnet.pm,v 1.1281 2015/04/13 16:30:32 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -6639,7 +6639,7 @@
# ------------------------------------------------- Check for a user privilege
sub allowed {
- my ($priv,$uri,$symb,$role,$clientip)=@_;
+ my ($priv,$uri,$symb,$role,$clientip,$noblockcheck)=@_;
my $ver_orguri=$uri;
$uri=&deversion($uri);
my $orguri=$uri;
@@ -6834,11 +6834,16 @@
if ($match) {
if ($env{'user.priv.'.$env{'request.role'}.'./'}
=~/\Q$priv\E\&([^\:]*)/) {
- my @blockers = &has_comm_blocking($priv,$symb,$uri);
- if (@blockers > 0) {
- $thisallowed = 'B';
+ my $value = $1;
+ if ($noblockcheck) {
+ $thisallowed.=$value;
} else {
- $thisallowed.=$1;
+ my @blockers = &has_comm_blocking($priv,$symb,$uri);
+ if (@blockers > 0) {
+ $thisallowed = 'B';
+ } else {
+ $thisallowed.=$value;
+ }
}
}
} else {
@@ -6850,11 +6855,15 @@
$refuri=&declutter($refuri);
my ($match) = &is_on_map($refuri);
if ($match) {
- my @blockers = &has_comm_blocking($priv,$symb,$refuri);
- if (@blockers > 0) {
- $thisallowed = 'B';
- } else {
+ if ($noblockcheck) {
$thisallowed='F';
+ } else {
+ my @blockers = &has_comm_blocking($priv,$symb,$refuri);
+ if (@blockers > 0) {
+ $thisallowed = 'B';
+ } else {
+ $thisallowed='F';
+ }
}
}
}
@@ -6909,11 +6918,15 @@
=~/\Q$priv\E\&([^\:]*)/) {
my $value = $1;
if ($priv eq 'bre') {
- my @blockers = &has_comm_blocking($priv,$symb,$uri);
- if (@blockers > 0) {
- $thisallowed = 'B';
- } else {
+ if ($noblockcheck) {
$thisallowed.=$value;
+ } else {
+ my @blockers = &has_comm_blocking($priv,$symb,$uri);
+ if (@blockers > 0) {
+ $thisallowed = 'B';
+ } else {
+ $thisallowed.=$value;
+ }
}
} else {
$thisallowed.=$value;
@@ -6947,11 +6960,15 @@
=~/\Q$priv\E\&([^\:]*)/) {
my $value = $1;
if ($priv eq 'bre') {
- my @blockers = &has_comm_blocking($priv,$symb,$refuri);
- if (@blockers > 0) {
- $thisallowed = 'B';
- } else {
+ if ($noblockcheck) {
$thisallowed.=$value;
+ } else {
+ my @blockers = &has_comm_blocking($priv,$symb,$refuri);
+ if (@blockers > 0) {
+ $thisallowed = 'B';
+ } else {
+ $thisallowed.=$value;
+ }
}
} else {
$thisallowed.=$value;
@@ -7271,7 +7288,7 @@
if ($mapsymb) {
if (ref($navmap)) {
my $mapres = $navmap->getBySymb($mapsymb);
- @to_test = $mapres->retrieveResources($mapres);
+ @to_test = $mapres->retrieveResources($mapres,undef,0,0,0,1);
foreach my $res (@to_test) {
my $symb = $res->symb();
next if ($symb eq $mapsymb);
@@ -12945,13 +12962,29 @@
=item *
-allowed($priv,$uri,$symb,$role) : check for a user privilege; returns codes for allowed actions
+allowed($priv,$uri,$symb,$role,$clientip,$noblockcheck) : check for a user privilege;
+returns codes for allowed actions
+
+The first argument is required, all others are optional.
+
+$priv is the privilege being checked.
+$uri contains additional information about what is being checked for access (e.g.,
+URL, course ID etc.).
+$symb is the unique resource instance identifier in a course; if needed,
+but not provided, it will be retrieved via a call to &symbread().
+$role is the role for which a priv is being checked (only used if priv is evb).
+$clientip is the user's IP address (only used when checking for access to portfolio
+files).
+$noblockcheck, if true, skips calls to &has_comm_blocking() for the bre priv. This
+prevents recursive calls to &allowed.
+
F: full access
U,I,K: authentication modes (cxx only)
'': forbidden
1: user needs to choose course
2: browse allowed
A: passphrase authentication needed
+ B: access temporarily blocked because of a blocking event in a course.
=item *
More information about the LON-CAPA-cvs
mailing list