[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

raeburn raeburn@source.lon-capa.org
Fri, 08 May 2009 01:43:50 -0000


raeburn		Fri May  8 01:43:50 2009 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Bug 5946
  Make check for privileged users (i.e. DCs) in lonnet::get_course_adv_roles() 
    more efficient, in cases where there are many users with non-student roles.
  Get information from nohist_domainroles.db for domain(s) of adv users in course,
    instead of from roles.db for each separate user.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.996 loncom/lonnet/perl/lonnet.pm:1.997
--- loncom/lonnet/perl/lonnet.pm:1.996	Wed May  6 12:13:26 2009
+++ loncom/lonnet/perl/lonnet.pm	Fri May  8 01:43:50 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.996 2009/05/06 12:13:26 raeburn Exp $
+# $Id: lonnet.pm,v 1.997 2009/05/08 01:43:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2734,6 +2734,7 @@
     my %dumphash=
             &dump('nohist_userroles',$coursehash{'domain'},$coursehash{'num'});
     my $now=time;
+    my %privileged;
     foreach my $entry (keys %dumphash) {
 	my ($tend,$tstart)=split(/\:/,$dumphash{$entry});
         if (($tstart) && ($tstart<0)) { next; }
@@ -2741,8 +2742,21 @@
         if (($tstart) && ($now<$tstart)) { next; }
         my ($role,$username,$domain,$section)=split(/\:/,$entry);
 	if ($username eq '' || $domain eq '') { next; }
-	if ((&privileged($username,$domain)) && 
-	    (!$nothide{$username.':'.$domain})) { next; }
+        unless (ref($privileged{$domain}) eq 'HASH') {
+            my %dompersonnel =
+                &Apache::lonnet::get_domain_roles($domain,['dc'],undef,$now);
+            $privileged{$domain} = {};
+            foreach my $server (keys(%dompersonnel)) {
+                if(ref($dompersonnel{$server}) eq 'HASH') {
+                    foreach my $user (keys(%{$dompersonnel{$server}})) {
+                        my ($trole,$uname,$udom) = split(/:/,$user);
+                        $privileged{$udom}{$uname} = 1;
+                    }
+                }
+            }
+        }
+        if ((exists($privileged{$domain}{$username})) && 
+            (!$nothide{$username.':'.$domain})) { next; }
 	if ($role eq 'cr') { next; }
         if ($codes) {
             if ($section) { $role .= ':'.$section; }