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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Wed, 30 Apr 2008 23:16:22 -0000


This is a MIME encoded message

--raeburn1209597382
Content-Type: text/plain

raeburn		Wed Apr 30 19:16:22 2008 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm 
  Log:
  Bug 5176. Record of role changes in a course.
  - Pass $context to more subroutines so it can be stored in record in nohist_rolelog.
  
  
--raeburn1209597382
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080430191622.txt"

Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.51 loncom/interface/lonuserutils.pm:1.52
--- loncom/interface/lonuserutils.pm:1.51	Thu Mar  6 16:57:33 2008
+++ loncom/interface/lonuserutils.pm	Wed Apr 30 19:16:19 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.51 2008/03/06 21:57:33 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.52 2008/04/30 23:16:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -42,7 +42,7 @@
 ###############################################################
 # Drop student from all sections of a course, except optional $csec
 sub modifystudent {
-    my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
+    my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
     # if $csec is undefined, drop the student from all the courses matching
     # this one.  If $csec is defined, drop them from all other sections of
     # this course and add them to section $csec
@@ -69,7 +69,7 @@
                         # dom  name  id mode pass     f     m     l     g
                         ($udom,$unam,'',  '',  '',undef,undef,undef,undef,
                          $section,time,undef,undef,$desiredhost,'','manual',
-                         '',$courseid);
+                         '',$courseid,'',$context);
                     $result .= $reply.':';
                 }
             }
@@ -129,7 +129,8 @@
         if ($role ne '') {
             $role =~ s/_/\//g;
             $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
-                                                      $role,$end,$start);
+                                                      $role,$end,$start,'',
+                                                      '',$context);
         }
     }
     return ($userresult,$authresult,$roleresult,$idresult);
@@ -1513,6 +1514,10 @@
 
 sub gather_userinfo {
     my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
+    my $viewablesec;
+    if ($context eq 'course') {
+        $viewablesec = &viewable_section($permission);
+    }
     foreach my $item (keys(%{$rolehash})) {
         my %userdata;
         if ($context eq 'author') { 
@@ -1522,7 +1527,6 @@
             &build_user_record($context,\%userdata,$userinfo,$indexhash,
                                $item,$userlist);
         } elsif ($context eq 'course') {
-            my $viewablesec = &viewable_section($permission);
             ($userdata{'username'},$userdata{'domain'},$userdata{'role'},
              $userdata{'section'}) = split(/:/,$item,-1);
             ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
@@ -3657,13 +3661,14 @@
                                 $sec = $secs[0];
                             }
                             &modifystudent($domain,$username,$cid,$sec,
-                                           $desiredhost);
+                                           $desiredhost,$context);
                             $roleresult =
                                 &Apache::lonnet::modifystudent
                                     ($domain,$username,$id,$amode,$password,
                                      $fname,$mname,$lname,$gen,$sec,$enddate,
                                      $startdate,$env{'form.forceid'},
-                                     $desiredhost,$email,'manual','',$cid);
+                                     $desiredhost,$email,'manual','',$cid,
+                                     '',$context);
                             $userresult = $roleresult;
                         } else {
                             if ($role ne '') { 
@@ -3969,24 +3974,25 @@
             $end = $now;
             $type = 'manual';
             $result =
-                &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
+                &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
         } elsif ($choice eq 'revoke') {
             # revoke or delete user role
             $end = $now; 
             if ($role eq 'st') {
                 $result = 
-                    &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
+                    &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
             } else {
                 $result = 
-                    &Apache::lonnet::revokerole($udom,$uname,$scope,$role);
+                    &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
+                                                '','',$context);
             }
         } elsif ($choice eq 'delete') {
             if ($role eq 'st') {
-                &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid);
+                &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context);
             }
             $result =
                 &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
-                                            $start,1);
+                                            $start,1,'',$context);
         } else {
             #reenable, activate, change access dates or change section
             if ($choice ne 'chgsec') {
@@ -3995,25 +4001,25 @@
             }
             if ($choice eq 'reenable') {
                 if ($role eq 'st') {
-                    $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
+                    $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
                 } else {
                     $result = 
                         &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
-                                                    $now);
+                                                    $now,'','',$context);
                 }
             } elsif ($choice eq 'activate') {
                 if ($role eq 'st') {
-                    $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
+                    $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
                 } else {
                     $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
-                                            $now);
+                                            $now,'','',$context);
                 }
             } elsif ($choice eq 'chgdates') {
                 if ($role eq 'st') {
-                    $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
+                    $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
                 } else {
                     $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
-                                                $start);
+                                                $start,'','',$context);
                 }
             } elsif ($choice eq 'chgsec') {
                 my (@newsecs,$revresult,$nochg,@retained);
@@ -4029,7 +4035,8 @@
                         } else {
                             $revresult =
                                 &Apache::lonnet::revokerole($udom,$uname,
-                                                            $scope,$role);
+                                                            $scope,$role,
+                                                            '','',$context);
                         } 
                     } else {
                         if (@newsecs > 0) {
@@ -4038,12 +4045,14 @@
                             } else {
                                 $revresult =
                                     &Apache::lonnet::revokerole($udom,$uname,
-                                                                $scope,$role);
+                                                                $scope,$role,
+                                                                '','',$context);
                             }
                         } else {
                             $revresult =
                                 &Apache::lonnet::revokerole($udom,$uname,
-                                                            $scope,$role);
+                                                            $scope,$role,
+                                                            '','',$context);
                         }
                     }
                 } else {
@@ -4058,17 +4067,17 @@
                     if (!$nochg) {
                         if ($role eq 'st') {
                             $result = 
-                                &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid);
+                                &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
                         } else {
                             my $newscope = $scopestem;
-                            $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start);
+                            $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
                         }
                     }
                 } else {
                     foreach my $newsec (@newsecs) { 
                         if (!grep(/^\Q$newsec\E$/,@retained)) {
                             if ($role eq 'st') {
-                                $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid);
+                                $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
                             } else {
                                 my $newscope = $scopestem;
                                 if ($newsec ne '') {

--raeburn1209597382--