[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm /lonnet/perl lonnet.pm

www lon-capa-cvs@mail.lon-capa.org
Sun, 20 Jul 2003 00:39:02 -0000


www		Sat Jul 19 20:39:02 2003 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Fixed bug #795: handling of custom roles in CUSR
  
  
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.64 loncom/interface/loncreateuser.pm:1.65
--- loncom/interface/loncreateuser.pm:1.64	Sat Jul 19 17:44:51 2003
+++ loncom/interface/loncreateuser.pm	Sat Jul 19 20:39:01 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.64 2003/07/19 21:44:51 www Exp $
+# $Id: loncreateuser.pm,v 1.65 2003/07/20 00:39:01 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -755,8 +755,8 @@
 	    if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
 # Revoke standard role
 	        $r->print('Revoking '.$2.' in '.$1.': <b>'.
-                     &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
-                     $ENV{'form.ccuname'},$1,$2,$now).'</b><br>');
+                     &Apache::lonnet::revokerole($ENV{'form.ccdomain'},
+                     $ENV{'form.ccuname'},$1,$2).'</b><br>');
 		if ($2 eq 'st') {
 		    $1=~/^\/(\w+)\/(\w+)/;
 		    my $cid=$1.'_'.$2;
@@ -773,7 +773,9 @@
 	    if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
 # Revoke custom role
 		$r->print(
-                'Revoking custom role '.$4.' by '.$3.'\@'.$2.' in '.$1.': <b>'.
+                'Revoking custom role '.$4.' by '.$3.'@'.$2.' in '.$1.': <b>'.
+&Apache::lonnet::revokecustomrole($ENV{'form.ccdomain'},
+				  $ENV{'form.ccuname'},$1,$2,$3,$4).
 		'</b><br>');
 	    }
 	} elsif ($_=~/^form\.del/) {
@@ -795,7 +797,29 @@
 		}
 	    } 
 	} elsif ($_=~/^form\.act/) {
-	    if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
+	    if 
+($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
+                # Activate a custom role
+		my $url='/'.$1.'/'.$2;
+		my $full=$1.'_'.$2.'_cr_cr_'.$3.'_'.$4.'_'.$5;
+		if ($ENV{'form.sec_'.$full}) {
+		    $url.='/'.$ENV{'form.sec_'.$full};
+		}
+
+		my $start = ( $ENV{'form.start_'.$full} ? 
+			      $ENV{'form.start_'.$full} : 
+			      $now );
+		my $end   = ( $ENV{'form.end_'.$full} ? 
+			      $ENV{'form.end_'.$full} :
+			      0 );
+
+    $r->print('Assigning custom role "'.$5.'" by '.$4.'@'.$3.' in '.$url.
+                         ($start?', starting '.localtime($start):'').
+                         ($end?', ending '.localtime($end):'').': <b>'.
+	      &Apache::lonnet::assigncustomrole(
+	$ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$3,$4,$5,$end,$start).
+	      '</b><br>');
+	    } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
 		# Activate roles for sections with 3 id numbers
 		# set start, end times, and the url for the class
 
@@ -810,7 +834,7 @@
 		    $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
 		}
 		# Assign the role and report it
-		$r->print('Assigning: '.$3.' in '.$url.
+		$r->print('Assigning '.$3.' in '.$url.
                          ($start?', starting '.localtime($start):'').
                          ($end?', ending '.localtime($end):'').': <b>'.
                           &Apache::lonnet::assignrole(
@@ -843,7 +867,7 @@
 			      0 );
 		my $url='/'.$1.'/';
 		# Assign the role and report it.
-		$r->print('Assigning: '.$2.' in '.$url.': '.
+		$r->print('Assigning '.$2.' in '.$url.': '.
                          ($start?', starting '.localtime($start):'').
                          ($end?', ending '.localtime($end):'').': <b>'.
                           &Apache::lonnet::assignrole(
@@ -1106,20 +1130,24 @@
             }
         }
         foreach (sort keys %customroles) {
-	    my $plrole=$_;
-	    $table .= <<ENDENTRY;
+	    if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
+		my $plrole=$_;
+                my $customrole=$protectedcourse.'_cr_cr_'.$ENV{'user.domain'}.
+		    '_'.$ENV{'user.name'}.'_'.$plrole;
+		$table .= <<ENDENTRY;
 <tr bgcolor="#$bgcol">
-<td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
+<td><input type="checkbox" name="act_$customrole"></td>
 <td>$plrole</td>
 <td>$area</td>
-<td><input type="text" size="5" name="sec_$protectedcourse\_$_"></td>
-<td><input type=hidden name="start_$protectedcourse\_$_" value=''>
+<td><input type="text" size="5" name="sec_$customrole"></td>
+<td><input type=hidden name="start_$customrole" value=''>
 <a href=
-"javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">Set Start Date</a></td>
-<td><input type=hidden name="end_$protectedcourse\_$_" value=''>
+"javascript:pjump('date_start','Start Date $plrole',document.cu.start_$customrole.value,'start_$customrole','cu.pres','dateset')">Set Start Date</a></td>
+<td><input type=hidden name="end_$customrole" value=''>
 <a href=
-"javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">Set End Date</a></td></tr>
+"javascript:pjump('date_end','End Date $plrole',document.cu.end_$customrole.value,'end_$customrole','cu.pres','dateset')">Set End Date</a></td></tr>
 ENDENTRY
+           }
 	}
     }
     return '' if ($table eq ''); # return nothing if there is nothing 
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.392 loncom/lonnet/perl/lonnet.pm:1.393
--- loncom/lonnet/perl/lonnet.pm:1.392	Fri Jul 18 15:50:28 2003
+++ loncom/lonnet/perl/lonnet.pm	Sat Jul 19 20:39:02 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.392 2003/07/18 19:50:28 www Exp $
+# $Id: lonnet.pm,v 1.393 2003/07/20 00:39:02 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2651,7 +2651,9 @@
     my ($udom,$uname,$url,$role,$end,$start,$deleteflag)=@_;
     my $mrole;
     if ($role =~ /^cr\//) {
-	unless (&allowed('ccr',$url)) {
+        my $cwosec=$url;
+        $cwosec=~s/^\/(\w+)\/(\w+)\/.*/$1\/$2/;
+	unless (&allowed('ccr',$cwosec)) {
            &logthis('Refused custom assignrole: '.
              $udom.' '.$uname.' '.$url.' '.$role.' '.$end.' '.$start.' by '.
 		    $ENV{'user.name'}.' at '.$ENV{'user.domain'});