[LON-CAPA-cvs] cvs: loncom /build add_domain_coordinator_privilege.pl expire_DC_role.pl make_domain_coordinator.pl /interface loncreateuser.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Fri Aug 17 18:43:58 EDT 2012


raeburn		Fri Aug 17 22:43:58 2012 EDT

  Modified files:              
    /loncom/build	make_domain_coordinator.pl 
                 	add_domain_coordinator_privilege.pl expire_DC_role.pl 
    /loncom/interface	loncreateuser.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Logging of role changes for domain roles and co-author roles
    (who, what, when, context, and by whom).
  - Access to appropriate log via submenu in Modify users in au or dc context
  - Scripts used to make, add or expire DC role from command line also write
    to rolelog.db on same server (stored with domainconfig user). 
  
  
-------------- next part --------------
Index: loncom/build/make_domain_coordinator.pl
diff -u loncom/build/make_domain_coordinator.pl:1.21 loncom/build/make_domain_coordinator.pl:1.22
--- loncom/build/make_domain_coordinator.pl:1.21	Thu Nov 17 14:35:22 2011
+++ loncom/build/make_domain_coordinator.pl	Fri Aug 17 22:43:03 2012
@@ -11,7 +11,7 @@
 # The LearningOnline Network
 # make_domain_coordinator.pl - Make a domain coordinator on a system
 #
-# $Id: make_domain_coordinator.pl,v 1.21 2011/11/17 14:35:22 raeburn Exp $
+# $Id: make_domain_coordinator.pl,v 1.22 2012/08/17 22:43:03 raeburn Exp $
 #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
 #
@@ -96,6 +96,7 @@
 use Apache::lonnet;
 use Apache::lonlocal;
 use DBI;
+use Storable qw(nfreeze);
 use strict;
 
 =pod
@@ -476,6 +477,35 @@
  system('/bin/chown',"www:www","$dompath/nohist_domainroles.db"); # Must be writeable by httpd process.
  system('/bin/chown',"www:www","$dompath/nohist_domainroles.db.lock");
 
+# Log with domainconfiguser in nohist_rolelog.db
+my $domconfiguser = $domain.'-domainconfig';
+my $subdir = $domconfiguser;
+$subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/;
+
+my $rolelogref = &LONCAPA::locking_hash_tie("$dompath/$subdir/$domconfiguser/nohist_rolelog.db",&GDBM_WRCREAT());
+my $domlogkey = &LONCAPA::escape($now.'00000'.$$.'000000'); 
+my $storehash = {
+                   role    => 'dc',
+                   start   => $now,
+                   end     => 0,
+                   context => 'server',
+                };
+my $domlogvalue = {
+                    'exe_uname' => '',
+                    'exe_udom'  => $domain,
+                    'exe_time'  => $now,
+                    'exe_ip'    => '127.0.0.1',
+                    'delflag'   => '',
+                    'logentry'  => $storehash,
+                    'uname'     => $username,
+                    'udom'      => $domain,
+                 };
+$rolelogref->{$domlogkey}=&freeze_escape($domlogvalue);
+&LONCAPA::locking_hash_untie($rolelogref);
+
+ system('/bin/chown',"www:www","$dompath/$subdir/nohist_rolelog.db"); # Must be writeable by httpd process.
+ system('/bin/chown',"www:www","$dompath/$subdir/nohist_rolelog.db.lock");
+
 #Update allusers MySQL table
 
 print(&mt('Adding new user to allusers table.')."\n");
@@ -574,6 +604,15 @@
     return $newpasswd;
 }
 
+sub freeze_escape {
+    my ($value)=@_;
+    if (ref($value)) {
+        $value=&nfreeze($value);
+        return '__FROZEN__'.&LONCAPA::escape($value);
+    }
+    return &LONCAPA::escape($value);
+}
+
 =pod
 
 =head1 AUTHOR
