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

albertel lon-capa-cvs-allow@mail.lon-capa.org
Fri, 10 Aug 2007 23:01:51 -0000


albertel		Fri Aug 10 19:01:51 2007 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
  Log:
  - BUG#5343, don't drop user from classlist if they have active student roles
  
  
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.169 loncom/interface/loncreateuser.pm:1.170
--- loncom/interface/loncreateuser.pm:1.169	Fri Aug 10 19:00:13 2007
+++ loncom/interface/loncreateuser.pm	Fri Aug 10 19:01:51 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.169 2007/08/10 23:00:13 albertel Exp $
+# $Id: loncreateuser.pm,v 1.170 2007/08/10 23:01:51 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1537,23 +1537,20 @@
 	if ($key=~/^form\.rev/) {
 	    if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
 # Revoke standard role
-	        $r->print(&mt('Revoking').' '.$2.' in '.$1.': <b>'.
-                     &Apache::lonnet::revokerole($env{'form.ccdomain'},
-                     $env{'form.ccuname'},$1,$2).'</b><br />');
-		if ($2 eq 'st') {
-		    $1=~m{^/($match_domain)/($match_courseid)};
-		    my $cid=$1.'_'.$2;
-		    my $user = $env{'form.ccuname'}.':'.$env{'form.ccdomain'};
-		    my $result = 
-			&Apache::lonnet::cput('classlist',
-					      { $user => $now },
-					      $env{'course.'.$cid.'.domain'},
-					      $env{'course.'.$cid.'.num'});
-		    $r->print(&mt('Drop from classlist: [_1]',
-				  '<b>'.$result.'</b>').'<br />');
+		my ($scope,$role) = ($1,$2);
+		my $result =
+		    &Apache::lonnet::revokerole($env{'form.ccdomain'},
+						$env{'form.ccuname'},
+						$scope,$role);
+	        $r->print(&mt('Revoking [_1] in [_2]: [_3]',
+			      $role,$scope,'<b>'.$result.'</b>').'<br />');
+		if ($role eq 'st') {
+		    my $result = &classlist_drop($scope,$env{'form.ccuname'},
+						 $env{'form.ccdomain'},$now);
+		    $r->print($result);
 		}
 	    } 
-	    if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
+	    if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$ }s) {
 # Revoke custom role
 		$r->print(&mt('Revoking custom role:').
                       ' '.$4.' by '.$3.':'.$2.' in '.$1.': <b>'.
@@ -1564,26 +1561,23 @@
 	} elsif ($key=~/^form\.del/) {
 	    if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
 # Delete standard role
-	        $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
-                     &Apache::lonnet::assignrole($env{'form.ccdomain'},
-                     $env{'form.ccuname'},$1,$2,$now,0,1).'<br />');
-		if ($2 eq 'st') {
-		    $1=~m{^/($match_domain)/($match_courseid)};
-		    my $cid=$1.'_'.$2;
-		    my $user = $env{'form.ccuname'}.':'.$env{'form.ccdomain'};
-		    my $result = 
-			&Apache::lonnet::cput('classlist',
-					      { $user => $now },
-					      $env{'course.'.$cid.'.domain'},
-					      $env{'course.'.$cid.'.num'});
-		    $r->print(&mt('Drop from classlist: [_1]',
-				  '<b>'.$result.'</b>').'<br />');
+		my ($scope,$role) = ($1,$2);
+		my $result =
+		    &Apache::lonnet::assignrole($env{'form.ccdomain'},
+						$env{'form.ccuname'},
+						$scope,$role,$now,0,1);
+	        $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
+			      '<b>'.$result.'</b>').'<br />');
+		if ($role eq 'st') {
+		    my $result = &classlist_drop($scope,$env{'form.ccuname'},
+						 $env{'form.ccdomain'},$now);
+		    $r->print($result);
 		}
             }
 	    if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
                 my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
 # Delete custom role
-                $r->print(&mt('Deleting custom role [_1] by [_2]@[_3] in [_4]',
+                $r->print(&mt('Deleting custom role [_1] by [_2]:[_3] in [_4]',
                       $rolename,$rnam,$rdom,$url).': <b>'.
                       &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
                          $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
@@ -1760,6 +1754,30 @@
     $r->print(&Apache::loncommon::end_page());
 }
 
+sub classlist_drop {
+    my ($scope,$uname,$udom,$now) = @_;
+    my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
+    my $cid=$cdom.'_'.$cnum;
+    my $user = $uname.':'.$udom;
+    if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
+	my $result = 
+	    &Apache::lonnet::cput('classlist',
+				  { $user => $now },
+				  $env{'course.'.$cid.'.domain'},
+				  $env{'course.'.$cid.'.num'});
+	return &mt('Drop from classlist: [_1]',
+		   '<b>'.$result.'</b>').'<br />';
+    }
+}
+
+sub active_student_role {
+    my ($cnum,$cdom,$uname,$udom) = @_;
+    my %roles = 
+	&Apache::lonnet::get_my_roles($uname,$udom,'userroles',
+				      ['future','active'],['st']);
+    return exists($roles{"$cnum:$cdom:st"});
+}
+
 sub quota_admin {
     my ($setquota,$changeHash) = @_;
     my $quotachanged;