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

raeburn raeburn at source.lon-capa.org
Sun Aug 9 17:43:18 EDT 2015


raeburn		Sun Aug  9 21:43:18 2015 EDT

  Modified files:              
    /loncom	lonsql 
    /loncom/interface	lonuserutils.pm loncommon.pm 
  Log:
  - Bug 5596
    - Message shown that initial retrieval of institutional data may take time.
    - Progress indicator displayed while enrollment in progress
    - Where institutional data are available for a user being added, that 
      replaces data included in file upload.
    - Student/employee ID checking for both new users and existing users
      if rule(s) specified in localenroll.pm for domain, and enabled via:
      domain configuration > User Creation > Format rules to check for IDs.
  
  
-------------- next part --------------
Index: loncom/lonsql
diff -u loncom/lonsql:1.94 loncom/lonsql:1.95
--- loncom/lonsql:1.94	Wed Aug  5 18:47:12 2015
+++ loncom/lonsql	Sun Aug  9 21:43:11 2015
@@ -3,7 +3,7 @@
 # The LearningOnline Network
 # lonsql - LON TCP-MySQL-Server Daemon for handling database requests.
 #
-# $Id: lonsql,v 1.94 2015/08/05 18:47:12 raeburn Exp $
+# $Id: lonsql,v 1.95 2015/08/09 21:43:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -637,11 +637,12 @@
         if ($@) {
             $response = 'error';
         } elsif ($result eq 'ok') {
+            $response = $result;
             if (keys(%instusers)) {
-                $response = $result.':'.&Apache::lonnet::freeze_escape(\%instusers); 
+                $response .= '='.&Apache::lonnet::freeze_escape(\%instusers);
             }
-        } else {
-            $response = 'unavailable';
+        } elsif ($result eq 'unavailable') {
+            $response = $result;
         }
     } else {
         $response = 'invalid';
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.171 loncom/interface/lonuserutils.pm:1.172
--- loncom/interface/lonuserutils.pm:1.171	Wed Aug  5 18:47:21 2015
+++ loncom/interface/lonuserutils.pm	Sun Aug  9 21:43:18 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.171 2015/08/05 18:47:21 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.172 2015/08/09 21:43:18 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4297,7 +4297,7 @@
         my $newuserdom = $env{'request.role.domain'};
         map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
         # Get new users list
-        my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%idinst_results,%alerts,%checkuname);
+        my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname);
         my $counter = -1;
         foreach my $line (@userdata) {
             $counter ++;
@@ -4507,7 +4507,7 @@
                         }
                         $checkid = 1;
                         $newuser = 1;
