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

raeburn raeburn@source.lon-capa.org
Sun, 21 Mar 2010 21:06:00 -0000


This is a MIME encoded message

--raeburn1269205560
Content-Type: text/plain

raeburn		Sun Mar 21 21:06:00 2010 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/enrollment	Autoupdate.pl 
  Log:
  - Bug 5805.
    - Allow existing non-empty entries for user information (lastname, middlename, firstname, generation, id and permanentemail) to be overwritten with empty entries, if field is included in $candelete array ref (new arg for lonnet::modifyuser().
    - Overwriting with empty entries allowed when:
      (a) Updating user information for a single user from "Modify User"        (domain, author or course context) - subject to domain config        for user modification.
      (b) Autoupdate.pl updates from institutional directory data,
          subject to domain config for Autoupdate.
  
  
--raeburn1269205560
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100321210600.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.336 loncom/interface/loncreateuser.pm:1.337
--- loncom/interface/loncreateuser.pm:1.336	Sun Mar 21 15:00:31 2010
+++ loncom/interface/loncreateuser.pm	Sun Mar 21 21:05:42 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.336 2010/03/21 15:00:31 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.337 2010/03/21 21:05:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2624,7 +2624,7 @@
                     if (ref($usertypes) eq 'HASH') {
                         $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses)); 
                     } else {
-                        $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
+                        $newsettings{'inststatus'} = join(', ',@inststatuses);
                     }
                 }
             } else {
@@ -2637,6 +2637,7 @@
             }
         } elsif ($context ne 'selfcreate') {
             $canshow{'inststatus'} = 1;
+            $newsettings{'inststatus'} = $oldsettings{'inststatus'};
         }
         $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
         if ($context eq 'domain') {
@@ -2697,12 +2698,6 @@
         $oldsettings{'quota'} = $oldportfolioquota.' Mb';
         $newsettings{'quota'} = $newportfolioquota.' Mb';
         if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
-            $changeHash{'firstname'}  = $env{'form.cfirstname'};
-            $changeHash{'middlename'} = $env{'form.cmiddlename'};
-            $changeHash{'lastname'}   = $env{'form.clastname'};
-            $changeHash{'generation'} = $env{'form.cgeneration'};
-            $changeHash{'id'}         = $env{'form.cid'};
-            $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
             my ($chgresult,$namechgresult);
             if (keys(%changed) > 0) {
                 $chgresult = 
@@ -2743,13 +2738,16 @@
                 }
             }
             if (keys(%namechanged) > 0) {
-            # Make the change
+                foreach my $field (@userinfo) {
+                    $changeHash{$field}  = $env{'form.c'.$field};
+                }
+# Make the change
                 $namechgresult =
                     &Apache::lonnet::modifyuser($env{'form.ccdomain'},
                         $env{'form.ccuname'},$changeHash{'id'},undef,undef,
                         $changeHash{'firstname'},$changeHash{'middlename'},
                         $changeHash{'lastname'},$changeHash{'generation'},
-                        $changeHash{'id'},undef,$changeHash{'permanentemail'});
+                        $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
                 %userupdate = (
                                lastname   => $env{'form.clastname'},
                                middlename => $env{'form.cmiddlename'},
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1057 loncom/lonnet/perl/lonnet.pm:1.1058
--- loncom/lonnet/perl/lonnet.pm:1.1057	Sun Mar 21 18:31:53 2010
+++ loncom/lonnet/perl/lonnet.pm	Sun Mar 21 21:05:51 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1057 2010/03/21 18:31:53 www Exp $
+# $Id: lonnet.pm,v 1.1058 2010/03/21 21:05:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6234,6 +6234,7 @@
                     if ($role eq 'cc' || $role eq 'co') {
                         %crsenv = &userenvironment($cdom,$cnum,('internal.courseowner'));
                         if (($role eq 'cc') && ($cnum !~ /^$match_community$/)) {
+
                             if ($env{'request.role'} eq 'cc./'.$cdom.'/'.$cnum) {
                                 if ($crsenv{'internal.courseowner'} eq 
                                     $env{'user.name'}.':'.$env{'user.domain'}) {
@@ -6439,12 +6440,12 @@
     my ($udom,    $uname, $uid,
         $umode,   $upass, $first,
         $middle,  $last,  $gene,
-        $forceid, $desiredhome, $email, $inststatus)=@_;
+        $forceid, $desiredhome, $email, $inststatus, $candelete)=@_;
     $udom= &LONCAPA::clean_domain($udom);
     $uname=&LONCAPA::clean_username($uname);
     &logthis('Call to modify user '.$udom.', '.$uname.', '.$uid.', '.
              $umode.', '.$first.', '.$middle.', '.
-	     $last.', '.$gene.'(forceid: '.$forceid.')'.
+	     $last.', '.$gene.'(forceid: '.$forceid.'; candelete: '.$candelete.')'.
              (defined($desiredhome) ? ' desiredhome = '.$desiredhome :
                                      ' desiredhome not specified'). 
              ' by '.$env{'user.name'}.' at '.$env{'user.domain'}.
@@ -6509,9 +6510,33 @@
         %names = @tmp;
     }
 #
-# Make sure to not trash student environment if instructor does not bother
-# to supply name and email information
-#
+# If name, email and/or uid are blank (e.g., because an uploaded file
+# of users did not contain them), do not overwrite existing values
+# unless field is in $candelete array ref.  
+#
+
+    my @fields = ('firstname','middlename','lastname','generation',
+                  'permanentemail','id');
+    my %newvalues;
+    if (ref($candelete) eq 'ARRAY') {
+        foreach my $field (@fields) {
+            if (grep(/^\Q$field\E$/,@{$candelete})) {
+                if ($field eq 'firstname') {
+                    $names{$field} = $first;
+                } elsif ($field eq 'middlename') {
+                    $names{$field} = $middle;
+                } elsif ($field eq 'lastname') {
+                    $names{$field} = $last;
+                } elsif ($field eq 'generation') { 
+                    $names{$field} = $gene;
+                } elsif ($field eq 'permanentemail') {
+                    $names{$field} = $email;
+                } elsif ($field eq 'id') {
+                    $names{$field}  = $uid;
+                }
+            }
+        }
+    }
     if ($first)  { $names{'firstname'}  = $first; }
     if (defined($middle)) { $names{'middlename'} = $middle; }
     if ($last)   { $names{'lastname'}   = $last; }
@@ -10238,9 +10263,16 @@
 
 =item *
 
-modifyuser($udom,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,
-           $forceid,$desiredhome,$email,$inststatus) : 
-modify user
+modifyuser($udom,$uname,$uid,$umode,$upass,$first,$middle,$last, $gene,
+           $forceid,$desiredhome,$email,$inststatus,$candelete) :
+
+will update user information (firstname,middlename,lastname,generation,
+permanentemail), and if forceid is true, student/employee ID also.
+A user's institutional affiliation(s) can also be updated.
+User information fields will not be overwritten with empty entries 
+unless the field is included in the $candelete array reference.
+This array is included when a single user is modified via "Manage Users",
+or when Autoupdate.pl is run by cron in a domain.
 
 =item *
 
Index: loncom/enrollment/Autoupdate.pl
diff -u loncom/enrollment/Autoupdate.pl:1.15 loncom/enrollment/Autoupdate.pl:1.16
--- loncom/enrollment/Autoupdate.pl:1.15	Sun Mar 21 20:39:30 2010
+++ loncom/enrollment/Autoupdate.pl	Sun Mar 21 21:06:00 2010
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 #
 # Automated Userinfo update script
-# $Id: Autoupdate.pl,v 1.15 2010/03/21 20:39:30 raeburn Exp $
+# $Id: Autoupdate.pl,v 1.16 2010/03/21 21:06:00 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -128,7 +128,7 @@
                         foreach my $field (@fields) {
                             $userupdate{$field} = $instusers{$uname}{$field};
                         }
-                        my $modresult = &Apache::lonnet::modifyuser($dom,$uname,$userupdate{'id'},undef,undef,$userupdate{'firstname'},$userupdate{'middlename'},$userupdate{'lastname'},$userupdate{'generation'},1,$hostid,$userupdate{'permanentemail'});
+                        my $modresult = &Apache::lonnet::modifyuser($dom,$uname,$userupdate{'id'},undef,undef,$userupdate{'firstname'},$userupdate{'middlename'},$userupdate{'lastname'},$userupdate{'generation'},1,$hostid,$userupdate{'permanentemail'},undef,\@fields);
                         if ($modresult eq 'ok') {
                             print $fh "User change: $uname:$dom; New values: 1.Name: $userupdate{'firstname'} $userupdate{'middlename'} $userupdate{'lastname'} $userupdate{'generation'}; 2. StuID: $userupdate{'id'}; 3. Email: $userupdate{'permanentemail'}.\n";
                             if ($settings->{'classlists'} == 1) {

--raeburn1269205560--