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

raeburn raeburn@source.lon-capa.org
Fri, 23 Oct 2009 00:20:41 -0000


raeburn		Fri Oct 23 00:20:41 2009 EDT

  Modified files:              
    /loncom/auth	lonroles.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - bug 6102.
     - Set user.login.time hash item even when the user has no roles, 
       in case user requests a course, and acquires role(s) in current session.
     - Change role status from 'future' to 'is' if role start time was after 
       login but before last refresh. 
     - Compare CC role start time with refresh time instead of login time
       for role selector to work where course was created in the current session
       (via course request process).
  
  
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.231 loncom/auth/lonroles.pm:1.232
--- loncom/auth/lonroles.pm:1.231	Wed Aug  5 13:39:56 2009
+++ loncom/auth/lonroles.pm	Fri Oct 23 00:20:36 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.231 2009/08/05 13:39:56 bisitz Exp $
+# $Id: lonroles.pm,v 1.232 2009/10/23 00:20:36 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -238,7 +238,7 @@
             # Check if user is CC trying to select a course role
             if ($env{'form.switchrole'}) {
                 if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
-                    &adhoc_course_role($then);
+                    &adhoc_course_role($refresh,$then);
                 }
             }
 	    my %temp=('logout_'.$env{'request.course.id'} => time);
@@ -1384,21 +1384,21 @@
 }
 
 sub adhoc_course_role {
-    my ($then) = @_; 
+    my ($refresh,$then) = @_;
     my ($cdom,$cnum);
     $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-    if (&check_forcc($cdom,$cnum,$then)) {
+    if (&check_forcc($cdom,$cnum,$refresh,$then)) {
         my $setprivs;
         if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
             $setprivs = 1;
         } else {
             my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
-            if (($start && ($start>$then || $start == -1)) ||
+            if (($start && ($start>$refresh || $start == -1)) ||
                 ($end && $end<$then)) {
                 $setprivs = 1;
             }
-        } 
+        }
         if ($setprivs) {
             if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
                 my $role = $1;
@@ -1428,7 +1428,7 @@
                 }
                 &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
                 &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
-                my $adhocstart = $then-1;
+                my $adhocstart = $refresh-1;
                 $userroles{'user.role.'.$spec} = $adhocstart.'.';
                 &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
             }
@@ -1438,7 +1438,7 @@
 }
 
 sub check_forcc {
-    my ($cdom,$cnum,$then) = @_;
+    my ($cdom,$cnum,$refresh,$then) = @_;
     my $is_cc;
     if ($cdom ne '' && $cnum ne '') {
         if (&Apache::lonnet::is_course($cdom,$cnum)) {
@@ -1446,7 +1446,7 @@
             if (defined($env{$envkey})) {
                 $is_cc = 1;
                 my ($tstart,$tend)=split(/\./,$env{$envkey});
-                if ($tstart && $tstart>$then) { $is_cc = 0; }
+                if ($tstart && $tstart>$refresh) { $is_cc = 0; }
                 if ($tend   && $tend  <$then) { $is_cc = 0; }
             }
         }
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1033 loncom/lonnet/perl/lonnet.pm:1.1034
--- loncom/lonnet/perl/lonnet.pm:1.1033	Thu Oct 22 22:01:47 2009
+++ loncom/lonnet/perl/lonnet.pm	Fri Oct 23 00:20:40 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1033 2009/10/22 22:01:47 raeburn Exp $
+# $Id: lonnet.pm,v 1.1034 2009/10/23 00:20:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3833,7 +3833,8 @@
 
 sub rolesinit {
     my ($domain,$username,$authhost)=@_;
-    my %userroles;
+    my $now=time;
+    my %userroles = ('user.login.time' => $now);
     my $rolesdump=reply("dump:$domain:$username:roles",$authhost);
     if (($rolesdump eq 'con_lost') || ($rolesdump eq '') || 
         ($rolesdump =~ /^error:/)) { 
@@ -3841,8 +3842,6 @@
     }
     my %allroles=();
     my %allgroups=();   
-    my $now=time;
-    %userroles = ('user.login.time' => $now);
     my $group_privs;
 
     if ($rolesdump ne '') {
@@ -4016,8 +4015,8 @@
             $$tstatus='is';
             if ($$tstart && $$tstart>$then) {
                 $$tstatus='future';
-                if ($$tstart && $$tstart>$refresh) {
-                    if ($$tstart<$now) {
+                if ($$tstart<$now) {
+                    if ($$tstart && $$tstart>$refresh) {
                         if (($$where ne '') && ($$role ne '')) {
                             my (%allroles,%allgroups,$group_privs);
                             my %userroles = (
@@ -4047,9 +4046,9 @@
                             my ($author,$adv)= &set_userprivs(\%userroles,\%allroles,\%allgroups);
                             &appenv(\%userroles,[$$role,'cm']);
                             &log($env{'user.domain'},$env{'user.name'},$env{'user.home'},"Role ".$role);
-                            $$tstatus = 'is';
                         }
                     }
+                    $$tstatus = 'is';
                 }
             }
             if ($$tend) {