[LON-CAPA-cvs] cvs: loncom /homework bridgetask.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 25 May 2006 19:55:11 -0000


This is a MIME encoded message

--albertel1148586911
Content-Type: text/plain

albertel		Thu May 25 15:55:11 2006 EDT

  Modified files:              
    /loncom/homework	bridgetask.pm 
  Log:
  - improved handling of
    - invalid grading queue entries 
    - section priv limiting
  
  
--albertel1148586911
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20060525155511.txt"

Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.155 loncom/homework/bridgetask.pm:1.156
--- loncom/homework/bridgetask.pm:1.155	Thu May 25 15:39:13 2006
+++ loncom/homework/bridgetask.pm	Thu May 25 15:55:10 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.155 2006/05/25 19:39:13 albertel Exp $
+# $Id: bridgetask.pm,v 1.156 2006/05/25 19:55:10 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1198,6 +1198,24 @@
     return &Apache::lonnet::cput($queue,\%data,$cdom,$cnum);
 }
 
+sub get_limited_classlist {
+    my ($sections) = @_;
+
+    my $classlist = &Apache::loncoursedata::get_classlist();
+
+    if (!grep('all',@{ $sections })) {
+	foreach my $student (keys(%$classlist)) {
+	    my $section  = 
+		$classlist->{$student}[&Apache::loncoursedata::CL_SECTION()];
+	    if (! grep($section,@{ $sections })) {
+		delete($classlist->{$student});
+	    }
+	}
+    }
+    return $classlist;
+}
+
+
 sub show_queue {
     my ($queue,$with_selects)=@_;
     my $result;
@@ -1207,14 +1225,25 @@
 
     my @chosen_sections=
 	&Apache::loncommon::get_env_multiple('form.chosensections');
-    &Apache::grades::init_perm();
-    my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
-    &Apache::grades::reset_perm();
+
+    my $classlist = &get_limited_classlist(\@chosen_sections);
+
     if (!(grep(/^all$/,@chosen_sections))) {
 	$result.='<p> Showing only sections <tt>'.join(', ',@chosen_sections).
 	    '</tt>.</p> '."\n";
     }
 
+    my ($view,$view_section);
+    my $scope = $env{'request.course.id'};
+    if (!($view=&Apache::lonnet::allowed('vgr',$scope))) {
+	$scope .= '/'.$env{'request.course.sec'};
+	if ( $view = &Apache::lonnet::allowed('vgr',$scope)) {
+	    $view_section=$env{'request.course.sec'};
+	} else {
+	    undef($view);
+	}
+    }
+
     my $regexp="^$symb\0";
     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
     my ($tmp)=%queue;
@@ -1228,6 +1257,16 @@
     foreach my $key (sort(keys(%queue))) {
 	my ($symb,$uname,$udom) = &decode_queue_key($key);
 	if (!defined($classlist->{$uname.':'.$udom})) { next; }
+	
+	my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
+
+	my $can_view=1;
+	if (!$view
+	    || ($view_section && !$section)
+	    || ($view_section && $section && ($view_section ne $section))) {
+	    $can_view=0;
+	}
+
 	if ($key=~/locked$/ && !$with_selects) {
 	    $result.="<tr><td>$uname</td>";
 	    $result.='<td>'.$queue{$key}.'</td></tr>';
@@ -1263,7 +1302,7 @@
 		    $seclist.='<input type="hidden" name="chosensections" 
                                value="'.$sec.'" />';
 		}
-		if ($end_time ne '' && time > $end_time) {
+		if ($can_view && ($end_time ne '' && time > $end_time)) {
 		    $result.=(<<FORM);
 <td>$status</td>
 <td>
@@ -1278,12 +1317,13 @@
 </form>
 </td>
 FORM
-
+                } elsif (!$can_view && ($end_time ne '' && time > $end_time)) {
+		    $result.='<td>'.&mt("Not gradable").'</td><td>&nbsp;</td>'
                 } else {
 		    $result.='<td>'.&mt("In Progress").'</td><td>&nbsp;</td>'
 		}
 	    }
-	    $result.= "<td>".$fullname->{$uname.':'.$udom}.
+	    $result.= "<td>".$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_FULLNAME()].
 		" <tt>($uname:$udom)</tt> </td>";
 	    $result.='<td>'.$slot_text.' End time: '.
 		&Apache::lonlocal::locallocaltime($end_time).
@@ -1300,6 +1340,9 @@
     my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
     my $cnum=$env{'course.'.$cid.'.num'};
     my $cdom=$env{'course.'.$cid.'.domain'};
+
+    my $classlist=&Apache::loncoursedata::get_classlist();
+
     my $regexp="^$symb\0";
     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
     my ($tmp)=%queue;
@@ -1309,12 +1352,14 @@
     my ($entries,$ready_to_grade,$locks)=(0,0,0);
     my %slot_cache;
     foreach my $key (sort(keys(%queue))) {
+	my ($symb,$uname,$udom) = &decode_queue_key($key);
+	if (!defined($classlist->{$uname.':'.$udom})) { next; }
+
 	if ($key=~/locked$/) {
 	    $locks++;
 	} elsif ($key=~/timestamp$/) {
 	    #ignore
 	} elsif ($key!~/(timestamp|locked)$/) {
-	    my ($symb,$uname,$udom) = &decode_queue_key($key);
 	    $entries++;
 	    if (my $slot=&slotted_access($queue{$key})) {
 		if (!exists($slot_cache{$slot})) {
@@ -1379,14 +1424,18 @@
 }
 
 sub pick_from_queue_data {
-    my ($queue,$check_section,$queuedata,$cdom,$cnum)=@_;
+    my ($queue,$check_section,$queuedata,$cdom,$cnum,$classlist)=@_;
     my @possible; # will hold queue entries that are valid to be selected
     foreach my $key (keys(%$queuedata)) {
 	if ($key =~ /\0locked$/) { next; }
 	if ($key =~ /\0timestamp$/) { next; }
+
 	my ($symb,$uname,$udom)=&decode_queue_key($key);
+	if (!defined($classlist->{$uname.':'.$udom})) { next; }
+
 	if ($check_section) {
-	    my $section=&Apache::lonnet::getsection($uname,$udom);
+	    my $section =
+		$classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
 	    if ($section eq $check_section) {
 		&Apache::lonxml::debug("my sec");
 		next;
@@ -1477,6 +1526,8 @@
 	$cnum=$env{'course.'.$cid.'.num'};
 	$cdom=$env{'course.'.$cid.'.domain'};
     }
+    my $classlist=&Apache::loncoursedata::get_classlist();
+
     my $regexp="^$symb\0";
     my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
     my ($tmp)=%queue;
@@ -1486,6 +1537,7 @@
 	next if ($key=~/locked$/);
 	next if ($key=~/timestamp$/);
 	my ($symb,$uname,$udom) = &decode_queue_key($key);
+	next if (!defined($classlist->{$uname.':'.$udom}));
 	push(@users,"$uname:$udom");
     }
     return @users;
@@ -1501,6 +1553,9 @@
     &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
     if ($todo) { return $todo; }
     my $attempts=0;
+
+    my $classlist=&Apache::loncoursedata::get_classlist();
+
     while (1) {
 	if ($attempts > 2) {
 	    # tried twice to get a queue entry, giving up
@@ -1511,21 +1566,22 @@
 			      $cdom,$cnum);
 	&Apache::lonxml::debug("$starttime");
 	my $regexp="^$symb\0queue\0";
-	my $range= ($attempts < 1 ) ? '0-100' : '0-400';
+	#my $range= ($attempts < 1 ) ? '0-100' : '0-400';
 
 	my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
 	#make a pass looking for a user _not_ in my section
 	if ($env{'request.course.sec'}) {
 	    &Apache::lonxml::debug("sce");
 	    $todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
-					\%queue,$cdom,$cnum);
+					\%queue,$cdom,$cnum,$classlist);
 	    &Apache::lonxml::debug("sce $todo");
 	}
 	# no one _not_ in our section so look for any user that is
 	# ready for grading
 	if (!$todo) {
 	    &Apache::lonxml::debug("no sce");
-	    $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum);
+	    $todo=&pick_from_queue_data($queue,undef,\%queue,$cdom,$cnum,
+					$classlist);
 	    &Apache::lonxml::debug("no sce $todo");
 	}
 	# no user to grade 
@@ -1570,9 +1626,8 @@
 
     my @chosen_sections=
 	&Apache::loncommon::get_env_multiple('form.chosensections');
-    &Apache::grades::init_perm();
-    my ($classlist,$section,$fullname)=&Apache::grades::getclasslist(\@chosen_sections,);
-    &Apache::grades::reset_perm();
+
+    my $classlist = &get_limited_classlist(\@chosen_sections);
     
     my $result;
     if (!(grep(/^all$/,@chosen_sections))) {
@@ -1581,7 +1636,7 @@
     }
     $result.='<table border="1">';
 
-    foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
+    foreach my $student (sort {lc($classlist->{$a}[&Apache::loncoursedata::CL_FULLNAME()]) cmp lc($classlist->{$b}[&Apache::loncoursedata::CL_FULLNAME()]) } (keys(%$classlist))) {
 	my ($uname,$udom) = split(/:/,$student);
 	
 	my $cnum=$env{'course.'.$cid.'.num'};
@@ -1604,7 +1659,7 @@
 	my $todo = 
 	    &Apache::lonnet::escape(&encode_queue_key($symb,$udom,$uname));
 	if ($cannot_grade) {
-	    $result.='<tr><td>&nbsp;</td><td>'.$fullname->{$student}.
+	    $result.='<tr><td>&nbsp;</td><td>'.$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()].
 		'</td><td>';
 	} else {
 	    my $seclist;

--albertel1148586911--