Index: loncom/build/add_domain_coordinator_privilege.pl
diff -u loncom/build/add_domain_coordinator_privilege.pl:1.7 loncom/build/add_domain_coordinator_privilege.pl:1.8
--- loncom/build/add_domain_coordinator_privilege.pl:1.7	Sun May 29 17:54:21 2011
+++ loncom/build/add_domain_coordinator_privilege.pl	Fri Aug 17 22:43:03 2012
@@ -14,7 +14,7 @@
 # add_domain_coordinator_privilege.pl - Add domain coordinator to an
 #    exisiting user on a LON-CAPA system.
 #
-# $Id: add_domain_coordinator_privilege.pl,v 1.7 2011/05/29 17:54:21 raeburn Exp $
+# $Id: add_domain_coordinator_privilege.pl,v 1.8 2012/08/17 22:43:03 raeburn Exp $
 #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
 #
@@ -79,6 +79,7 @@
 use Apache::lonnet;
 use Apache::loncommon;
 use Apache::lonlocal;
+use Storable qw(nfreeze);
 
 =pod
 
@@ -234,6 +235,35 @@
 system('/bin/chown',"www:www","$dompath/nohist_domainroles.db"); # Must be writeable by httpd process.
 system('/bin/chown',"www:www","$dompath/nohist_domainroles.db.lock");
 
+# Log with domainconfiguser in nohist_rolelog.db
+my $domconfiguser = $domain.'-domainconfig';
+my $subdir = $domconfiguser;
+$subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/;
+
+my $rolelogref = &LONCAPA::locking_hash_tie("$dompath/$subdir/$domconfiguser/nohist_rolelog.db",&GDBM_WRCREAT());
+my $domlogkey = &LONCAPA::escape($now.'00000'.$$.'000000');
+my $storehash = {
+                   role    => 'dc',
+                   start   => $now,
+                   end     => 0,
+                   context => 'server',
+                };
+my $domlogvalue = {
+                    'exe_uname' => '',
+                    'exe_udom'  => $domain,
+                    'exe_time'  => $now,
+                    'exe_ip'    => '127.0.0.1',
+                    'delflag'   => '',
+                    'logentry'  => $storehash,
+                    'uname'     => $username,
+                    'udom'      => $domain,
+                 };
+$rolelogref->{$domlogkey}=&freeze_escape($domlogvalue);
+&LONCAPA::locking_hash_untie($rolelogref);
+
+ system('/bin/chown',"www:www","$dompath/$subdir/nohist_rolelog.db"); # Must be writeable by httpd process.
+ system('/bin/chown',"www:www","$dompath/$subdir/nohist_rolelog.db.lock");
+
 =pod
 
 =item 2.
@@ -248,3 +278,12 @@
       "\n");
 exit;
 
+sub freeze_escape {
+    my ($value)=@_;
+    if (ref($value)) {
+        $value=&nfreeze($value);
+        return '__FROZEN__'.&LONCAPA::escape($value);
+    }
+    return &LONCAPA::escape($value);
+}
+
Index: loncom/build/expire_DC_role.pl
diff -u loncom/build/expire_DC_role.pl:1.3 loncom/build/expire_DC_role.pl:1.4
--- loncom/build/expire_DC_role.pl:1.3	Fri Jul  6 13:49:32 2012
+++ loncom/build/expire_DC_role.pl	Fri Aug 17 22:43:03 2012
@@ -6,7 +6,7 @@
 # a user who currently has such a role in a domain for which current server is
 # a library server for the domain.
 # 
-# $Id: expire_DC_role.pl,v 1.3 2012/07/06 13:49:32 raeburn Exp $
+# $Id: expire_DC_role.pl,v 1.4 2012/08/17 22:43:03 raeburn Exp $
 #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
 #
@@ -70,6 +70,7 @@
 use Apache::lonnet;
 use Apache::loncommon;
 use Apache::lonlocal;
+use Storable qw(nfreeze);
 
 =pod
 
@@ -199,7 +200,55 @@
  system('/bin/chown',"www:www","$dompath/nohist_domainroles.db"); # Must be writeable by httpd process.
  system('/bin/chown',"www:www","$dompath/nohist_domainroles.db.lock");
 
