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

albertel lon-capa-cvs-allow@mail.lon-capa.org
Thu, 09 Aug 2007 00:59:16 -0000


albertel		Wed Aug  8 20:59:16 2007 EDT

  Modified files:              
    /loncom/homework	bridgetask.pm 
  Log:
  - BUG#5333
     - section restrictions apply when
          - using 'list of user's grade status'
          - whether or not you get to select the section you want to see
          - restricte regrade a user to only users in your section
          - hides the 'show grading status' button if you are section limited
  
  
Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.236 loncom/homework/bridgetask.pm:1.237
--- loncom/homework/bridgetask.pm:1.236	Fri Aug  3 19:29:57 2007
+++ loncom/homework/bridgetask.pm	Wed Aug  8 20:59:16 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.236 2007/08/03 23:29:57 albertel Exp $
+# $Id: bridgetask.pm,v 1.237 2007/08/09 00:59:16 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -244,13 +244,20 @@
     my $result="\n\t".'<input type="submit" name="gradeasubmission" value="'.
 	&mt("Get a submission to grade").'" />';
     $result.="\n\t".'<input type="hidden" name="grade_target" value="webgrade" />';
-    if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})
-	|| &Apache::lonnet::allowed('mgq',$env{'request.course.id'}.'/'.$env{'request.course.sec'})
-	) {
+    my $see_all = &Apache::lonnet::allowed('mgq',$env{'request.course.id'});
+    my $see_sec = &Apache::lonnet::allowed('mgq',$env{'request.course.id'}.
+					   '/'.$env{'request.course.sec'});
+
+    if ($see_all || $see_sec) {
 	my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
 	$result.="\n\t".'<table>'."\n\t\t".'<tr>';
-	$result.="\n\t\t\t".'<td rowspan="4">Specify a section: </td>'.
-	    "\n\t\t\t".'<td rowspan="4">'.$sec_select."\n\t\t\t".'</td>';
+	if ($see_all || (!&section_restricted())) {
+	    $result.="\n\t\t\t".'<td rowspan="4">Specify a section: </td>'.
+		"\n\t\t\t".'<td rowspan="4">'.$sec_select."\n\t\t\t".'</td>';
+	} else {
+	    $result.="\n\t\t\t".'<td rowspan="4">Grading section: </td>'.
+		"\n\t\t\t".'<td rowspan="4">'.$env{'request.course.sec'}."\n\t\t\t".'</td>';
+	}
 	$result.="\n\t\t\t".'<td>'.'<input type="submit" name="reviewagrading" value="'.
 	    &mt("Select an entry from the grading queue:").'" /> ';
 
@@ -623,12 +630,14 @@
 		my $target_id = 
 		    &Apache::lonstathelpers::make_target_id({symb => $symb,
 							     part => '0'});
-		$result.='<form method="post" name="gradingstatus" action="/adm/statistics">'.
-		    '<input type="hidden" name="problemchoice" value="'.$target_id.'" />'.
-		    '<input type="hidden" name="reportSelected" value="grading_analysis" />'.
-		    '<input type="submit" name="grading" value="'.
-		    &mt('Show Grading Status').'" />'.
-		    '</form>';
+		if (&section_restricted()) {
+		    $result.='<form method="post" name="gradingstatus" action="/adm/statistics">'.
+			'<input type="hidden" name="problemchoice" value="'.$target_id.'" />'.
+			'<input type="hidden" name="reportSelected" value="grading_analysis" />'.
+			'<input type="submit" name="grading" value="'.
+			&mt('Show Grading Status').'" />'.
+			'</form>';
+		}
 	    }
 	}
     }
@@ -807,9 +816,8 @@
 		$result.='<input type="hidden" name="regrade" value="'.
 		    $env{'form.regrade'}.'" />';
 	    }