-                        $checkuname{$username.':'.$newuserdom} = { 'newuser' => 1, 'id' => 1 };
+                        $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
                     } else {
                         if ($context eq 'course' || $context eq 'author') {
                             if ($userdomain eq $domain ) {
@@ -4566,34 +4566,41 @@
         } # end of foreach (@userdata)
         if ($counter > -1) {
             my $total = $counter + 1;
-            my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
             my %checkids;
-            if (keys(%existinguser)) {
-                foreach my $dom (keys(%existinguser)) {
-                    if (ref($existinguser{$dom}) eq 'HASH') {
-                        my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
-                        foreach my $username (keys(%{$existinguser{$dom}})) {
-                            if ($idhash{$username} ne $existinguser{$dom}{$username}) {
-                                $checkids{$username.':'.$dom} = { 'id' => $existinguser{$dom}{$username} };
+            if ((keys(%existinguser)) || (keys(%checkuname))) {
+                $r->print(&mt('Please be patient -- checking for institutional data ...'));
+                $r->rflush();
+                if (keys(%existinguser)) {
+                    foreach my $dom (keys(%existinguser)) {
+                        if (ref($existinguser{$dom}) eq 'HASH') {
+                            my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
+                            foreach my $username (keys(%{$existinguser{$dom}})) {
+                                if ($idhash{$username} ne $existinguser{$dom}{$username}) {
+                                    $checkids{$username.':'.$dom} = {
+                                                                    'id' => $existinguser{$dom}{$username},
+                                                                    };
+                                }
+                            }
+                            if (keys(%checkids)) {
+                                &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
+                                                                    \%alerts,\%rulematch,
+                                                                    \%inst_results,\%curr_rules,
+                                                                    \%got_rules);
                             }
-                        }
-                        if (keys(%checkids)) {
-                            &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
-                                                                \%alerts,\%rulematch,
-                                                                \%idinst_results,\%curr_rules,
-                                                                \%got_rules);
                         }
                     }
                 }
+                if (keys(%checkuname)) {
+                    &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
+                                                        \%alerts,\%rulematch,\%inst_results,
+                                                        \%curr_rules,\%got_rules);
+                }
+                $r->print(' '.&mt('done').'<br /><br />');
+                $r->rflush();
             }
-            if (keys(%checkuname)) {
-                &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1 },
-                                                    \%alerts,\%rulematch,\%inst_results,
-                                                    \%curr_rules,\%got_rules);
-            }
+            my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
             $r->print('<ul>');
             for (my $i=0; $i<=$counter; $i++) {
-                &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
                 if ($disallow{$i}) {
                     $r->print('<li>'.$disallow{$i}.'</li>');
                 } elsif (ref($userinfo{$i}) eq 'HASH') {
@@ -4627,6 +4634,40 @@
                                 }
                             }
                         }
+                        if (ref($inst_results{$user}) eq 'HASH') {
+                            if ($inst_results{$user}{'firstname'} ne '') {
+                                $fname = $inst_results{$user}{'firstname'};
+                            }
+                            if ($inst_results{$user}{'middlename'} ne '') {
+                                $mname = $inst_results{$user}{'middlename'};
+                            }
+                            if ($inst_results{$user}{'lasttname'} ne '') {
+                                $lname = $inst_results{$user}{'lastname'};
+                            }
+                            if ($inst_results{$user}{'permanentemail'} ne '') {
+                                $email = $inst_results{$user}{'permanentemail'};
+                            }
+                            if ($inst_results{$user}{'id'} ne '') {
+                                $id = $inst_results{$user}{'id'};
+                                $checkid = 0;
+                            }
+                            if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
+                                $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
+                            }
+                        }
+                        if (($checkid) && ($id ne '')) {
+                            if (ref($alerts{'id'}) eq 'HASH') {
+                                if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
+                                    if ($alerts{'id'}{$userdomain}{$username}) {
+                                        $r->print('<li>'.
+                                                  &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
+                                                  '<b>'.$username.'</b>').'<br />'.
+                                                  &mt('Consequently, the user was not created.').'</li>');
+                                        next;
+                                    }
+                                }
+                            }
+                        }
                         my $usertype = 'unofficial';
                         if (ref($rulematch{$user}) eq 'HASH') {
                             if ($rulematch{$user}{'username'}) {
@@ -4639,18 +4680,17 @@
                                       &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype).'</li>');
                             next;
                         }
-                    }
-                    if ($id ne '') {
+                    } elsif ($id ne '') {
                         if (exists($checkids{$user})) {
                             $checkid = 1; 
                             if (ref($alerts{'id'}) eq 'HASH') {
                                 if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
-                                    if ($alerts{'id'}{$userdomain}{$id}) {
+                                    if ($alerts{'id'}{$userdomain}{$username}) {
                                         $r->print('<li>'.
-                                                  &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is found by your directory service.',
+                                                  &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
                                                   '<b>'.$username.'</b>').'<br />'.
-                                                  &mt('Consequently, the user was not created.').'</li>');
-                                        next;
+                                                  &mt('Consequently, the ID was not changed.').'</li>');
+                                        $id = '';
                                     }
                                 }
                             }
@@ -4729,8 +4769,9 @@
                                                 $username,$userdomain,\%userchg);
                     }
                 }
-                $r->print('</ul>');
+                &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
             } # end of loop