+# Log with domainconfiguser in nohist_rolelog.db
+my $domconfiguser = $domain.'-domainconfig';
+my $subdir = $domconfiguser;
+$subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/;
+
+print "Looking to tie $dompath/$subdir/nohist_rolelog.db\n";
+
+my $rolelogref = &LONCAPA::locking_hash_tie("$dompath/$subdir/$domconfiguser/nohist_rolelog.db",&GDBM_WRCREAT());
+
+if (ref($rolelogref) eq 'HASH') {
+    foreach my $key (keys(%{$rolelogref})) {
+        print "found $key\n";
+    }
+}
+
+my $domlogkey = &LONCAPA::escape($now.'00000'.$$.'000000');
+my $storehash = {
+                   role    => 'dc',
+                   start   => $start,
+                   end     => $now,
+                   context => 'server',
+                };
+my $domlogvalue = {
+                    'exe_uname' => '',
+                    'exe_udom'  => $domain,
+                    'exe_time'  => $now,
+                    'exe_ip'    => '127.0.0.1',
+                    'delflag'   => '',
+                    'logentry'  => $storehash,
+                    'uname'     => $username,
+                    'udom'      => $domain,
+                 };
+$rolelogref->{$domlogkey}=&freeze_escape($domlogvalue);
+&LONCAPA::locking_hash_untie($rolelogref);
+
+ system('/bin/chown',"www:www","$dompath/$subdir/nohist_rolelog.db"); # Must be writeable by httpd process.
+ system('/bin/chown',"www:www","$dompath/$subdir/nohist_rolelog.db.lock");
+
+
 # Output success message.
 print(&mt('User: [_1], domain coordinator role expired in domain: [_2].',$user,$role_domain)."\n");
 
+sub freeze_escape {
+    my ($value)=@_;
+    if (ref($value)) {
+        $value=&nfreeze($value);
+        return '__FROZEN__'.&LONCAPA::escape($value);
+    }
+    return &LONCAPA::escape($value);
+}
+
 exit;
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.362 loncom/interface/loncreateuser.pm:1.363
--- loncom/interface/loncreateuser.pm:1.362	Tue Aug 14 15:45:06 2012
+++ loncom/interface/loncreateuser.pm	Fri Aug 17 22:43:31 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.362 2012/08/14 15:45:06 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.363 2012/08/17 22:43:31 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1701,7 +1701,7 @@
                     $allowed=1;
                 }
             }
-            if ($role_code eq 'ca' || $role_code eq 'au') {
+            if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
                 $class='Construction Space';
             } elsif ($role_code eq 'su') {
                 $class='System';
@@ -4496,10 +4496,14 @@
                           $cdom,$cnum,$coursedesc));
         }
     } elsif ($env{'form.action'} eq 'changelogs') {
+        my $helpitem;
+        if ($context eq 'course') {
+            $helpitem = 'Course_User_Logs';
+        }
         push (@{$brcrum},
                  {href => '/adm/createuser?action=changelogs',
                   text => 'User Management Logs',
-                  help => 'Course_User_Logs'});
+                  help => $helpitem});
         $bread_crumbs_component = 'User Changes';
         $args = { bread_crumbs           => $brcrum,
                   bread_crumbs_component => $bread_crumbs_component};
@@ -4659,6 +4663,14 @@
              permission => $permission->{'cusr'},
              linktitle => 'Approve or reject author role requests',
             },
+            {
+             linktext => 'Change Log',
+             icon => 'document-properties.png',
+             #help => 'Course_User_Logs',
+             url => '/adm/createuser?action=changelogs',
+             permission => $permission->{'cusr'},
+             linktitle => 'View change log.',
+            },
         );
         
     }elsif ($context eq 'course'){
@@ -4775,8 +4787,17 @@
                 },
             );
         }
