[LON-CAPA-cvs] cvs: loncom /automation batchcreatecourse.pm /enrollment Enrollment.pm /lonnet/perl lonnet.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Fri, 11 May 2007 01:48:26 -0000


raeburn		Thu May 10 21:48:26 2007 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/enrollment	Enrollment.pm 
    /loncom/automation	batchcreatecourse.pm 
  Log:
  Bug 5134. If the course owner was not an existing user and needed to be added as a new user, this would fail for a user with auth type = localauth because no homeserver existed for the course for lonnet::auto_create_password().
  - now pass an extra argument (domain of new user) and contact primary domain server for this domain to access localauth password cretion in localenroll.pm
  - extra logging in Enrollment.pm to log case where authchk fails for localauth case
  - batchcreatecourse.pm now checks whether a valid courseID was returned for the new course.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.872 loncom/lonnet/perl/lonnet.pm:1.873
--- loncom/lonnet/perl/lonnet.pm:1.872	Wed May  2 18:00:02 2007
+++ loncom/lonnet/perl/lonnet.pm	Thu May 10 21:48:19 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.872 2007/05/02 22:00:02 albertel Exp $
+# $Id: lonnet.pm,v 1.873 2007/05/11 01:48:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4486,15 +4486,27 @@
 }
 
 sub auto_create_password {
-    my ($cnum,$cdom,$authparam) = @_;
-    my $homeserver = &homeserver($cnum,$cdom); 
+    my ($cnum,$cdom,$authparam,$udom) = @_;
+    my ($homeserver,$response);
     my $create_passwd = 0;
     my $authchk = '';
-    my $response=&unescape(&reply('autocreatepassword:'.$authparam.':'.$cdom,$homeserver));
-    if ($response eq 'refused') {
-        $authchk = 'refused';
+    if ($udom =~ /^$match_domain$/) {
+        $homeserver = &domain($udom,'primary');
+    }
+    if ($homeserver eq '') {
+        if (($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/)) {
+            $homeserver = &homeserver($cnum,$cdom);
+        }
+    }
+    if ($homeserver eq '') {
+        $authchk = 'nodomain';
     } else {
-        ($authparam,$create_passwd,$authchk) = split/:/,$response;
+        $response=&unescape(&reply('autocreatepassword:'.$authparam.':'.$cdom,$homeserver));
+        if ($response eq 'refused') {
+            $authchk = 'refused';
+        } else {
+            ($authparam,$create_passwd,$authchk) = split/:/,$response;
+        }
     }
     return ($authparam,$create_passwd,$authchk);
 }
Index: loncom/enrollment/Enrollment.pm
diff -u loncom/enrollment/Enrollment.pm:1.33 loncom/enrollment/Enrollment.pm:1.34
--- loncom/enrollment/Enrollment.pm:1.33	Fri Mar  2 16:38:18 2007
+++ loncom/enrollment/Enrollment.pm	Thu May 10 21:48:23 2007
@@ -1,5 +1,5 @@
 # Automated Enrollment manager
-# $Id: Enrollment.pm,v 1.33 2007/03/02 21:38:18 raeburn Exp $
+# $Id: Enrollment.pm,v 1.34 2007/05/11 01:48:23 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -428,7 +428,6 @@
     if ($switchcount > 0) {
         if ($context eq "updatenow") {
             $switchresult = substr($switchresult,0,rindex($switchresult,"<li>"));
-            print STDERR &mt("[quant,_1,student]",$switchcount)."\n"; 
             $switchresult = &mt("The following [quant,_1,student] switched sections in this LON-CAPA course:",$switchcount).'<br/><ul><li>'.$switchresult.'</ul><br/><br/>';
         } else {
             $switchresult = &mt("The following [quant,_1,student] switched sections in this LON-CAPA course:",$switchcount)."\n\n".$switchresult."\n\n";
@@ -492,7 +491,7 @@
             }
         }
     } elsif ($auth eq "localauth") {
-        ($authparam,$create_passwd,$authchk) = &Apache::lonnet::auto_create_password($crs,$cdom,$authparam);
+        ($authparam,$create_passwd,$authchk) = &Apache::lonnet::auto_create_password($crs,$cdom,$authparam,$udom);
     } elsif ($auth =~ m/^krb/) {
         if ($authparam eq '') {
             $$logmsg .= &mt('No Kerberos domain was provided for the new user - [_1], so the new user was not enrolled in the course',$uname).$linefeed;
@@ -501,7 +500,7 @@
     } else {
         $authchk = 'invalid';
         $$logmsg .= &mt('An invalid authentication type was provided for the new user - [_1], so the user was not enrolled in the course.',$uname).$linefeed;
-    }   
+    }
     if ($authchk eq 'ok') {
 # Now create user.
         my $type = 'auto';
@@ -575,6 +574,8 @@
         } else {
             $$logmsg .= &mt('An error occurred adding new user [_1] - [_2].',$uname,$outcome).$linefeed;
         }
+    } else {
+        $$logmsg .= &mt('An error occurred adding the new user [_1] because the authcheck failed for authtype [_2] and parameter [_3].',$uname,$auth,$authparam).' '.&mt('The authcheck response was [_1].',$authchk).$linefeed;
     }
     return $outcome;
 }
Index: loncom/automation/batchcreatecourse.pm
diff -u loncom/automation/batchcreatecourse.pm:1.20 loncom/automation/batchcreatecourse.pm:1.21
--- loncom/automation/batchcreatecourse.pm:1.20	Fri Mar  2 20:40:38 2007
+++ loncom/automation/batchcreatecourse.pm	Thu May 10 21:48:26 2007
@@ -1,5 +1,5 @@
 #
-# $Id: batchcreatecourse.pm,v 1.20 2007/03/03 01:40:38 albertel Exp $
+# $Id: batchcreatecourse.pm,v 1.21 2007/05/11 01:48:26 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -32,6 +32,7 @@
 use Apache::lonnet;
 use Apache::loncommon;
 use Apache::lonlocal;
+use LONCAPA qw(:match);
 
 use strict;
 
@@ -218,7 +219,9 @@
                 &parse_coursereqs($newcoursedir.'/'.$request, \%details);
                 foreach my $num (sort keys %details) {
                     my $courseid = &build_course($dom,$num,$context,\%details,\%longroles,\$logmsg,\$newusermsg,\$addresult,\%enrollcount,\$output,\$keysmsg);
-                    $$courseids{$courseid} = $details{$num}{'class'};
+                    if ($courseid =~ /^$match_courseid$/) {
+                        $$courseids{$courseid} = $details{$num}{'class'};
+                    }
                 }
             }
         }