[LON-CAPA-cvs] cvs: loncom /enrollment Autoupdate.pl

raeburn raeburn at source.lon-capa.org
Tue Aug 31 22:14:42 EDT 2021


raeburn		Wed Sep  1 02:14:42 2021 EDT

  Modified files:              
    /loncom/enrollment	Autoupdate.pl 
  Log:
  - Bug 6959 Automated update can be configured to skip checking for changes
    in user information for users deemed inactive.
  
  
Index: loncom/enrollment/Autoupdate.pl
diff -u loncom/enrollment/Autoupdate.pl:1.23 loncom/enrollment/Autoupdate.pl:1.24
--- loncom/enrollment/Autoupdate.pl:1.23	Wed Jan 27 22:23:18 2016
+++ loncom/enrollment/Autoupdate.pl	Wed Sep  1 02:14:42 2021
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 #
 # Automated Userinfo update script
-# $Id: Autoupdate.pl,v 1.23 2016/01/27 22:23:18 raeburn Exp $
+# $Id: Autoupdate.pl,v 1.24 2021/09/01 02:14:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -28,6 +28,7 @@
     use strict;
     use lib '/home/httpd/lib/perl';
     use localenroll;
+    use GDBM_File;
     use Apache::lonnet;
     use Apache::loncommon;
     use Apache::lonlocal;
@@ -53,11 +54,19 @@
         #only run if configured to
         my $run_update = 0;
         my $settings;
+        my $allowed_inactivity;
+        my $check_unexpired;
         if (ref($domconfig{'autoupdate'}) eq 'HASH') {
             $settings = $domconfig{'autoupdate'};
             if ($settings->{'run'} eq '1') {
                 $run_update = 1;
             }
+            if ($settings->{'lastactive'} =~/^\d+$/) {
+                $allowed_inactivity = 86400 * $settings->{'lastactive'};
+            }
+            if ($settings->{'unexpired'}) {
+                $check_unexpired = 1;
+            }
         }
         next if (!$run_update);
         open(my $fh,">>$logfile");
@@ -67,7 +76,7 @@
         # get user information
         my (%users,%instusers,%instids);
         my $dir = $Apache::lonnet::perlvar{lonUsersDir}.'/'.$dom;
-        &descend_tree($dom,$dir,0,\%users,\%courses);
+        &descend_tree($dom,$dir,0,\%users,\%courses,$allowed_inactivity,$check_unexpired);
         my $resp = &localenroll::allusers_info($dom,\%instusers,\%instids,\%users);
         if ($resp ne 'ok') {
             print $fh &mt('Problem retrieving institutional data for users in domain: [_1].',$dom)."\n".
@@ -191,7 +200,7 @@
     }
 
 sub descend_tree {
-    my ($dom,$dir,$depth,$alldomusers,$coursesref) = @_;
+    my ($dom,$dir,$depth,$alldomusers,$coursesref,$allowed_inactivity,$check_unexpired) = @_;
     if (-d $dir) {
         opendir(DIR,$dir);
         my @contents = grep(!/^\./,readdir(DIR));
@@ -199,11 +208,58 @@
         $depth ++;
         foreach my $item (@contents) {
             if (($depth < 4) && (length($item) == 1)) {
-                &descend_tree($dom,$dir.'/'.$item,$depth,$alldomusers,$coursesref);
+                &descend_tree($dom,$dir.'/'.$item,$depth,$alldomusers,$coursesref,
+                              $allowed_inactivity,$check_unexpired);
             } elsif (-e $dir.'/'.$item.'/passwd') {
                 if (ref($coursesref) eq 'HASH') {
                     next if (exists($coursesref->{$dom.'_'.$item}));
                 }
+                if ($allowed_inactivity) {
+                    my $now = time;
+                    my $aclog = $dir.'/'.$item.'/activity.log';
+                    my $roledb = $dir.'/'.$item.'/roles.db';
+                    if (-e $aclog) {
+                        my $lastac=(stat($aclog))[9];
+                        if (($now - $lastac) > $allowed_inactivity) {
+                            if (-e $roledb) {
+                                my $lastrolechg=(stat($roledb))[9];
+                                next if (($now - $lastrolechg) > $allowed_inactivity);
+                            } else {
+                                next;
+                            }
+                        }
+                    } elsif (-e $roledb) {
+                        my $lastrolechg=(stat($roledb))[9];
+                        next if (($now - $lastrolechg) > $allowed_inactivity);
+                    } else {
+                        next;
+                    }
+                }
+                if ($check_unexpired) {
+                    my $roledb = $dir.'/'.$item.'/roles.db';
+                    my $unexpired = 0;
+                    my $now = time;
+                    if (-e $roledb) {
+                        my $roleshash = &LONCAPA::tie_user_hash($dom,$item,'roles',&GDBM_READER()) or next;
+                        if (ref($roleshash)) {
+                            while (my ($key,$value) = each(%$roleshash)) {
+                                next if ($key =~ /^rolesdef/);
+                                my ($role,$roleend,$rolestart) = split(/\_/,$value);
+                                next if ($role =~ /^gr\//);
+                                if (!$roleend || $roleend > $now) {
+                                    $unexpired = 1;
+                                    last;
+                                }
+                            }
+                            &LONCAPA::untie_user_hash($roleshash);
+                            next unless ($unexpired);
+                        } else {
+                            next;
+                        }
+                    } else {
+                        next;
+                    }
+                }
                 $$alldomusers{$item} = '';
             }
         }




More information about the LON-CAPA-cvs mailing list