-    };
-return Apache::lonhtmlcommon::generate_menu(@menu);
+    } elsif ($context eq 'author') {
+            {
+             linktext => 'Change Log',
+             icon => 'document-properties.png',
+             #help => 'Course_User_Logs',
+             url => '/adm/createuser?action=changelogs',
+             permission => $permission->{'cusr'},
+             linktitle => 'View change log.',
+            },
+    }
+    return Apache::lonhtmlcommon::generate_menu(@menu);
 #               { text => 'View Log-in History',
 #                 help => 'Course_User_Logins',
 #                 action => 'logins',
@@ -5466,18 +5487,35 @@
 
 sub print_userchangelogs_display {
     my ($r,$context,$permission) = @_;
-    my $formname = 'roleslog';
-    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-    my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-    my $crstype = &Apache::loncommon::course_type();
-    my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
+    my $formname = 'rolelog';
+    my ($username,$domain,$crstype,%roleslog);
+    if ($context eq 'domain') {
+        $domain = $env{'request.role.domain'};
+        %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
+    } else {
+        if ($context eq 'course') { 
+            $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
+            $username = $env{'course.'.$env{'request.course.id'}.'.num'};
+            $crstype = &Apache::loncommon::course_type();
+            my %saveable_parameters = ('show' => 'scalar',);
+            &Apache::loncommon::store_course_settings('roles_log',
+                                                      \%saveable_parameters);
+            &Apache::loncommon::restore_course_settings('roles_log',
+                                                        \%saveable_parameters);
+        } elsif ($context eq 'author') {
+            $domain = $env{'user.domain'}; 
+            if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
+                $username = $env{'user.name'};
+            } else {
+                undef($domain);
+            }
+        }
+        if ($domain ne '' && $username ne '') { 
+            %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
+        }
+    }
     if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
 
-    my %saveable_parameters = ('show' => 'scalar',);
-    &Apache::loncommon::store_course_settings('roles_log',
-                                              \%saveable_parameters);
-    &Apache::loncommon::restore_course_settings('roles_log',
-                                                \%saveable_parameters);
     # set defaults
     my $now = time();
     my $defstart = $now - (7*24*3600); #7 days ago 
@@ -5519,7 +5557,8 @@
 
     # Form Header
     $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
-              &role_display_filter($formname,$cdom,$cnum,\%curr,$version,$crstype));
+              &role_display_filter($context,$formname,$domain,$username,\%curr,
+                                   $version,$crstype));
 
     # Create navigation
     my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records);
@@ -5532,9 +5571,13 @@
        .'<th>'.&mt('When').'</th>'
        .'<th>'.&mt('Who made the change').'</th>'
        .'<th>'.&mt('Changed User').'</th>'
-       .'<th>'.&mt('Role').'</th>'
-       .'<th>'.&mt('Section').'</th>'
-       .'<th>'.&mt('Context').'</th>'
+       .'<th>'.&mt('Role').'</th>';
+
+    if ($context eq 'course') {
+        $tableheader .= '<th>'.&mt('Section').'</th>';
+    }
+    $tableheader .=
+        '<th>'.&mt('Context').'</th>'
        .'<th>'.&mt('Start').'</th>'
        .'<th>'.&mt('End').'</th>'
        .&Apache::loncommon::end_data_table_header_row();
@@ -5603,7 +5646,7 @@
         if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
             $chgcontext = 'selfenroll';
         }
-        my %lt = &rolechg_contexts($crstype);
+        my %lt = &rolechg_contexts($context,$crstype);
         if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
             $chgcontext = $lt{$chgcontext};
         }
@@ -5613,9 +5656,12 @@
            .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
            .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
            .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
-           .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>'
-           .'<td>'.$sec.'</td>'
-           .'<td>'.$chgcontext.'</td>'
+           .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
+        if ($context eq 'course') { 
+            $r->print('<td>'.$sec.'</td>');
+        }
+        $r->print(
+            '<td>'.$chgcontext.'</td>'
            .'<td>'.$rolestart.'</td>'
            .'<td>'.$roleend.'</td>'
            .&Apache::loncommon::end_data_table_row()."\n");