+            $r->print('</ul>');
             &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
         }
         # Flush the course logs so reverse user roles immediately updated
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1226 loncom/interface/loncommon.pm:1.1227
--- loncom/interface/loncommon.pm:1.1226	Wed Aug  5 18:47:21 2015
+++ loncom/interface/loncommon.pm	Sun Aug  9 21:43:18 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1226 2015/08/05 18:47:21 raeburn Exp $
+# $Id: loncommon.pm,v 1.1227 2015/08/09 21:43:18 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -9779,13 +9779,19 @@
                 if ($checkid) {
                     if (ref($usershash->{$user}) eq 'HASH') {
                         if ($usershash->{$user}->{'id'} ne '') {
-                            $by_id{$udom}{$usershash->{$user}->{'id'}} = 1; 
+                            $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname; 
                             $userdoms{$udom} = 1;
+                            if (ref($inst_results) eq 'HASH') {
+                                $inst_results->{$uname.':'.$udom} = {};
+                            }
                         }
                     }
                 } else {
                     $by_username{$udom}{$uname} = 1;
                     $userdoms{$udom} = 1;
+                    if (ref($inst_results) eq 'HASH') {
+                        $inst_results->{$uname.':'.$udom} = {};
+                    }
                 }
             }
             foreach my $udom (keys(%userdoms)) {
@@ -9795,8 +9801,8 @@
                     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                         foreach my $item ('username','id') {
                             if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
-                               $$curr_rules{$udom}{$item} =
-                                   $domconfig{'usercreation'}{$item.'_rule'};
+                                $$curr_rules{$udom}{$item} =
+                                    $domconfig{'usercreation'}{$item.'_rule'};
                             }
                         }
                     }
@@ -9807,10 +9813,16 @@
                 foreach my $udom (keys(%by_id)) {
                     my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
                     if ($outcome eq 'ok') {
+                        foreach my $id (keys(%{$by_id{$udom}})) {
+                            my $uname = $by_id{$udom}{$id};
+                            $inst_response{$uname.':'.$udom} = $outcome;
+                        }
                         if (ref($results) eq 'HASH') {
                             foreach my $uname (keys(%{$results})) {
-                                $inst_response{$uname.':'.$udom} = $outcome;
-                                $inst_results->{$uname.':'.$udom} = $results->{$uname};
+                                if (exists($inst_response{$uname.':'.$udom})) {
+                                    $inst_response{$uname.':'.$udom} = $outcome;
+                                    $inst_results->{$uname.':'.$udom} = $results->{$uname};
+                                }
                             }
                         }
                     }
@@ -9819,9 +9831,11 @@
                 foreach my $udom (keys(%by_username)) {
                     my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
                     if ($outcome eq 'ok') {
+                        foreach my $uname (keys(%{$by_username{$udom}})) {
+                            $inst_response{$uname.':'.$udom} = $outcome;
+                        }
                         if (ref($results) eq 'HASH') {
                             foreach my $uname (keys(%{$results})) {
-                                $inst_response{$uname.':'.$udom} = $outcome;
                                 $inst_results->{$uname.':'.$udom} = $results->{$uname};
                             }
                         }
@@ -9876,8 +9890,15 @@
             my ($uname,$udom) = split(/:/,$user);
             next if (($udom eq '') || ($uname eq ''));
             my $id;
-            if (ref($usershash->{$user})) {
-                $id = $usershash->{$user}->{'id'};
+            if (ref($inst_results) eq 'HASH') {
+                if (ref($inst_results->{$user}) eq 'HASH') {
+                    $id = $inst_results->{$user}->{'id'};
+                }
+            }
+            if ($id eq '') { 
+                if (ref($usershash->{$user})) {
+                    $id = $usershash->{$user}->{'id'};
+                }
             }
             foreach my $item (keys(%{$checks})) {
                 if (ref($$curr_rules{$udom}) eq 'HASH') {
@@ -9893,6 +9914,10 @@
                                             if (ref($inst_results->{$user}) eq 'HASH') {
                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                                                     $$alerts{$item}{$udom}{$uname} = 1;
+                                                } elsif ($item eq 'id') {
+                                                    if ($inst_results->{$user}->{'id'} eq '') {
+                                                        $$alerts{$item}{$udom}{$uname} = 1;
+                                                    }
                                                 }
                                             }
                                         }


More information about the LON-CAPA-cvs mailing list