-	    if ($env{'form.chosensections'}) {
-		my @chosen_sections=
-		    &Apache::loncommon::get_env_multiple('form.chosensections');
+	    if ($env{'form.chosensections'} || &section_restricted()) {
+		my @chosen_sections = &get_allowed_sections();
 		foreach my $sec (@chosen_sections) {
 		    $result.='<input type="hidden" name="chosensections" 
                                value="'.$sec.'" />';
@@ -905,7 +913,14 @@
 	my $cdom  = $env{'course.'.$cid.'.domain'};
 	my $uname = &LONCAPA::clean_username($env{'form.gradinguser'});
 	my $udom  = &LONCAPA::clean_domain($env{'form.gradingdomain'});
-
+	
+	if (&section_restricted()) {
+	    my $classlist=&get_limited_classlist();
+	    if (!&allow_grade_user($classlist->{$uname.':'.$udom})) {
+		return (undef,'not_allowed',
+			&mt('Requested student ([_1]) is in a section you aren\'t allowed to grade.',$uname.':'.$udom));
+	    }
+	}
 	my $gradingkey=&encode_queue_key($symb,$udom,$uname);
 
 	my $queue;
@@ -1521,11 +1536,11 @@
        	}
     }
 
-    if (ref($sections) && !grep('all',@{ $sections })) {
+    if (ref($sections) && !grep {$_ eq 'all'} (@{ $sections })) {
 	foreach my $student (keys(%$classlist)) {
 	    my $section  = 
 		$classlist->{$student}[&Apache::loncoursedata::CL_SECTION()];
-	    if (! grep($section,@{ $sections })) {
+	    if (! grep {$_ eq $section} (@{ $sections })) {
 		delete($classlist->{$student});
 	    }
 	}
@@ -1541,8 +1556,7 @@
     my $cnum=$env{'course.'.$cid.'.num'};
     my $cdom=$env{'course.'.$cid.'.domain'};
 
-    my @chosen_sections=
-	&Apache::loncommon::get_env_multiple('form.chosensections');
+    my @chosen_sections = &get_allowed_sections();
 
     my $classlist = &get_limited_classlist(\@chosen_sections);
 
@@ -1571,7 +1585,6 @@
     my ($tmp)=%queue;
     if ($tmp=~/^error: 2 /) {
 	$result.=
-	    
 	    &Apache::loncommon::start_data_table().
 	    &Apache::loncommon::start_data_table_row().
 	    '<td>'.&mt('Empty').'</td>'.
@@ -1589,7 +1602,7 @@
     foreach my $key (sort(keys(%queue))) {
 	my ($symb,$uname,$udom) = &decode_queue_key($key);
 	next if (!defined($classlist->{$uname.':'.$udom}));
-	next if (&section_restricted($classlist->{$uname.':'.$udom}));
+	next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
 	
 	my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
 
@@ -1675,16 +1688,33 @@
     return $result;
 }
 
+sub get_allowed_sections {
+    my @chosen_sections;
+    if (&section_restricted()) {
+	@chosen_sections = ($env{'request.course.sec'});
+    } else {
+	@chosen_sections =
+	    &Apache::loncommon::get_env_multiple('form.chosensections');
+    }
+
+    return @chosen_sections;
+}
+
 sub section_restricted {
-    my ($classlist_entry) = @_;
     my $cid =(&Apache::lonnet::whichuser())[1];
-    if (lc($env{'course.'.$cid.'.task_grading'}) eq 'section'
-	&& $env{'request.course.sec'}
+    return (lc($env{'course.'.$cid.'.task_grading'}) eq 'section'
+	    && $env{'request.course.sec'} ne '' );
+}
+
+sub allow_grade_user {
+    my ($classlist_entry) = @_;
+
+    if (&section_restricted()
 	&& $env{'request.course.sec'} ne
 	      $classlist_entry->[&Apache::loncoursedata::CL_SECTION()]) {
-	return 1;
+	return 0;
     }
-    return 0;
+    return 1;
 }
 
 sub get_queue_counts {
@@ -1708,7 +1738,7 @@
     foreach my $key (sort(keys(%queue))) {
 	my ($symb,$uname,$udom) = &decode_queue_key($key);
 	next if (!defined($classlist->{$uname.':'.$udom}));
-	next if (&section_restricted($classlist->{$uname.':'.$udom}));
+	next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
 
 	if ($key=~/locked$/) {
 	    $locks++;
@@ -1787,7 +1817,7 @@
 
 	my ($symb,$uname,$udom)=&decode_queue_key($key);
 	next if (!defined($classlist->{$uname.':'.$udom}));
-	next if (&section_restricted($classlist->{$uname.':'.$udom}));
+	next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
 
 	if ($check_section) {
 	    my $section =
@@ -1912,7 +1942,7 @@
 	next if ($key=~/timestamp$/);
 	my ($symb,$uname,$udom) = &decode_queue_key($key);
 	next if (!defined($classlist->{$uname.':'.$udom}));
-	next if (&section_restricted($classlist->{$uname.':'.$udom}));
+	next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
 	push(@users,"$uname:$udom");
     }
     return @users;
@@ -1999,9 +2029,7 @@
 sub select_user {
     my ($symb,$cid)=&Apache::lonnet::whichuser();
 
-    my @chosen_sections=
-	&Apache::loncommon::get_env_multiple('form.chosensections');
-
+    my @chosen_sections = &get_allowed_sections();
     my $classlist = &get_limited_classlist(\@chosen_sections);
     
     my $result;
@@ -2054,7 +2082,7 @@
       <input type="submit" name="submit" value="Regrade" />
       $seclist
     </form>
-  <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt></td>
+  <td>$classlist->{$student}[&Apache::loncoursedata::CL_FULLNAME()] <tt>($student)</tt> Sec: $classlist->{$student}[&Apache::loncoursedata::CL_SECTION()]</td>
   <td>
 RESULT
         }