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

raeburn raeburn at source.lon-capa.org
Wed Dec 6 23:47:00 EST 2023


raeburn		Thu Dec  7 04:47:00 2023 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm 
  Log:
  - Prevent name information in classlist.db files being updated with empty
    string(s) if file upload by DC i used make bulk change(s) to studentIDs
    when csv file lacks column(s) containing name information for users.
  
  
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.219 loncom/interface/lonuserutils.pm:1.220
--- loncom/interface/lonuserutils.pm:1.219	Sat Nov  4 00:06:00 2023
+++ loncom/interface/lonuserutils.pm	Thu Dec  7 04:47:00 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.219 2023/11/04 00:06:00 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.220 2023/12/07 04:47:00 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -104,7 +104,7 @@
 sub modifyuserrole {
     my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
         $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
-        $end,$start,$checkid,$inststatus) = @_;
+        $end,$start,$checkid,$inststatus,$emptyok) = @_;
     my ($scope,$userresult,$authresult,$roleresult,$idresult);
     if ($setting eq 'course' || $context eq 'course') {
         $scope = '/'.$cid;
@@ -139,6 +139,25 @@
                                   generation => $gene,
                                   id         => $uid,
                                  );
+
+                # When "Update ID in user's course(s)" and "Force change of existing ID"
+                # checkboxes both checked, prevent replacement of name information
+                # in classlist.db file(s) for the user's course(s) with blank(s),
+                # in the case where the uploaded csv file was without column(s) for
+                # the particular field. Fields are: First Name, Middle Names/Initials,
+                # Last Name (or the composite: Last Name, First Names), and Generation.
+
+                my %emptyallowed;
+                if ((ref($emptyok) eq 'HASH') && (keys(%{$emptyok}) > 0)) {
+                    %emptyallowed = %{$emptyok};
+                }
+                foreach my $field (keys(%userupdate)) {
+                    if ($userupdate{$field} eq '') {
+                        unless ($emptyallowed{$field}) {
+                            delete($userupdate{$field});
+                        }
+                    }
+                }
                 $idresult = &propagate_id_change($uname,$udom,\%userupdate);
             }
         }
@@ -4780,9 +4799,25 @@
         $fieldstype{$field.'_choice'} = 'scalar';
     }
     &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
-    my ($cid,$crstype,$setting,$crsdom,$crsnum,$oldcrsuserdoms);
+    my ($cid,$crstype,$setting,$crsdom,$crsnum,$oldcrsuserdoms,%emptyok);
     if ($context eq 'domain') {
         $setting = $env{'form.roleaction'};
+        if (exists($fields{'names'})) {
+            map { $emptyok{$_} = 1; } ('lastname','firstname','middlename');
+        } else {
+            if (exists($fields{'lname'})) {
+                $emptyok{'lastname'} = 1;
+            }
+            if (exists($fields{'fname'})) {
+                $emptyok{'firstname'} = 1;
+            }
+            if (exists($fields{'mname'})) {
+                $emptyok{'middlename'} = 1;
+            }
+        }
+        if (exists($fields{'gen'})) {
+            $emptyok{'generation'} = 1;
+        }
     }
     if ($env{'request.course.id'} ne '') {
         $cid = $env{'request.course.id'};
@@ -5604,7 +5639,7 @@
                                                 $mname,$lname,$gen,$singlesec,
                                                 $env{'form.forceid'},$desiredhost,
                                                 $email,$role,$enddate,$startdate,
-                                                $checkid,$inststatus);
+                                                $checkid,$inststatus,\%emptyok);
                         }
                     }
                     if ($multiple) {




More information about the LON-CAPA-cvs mailing list