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

raeburn raeburn at source.lon-capa.org
Tue Sep 4 16:48:05 EDT 2012


raeburn		Tue Sep  4 20:48:05 2012 EDT

  Modified files:              
    /loncom/auth	lonroles.pm 
    /loncom/interface	lonmenu.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Bug 6419.
    - "Switch role to ..." in a course can handle switching back and forth
      between roles with/without request.role.adv = 1, where course item has
      URL hidden (from Course Editor). 
  
  
-------------- next part --------------
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.275 loncom/auth/lonroles.pm:1.276
--- loncom/auth/lonroles.pm:1.275	Sun Aug 19 03:11:43 2012
+++ loncom/auth/lonroles.pm	Tue Sep  4 20:47:46 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.275 2012/08/19 03:11:43 raeburn Exp $
+# $Id: lonroles.pm,v 1.276 2012/09/04 20:47:46 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -141,7 +141,7 @@
 use GDBM_File;
 use LONCAPA qw(:DEFAULT :match);
 use HTML::Entities;
- 
+
 
 sub redirect_user {
     my ($r,$title,$url,$msg) = @_;
@@ -579,11 +579,52 @@
 				    $furl = "/adm/helper/course.initialization.helper";
 				    # Send the user to the course they selected
 				} elsif ($env{'request.course.id'}) {
-                                    if ($env{'form.destinationurl'}) {
-                                        my $dest = $env{'form.destinationurl'};
-                                        if ($env{'form.destsymb'} ne '') {
-                                            my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
-                                            $dest .= '?symb='.$esc_symb;
+                                    my ($dest,$destsymb,$checkenc);
+                                    $dest = $env{'form.destinationurl'};
+                                    $destsymb = $env{'form.destsymb'};
+                                    if ($dest ne '') {
+                                        if ($env{'form.switchrole'}) {
+                                            if ($destsymb ne '') {
+                                                if ($destsymb !~ m{^/enc/}) {
+                                                    unless ($env{'request.role.adv'}) {
+                                                        $checkenc = 1;
+                                                    }
+                                                }
+                                            }
+                                            if ($dest =~ m{^/enc/}) {
+                                                if ($env{'request.role.adv'}) {
+                                                    $dest = &Apache::lonenc::unencrypted($dest);
+                                                    if ($destsymb eq '') {
+                                                        ($destsymb) = ($dest =~ /\?symb=([^\&]*)/);
+                                                        $destsymb = &unescape($destsymb);
+                                                    }
+                                                }
+                                            } else {
+                                                if ($destsymb eq '') {
+                                                    ($destsymb) = ($dest =~ /\?symb=([^\&]+)/);
+                                                    $destsymb = &unescape($destsymb);
+                                                }
+                                                unless ($env{'request.role.adv'}) {
+                                                    $checkenc = 1;
+                                                }
+                                            }
+                                            if (($checkenc) && ($destsymb ne '')) {
+                                                my ($encstate,$unencsymb,$res);
+                                                my $unencsymb = &Apache::lonnet::symbclean($destsymb);
+                                                (undef,undef,$res) = &Apache::lonnet::decode_symb($unencsymb);
+                                                &Apache::lonnet::symbverify($unencsymb,$res,\$encstate);
+                                                if ($encstate) {
+                                                    if (($dest ne '') && ($dest !~ m{^/enc/})) {
+                                                        $dest=&Apache::lonenc::encrypted($dest);
+                                                    }
+                                                }
+                                            }
+                                        }
+                                        unless (($dest =~ m{^/enc/}) || ($dest =~ /\?symb=.+___\d+___.+/)) {
+                                            if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) {
+                                                my $esc_symb = &escape($destsymb);
+                                                $dest .= '?symb='.$esc_symb;
+                                            }
                                         }
                                         &redirect_user($r, &mt('Entering [_1]',
                                                        $env{'course.'.$courseid.'.description'}),
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.385 loncom/interface/lonmenu.pm:1.386
--- loncom/interface/lonmenu.pm:1.385	Thu Aug 16 18:35:47 2012
+++ loncom/interface/lonmenu.pm	Tue Sep  4 20:47:56 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.385 2012/08/16 18:35:47 raeburn Exp $
+# $Id: lonmenu.pm,v 1.386 2012/09/04 20:47:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1479,8 +1479,22 @@
     } else {
         $ccrole = 'cc';
     }
-    my $priv;
+    my ($priv,$gotsymb,$destsymb);
     my $destinationurl = $ENV{'REQUEST_URI'};
+    if ($destinationurl =~ /\?symb=/) {
+        $gotsymb = 1;
+    } elsif ($destinationurl =~ m{^/enc/}) {
+        my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
+        if ($plainurl =~ /\?symb=/) {
+            $gotsymb = 1;
+        }
+    }
+    unless ($gotsymb) {
+        $destsymb = &Apache::lonnet::symbread();
+        if ($destsymb ne '') {
+            $destsymb = &Apache::lonenc::check_encrypt($destsymb);
+        }
+    }
     my $reqprivs = &required_privs();
     if (ref($reqprivs) eq 'HASH') {
         my $destination = $destinationurl;
@@ -1568,7 +1582,12 @@
                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
             }
         }
-        $role_selector .= '</select>'."\n".
+        $role_selector .= '</select>'."\n";
+        if ($destsymb ne '') {
+            $role_selector .= '<input type="hidden" name="destsymb" value="'.
+                              &HTML::Entities::encode($destsymb).'" />'."\n";
+        }
+        $role_selector .=
                '<input type="hidden" name="destinationurl" value="'.
                &HTML::Entities::encode($destinationurl).'" />'."\n".
                '<input type="hidden" name="gotorole" value="1" />'."\n".
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1189 loncom/lonnet/perl/lonnet.pm:1.1190
--- loncom/lonnet/perl/lonnet.pm:1.1189	Sun Sep  2 16:18:24 2012
+++ loncom/lonnet/perl/lonnet.pm	Tue Sep  4 20:48:05 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1189 2012/09/02 16:18:24 raeburn Exp $
+# $Id: lonnet.pm,v 1.1190 2012/09/04 20:48:05 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -10018,7 +10018,7 @@
 # --------------------------------------------------------------- Verify a symb
 
 sub symbverify {
-    my ($symb,$thisurl)=@_;
+    my ($symb,$thisurl,$encstate)=@_;
     my $thisfn=$thisurl;
     $thisfn=&declutter($thisfn);
 # direct jump to resource in page or to a sequence - will construct own symbs
@@ -10054,11 +10054,14 @@
                }
                if (
   &symbclean(&declutter($bighash{'map_id_'.$mapid}).'___'.$resid.'___'.$thisfn)
-   eq $symb) { 
+   eq $symb) {
+                   if (ref($encstate)) {
+                       $$encstate = $bighash{'encrypted_'.$id};
+                   }
 		   if (($env{'request.role.adv'}) ||
 		       ($bighash{'encrypted_'.$id} eq $env{'request.enc'}) ||
                        ($thisurl eq '/adm/navmaps')) {
-		       $okay=1; 
+		       $okay=1;
 		   }
 	       }
 	   }
@@ -12255,12 +12258,14 @@
 
 =item *
 
-symbverify($symb,$thisfn) : verifies that $symb actually exists and is
-a possible symb for the URL in $thisfn, and if is an encryypted
+symbverify($symb,$thisfn,$encstate) : verifies that $symb actually exists
+and is a possible symb for the URL in $thisfn, and if is an encrypted
 resource that the user accessed using /enc/ returns a 1 on success, 0
-on failure, user must be in a course, as it assumes the existance of
-the course initial hash, and uses $env('request.course.id'}
-
+on failure, user must be in a course, as it assumes the existence of
+the course initial hash, and uses $env('request.course.id'}.  The third
+arg is an optional reference to a scalar.  If this arg is passed in the 
+call to symbverify, it will be set to 1 if the symb has been set to be 
+encrypted; otherwise it will be null.  
 
 =item *
 


More information about the LON-CAPA-cvs mailing list