@@ -5683,9 +5729,11 @@
 }
 
 sub role_display_filter {
-    my ($formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
-    my $context = 'course';
-    my $lctype = lc($crstype);
+    my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
+    my $lctype;
+    if ($context eq 'course') {
+        $lctype = lc($crstype);
+    }
     my $nolink = 1;
     my $output = '<table><tr><td valign="top">'.
                  '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
@@ -5700,7 +5748,7 @@
         &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
                                             $curr->{'rolelog_end_date'},undef,
                                             undef,undef,undef,undef,undef,undef,$nolink);
-    my %lt = &rolechg_contexts($crstype);
+    my %lt = &rolechg_contexts($context,$crstype);
     $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
                '<table><tr><td>'.&mt('After:').
                '</td><td>'.$startform.'</td></tr>'.
@@ -5714,7 +5762,7 @@
         $output .= ' selected="selected"';
     }
     $output .=  '>'.&mt('Any').'</option>'."\n";
-    my @roles = &Apache::lonuserutils::course_roles($context,undef,1,$lctype);
+    my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
     foreach my $role (@roles) {
         my $plrole;
         if ($role eq 'cr') {
@@ -5732,13 +5780,23 @@
                '<td>  </td>'.
                '<td valign="top"><b>'.
                &mt('Context:').'</b><br /><select name="chgcontext">';
-    foreach my $chgtype ('any','auto','updatenow','createcourse','course','domain','selfenroll','requestcourses') {
+    my @posscontexts;
+    if ($context eq 'course') {
+        @posscontexts = ('any','auto','updatenow','createcourse','course','domain','selfenroll','requestcourses');
+    } elsif ($context eq 'domain') {
+        @posscontexts = ('any','domain','requestauthor','domconfig','server');
+    } else {
+        @posscontexts = ('any','author','domain');
+    } 
+    foreach my $chgtype (@posscontexts) {
         my $selstr = '';
         if ($curr->{'chgcontext'} eq $chgtype) {
             $selstr = ' selected="selected"';
         }
-        if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
-            next if (!&Apache::lonnet::auto_run($cnum,$cdom));
+        if ($context eq 'course') {
+            if (($chgtype eq 'auto') || ($chgtype eq 'updatenow')) {
+                next if (!&Apache::lonnet::auto_run($cnum,$cdom));
+            }
         }
         $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
     }
@@ -5751,9 +5809,14 @@
               .'</p>';
 
     # Server version info
+    my $needsrev = '2.11.0';
+    if ($context eq 'course') {
+        $needsrev = '2.7.0';
+    }
+    
     $output .= '<p class="LC_info">'
               .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
-                  ,'2.6.99.0');
+                  ,$needsrev);
     if ($version) {
         $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
     }
@@ -5762,8 +5825,10 @@
 }
 
 sub rolechg_contexts {
-    my ($crstype) = @_;
-    my %lt = &Apache::lonlocal::texthash (
+    my ($context,$crstype) = @_;
+    my %lt;
+    if ($context eq 'course') {
+        %lt = &Apache::lonlocal::texthash (
                                              any          => 'Any',
                                              auto         => 'Automated enrollment',
                                              updatenow    => 'Roster Update',
@@ -5773,11 +5838,26 @@
                                              selfenroll   => 'Self-enrolled',
                                              requestcourses => 'Course Request',
                                          );
-    if ($crstype eq 'Community') {
-        $lt{'createcourse'} = &mt('Community Creation');
-        $lt{'course'} = &mt('User Management in community');
-        $lt{'requestcourses'} = &mt('Community Request');
-    }
+        if ($crstype eq 'Community') {
+            $lt{'createcourse'} = &mt('Community Creation');
+            $lt{'course'} = &mt('User Management in community');
+            $lt{'requestcourses'} = &mt('Community Request');
+        }
+    } elsif ($context eq 'domain') {
+        %lt = &Apache::lonlocal::texthash (
+                                             any           => 'Any',
+                                             domain        => 'User Management in domain',
+                                             requestauthor => 'Authoring Request',
+                                             server        => 'Command line script (DC role)',
+                                             domconfig     => 'Self-enrolled',
+                                         );
+    } else {
+        %lt = &Apache::lonlocal::texthash (
+                                             any    => 'Any',
+                                             domain => 'User Management in domain',
+                                             author => 'User Management by author',
+                                         );
+    } 
     return %lt;
 }
 
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1183 loncom/lonnet/perl/lonnet.pm:1.1184
--- loncom/lonnet/perl/lonnet.pm:1.1183	Tue Aug 14 15:45:34 2012
+++ loncom/lonnet/perl/lonnet.pm	Fri Aug 17 22:43:58 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1183 2012/08/14 15:45:34 raeburn Exp $
+# $Id: lonnet.pm,v 1.1184 2012/08/17 22:43:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -113,30 +113,33 @@
 our @EXPORT = qw(%env);
 
 
-# --------------------------------------------------------------------- Logging
+# ---------------------------------------------------------------- Role Logging
 {
     my $logid;
-    sub instructor_log {
-	my ($hash_name,$storehash,$delflag,$uname,$udom,$cnum,$cdom)=@_;
-        if (($cnum eq '') || ($cdom eq '')) {
-            $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-            $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+    sub write_rolelog {
+	my ($context,$hash_name,$storehash,$delflag,$udom,$uname,$cdom,$cnum)=@_;
+        if ($context eq 'course') {
+            if (($cnum eq '') || ($cdom eq '')) {
+                $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+                $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+            }
         }
-	$logid++;
+	$logid ++;
         my $now = time();
 	my $id=$now.'00000'.$$.'00000'.$logid;
-	return &Apache::lonnet::put('nohist_'.$hash_name,
-				    { $id => {
-					'exe_uname' => $env{'user.name'},
-					'exe_udom'  => $env{'user.domain'},
-					'exe_time'  => $now,
-					'exe_ip'    => $ENV{'REMOTE_ADDR'},
-					'delflag'   => $delflag,
-					'logentry'  => $storehash,
-					'uname'     => $uname,
-					'udom'      => $udom,
-				    }
-				  },$cdom,$cnum);
+        my $logentry = { 
+                          $id => {
+                                   'exe_uname' => $env{'user.name'},
+                                   'exe_udom'  => $env{'user.domain'},
+                                   'exe_time'  => $now,
+                                   'exe_ip'    => $ENV{'REMOTE_ADDR'},
+                                   'delflag'   => $delflag,
+                                   'logentry'  => $storehash,
+                                   'uname'     => $uname,
+                                   'udom'      => $udom,
+                                  }
+                       };
+	return &put('nohist_'.$hash_name,$logentry,$cdom,$cnum);
     }
 }
 
@@ -3534,38 +3537,70 @@
 
 sub courserolelog {
     my ($trole,$username,$domain,$area,$tstart,$tend,$delflag,$selfenroll,$context)=@_;
-    if (($trole eq 'cc') || ($trole eq 'in') ||
-        ($trole eq 'ep') || ($trole eq 'ad') ||
-        ($trole eq 'ta') || ($trole eq 'st') ||
-        ($trole=~/^cr/) || ($trole eq 'gr') ||
-        ($trole eq 'co')) {
-        if ($area =~ m-^/($match_domain)/($match_courseid)/?([^/]*)-) {
-            my $cdom = $1;
-            my $cnum = $2;
-            my $sec = $3;
-            my $namespace = 'rolelog';
-            my %storehash = (
-                               role    => $trole,
-                               start   => $tstart,
-                               end     => $tend,
-                               selfenroll => $selfenroll,
-                               context    => $context,
-                            );
-            if ($trole eq 'gr') {
-                $namespace = 'groupslog';
-                $storehash{'group'} = $sec;
-            } else {
-                $storehash{'section'} = $sec;
-            }
-            &instructor_log($namespace,\%storehash,$delflag,$username,$domain,$cnum,$cdom);
-            if (($trole ne 'st') || ($sec ne '')) {
-                &devalidate_cache_new('getcourseroles',$cdom.'_'.$cnum);
-            }
+    if ($area =~ m-^/($match_domain)/($match_courseid)/?([^/]*)-) {
+        my $cdom = $1;
+        my $cnum = $2;
+        my $sec = $3;
+        my $namespace = 'rolelog';
+        my %storehash = (
+                           role    => $trole,
+                           start   => $tstart,
+                           end     => $tend,
+                           selfenroll => $selfenroll,
+                           context    => $context,
+                        );
+        if ($trole eq 'gr') {
+            $namespace = 'groupslog';
+            $storehash{'group'} = $sec;
+        } else {
+            $storehash{'section'} = $sec;
+        }
+        &write_rolelog('course',$namespace,\%storehash,$delflag,$domain,
+                       $username,$cdom,$cnum);
+        if (($trole ne 'st') || ($sec ne '')) {
+            &devalidate_cache_new('getcourseroles',$cdom.'_'.$cnum);
         }
     }
     return;
 }
 
+sub domainrolelog {
+    my ($trole,$username,$domain,$area,$tstart,$tend,$delflag,$context)=@_;
+    if ($area =~ m{^/($match_domain)/$}) {
+        my $cdom = $1;
+        my $domconfiguser = &Apache::lonnet::get_domainconfiguser($cdom);
+        my $namespace = 'rolelog';
+        my %storehash = (
+                           role    => $trole,
+                           start   => $tstart,
+                           end     => $tend,
+                           context => $context,
+                        );
+        &write_rolelog('domain',$namespace,\%storehash,$delflag,$domain,
+                       $username,$cdom,$domconfiguser);
+    }
+    return;
+
+}
+
+sub coauthorrolelog {
+    my ($trole,$username,$domain,$area,$tstart,$tend,$delflag,$context)=@_;
+    if ($area =~ m{^/($match_domain)/($match_username)$}) {
+        my $audom = $1;
+        my $auname = $2;
+        my $namespace = 'rolelog';
+        my %storehash = (
+                           role    => $trole,
+                           start   => $tstart,
+                           end     => $tend,
+                           context => $context,
+                        );
+        &write_rolelog('author',$namespace,\%storehash,$delflag,$domain,
+                       $username,$audom,$auname);
+    }
+    return;
+}
+
 sub get_course_adv_roles {
     my ($cid,$codes) = @_;
     $cid=$env{'request.course.id'} unless (defined($cid));
@@ -7604,11 +7639,25 @@
     if ($answer eq 'ok') {
 	&userrolelog($role,$uname,$udom,$url,$start,$end);
 # for course roles, perform group memberships changes triggered by role change.
-        &courserolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag,$selfenroll,$context);
         unless ($role =~ /^gr/) {
             &Apache::longroup::group_changes($udom,$uname,$url,$role,$origend,
                                              $origstart,$selfenroll,$context);
         }
+        if (($role eq 'cc') || ($role eq 'in') ||
+            ($role eq 'ep') || ($role eq 'ad') ||
+            ($role eq 'ta') || ($role eq 'st') ||
+            ($role=~/^cr/) || ($role eq 'gr') ||
+            ($role eq 'co')) {
+            &courserolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag,
+                           $selfenroll,$context);
+        } elsif (($role eq 'li') || ($role eq 'dg') || ($role eq 'sc') ||
+                 ($role eq 'au') || ($role eq 'dc')) {
+            &domainrolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag,
+                           $context);
+        } elsif (($role eq 'ca') || ($role eq 'aa')) {
+            &coauthorrolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag,
+                             $context); 
+        }
         if ($role eq 'cc') {
             &autoupdate_coowners($url,$end,$start,$uname,$udom);
         }


More information about the LON-CAPA-cvs mailing list