[LON-CAPA-cvs] cvs: rat / lonpage.pm loncom/auth switchserver.pm loncom/interface loncommon.pm londocs.pm lonhtmlcommon.pm lonmenu.pm loncom/lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Tue Sep 13 08:22:15 EDT 2022


raeburn		Tue Sep 13 12:22:15 2022 EDT

  Modified files:              
    /loncom/interface	loncommon.pm londocs.pm lonhtmlcommon.pm 
                     	lonmenu.pm 
    /loncom/auth	switchserver.pm 
    /loncom/lonnet/perl	lonnet.pm 
    /rat	lonpage.pm 
  Log:
  - In course context, switch server to resource's home server opens new tab
    when editing published resource, and ca role is loaded,  when user's domain
    (by default) disallows session hosting of domain's users in resource's domain. 
  - New arg (skip_enc_check) in redirect args , used by loncommon::headtag()
    it true, omit application of check_encrypt().
  - New seventh item ($shownsymb) in args for lonhtmlcommon::jump_to_editres()
  
  
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1387 loncom/interface/loncommon.pm:1.1388
--- loncom/interface/loncommon.pm:1.1387	Thu Sep  8 01:41:13 2022
+++ loncom/interface/loncommon.pm	Tue Sep 13 12:22:14 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1387 2022/09/08 01:41:13 raeburn Exp $
+# $Id: loncommon.pm,v 1.1388 2022/09/13 12:22:14 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -8881,6 +8881,7 @@
                                       window (side effect of setting
                                       $env{'internal.head.to_opener'} to
                                       1, if true.
+                                   5- whether encrypt check should be skipped
             domain         -> force to color decorate a page for a specific
                                domain
             function       -> force usage of a specific rolish color scheme
@@ -8943,8 +8944,10 @@
         }
     }
     if (ref($args->{'redirect'})) {
-	my ($time,$url,$inhibit_continue,$to_opener) = @{$args->{'redirect'}};
-	$url = &Apache::lonenc::check_encrypt($url);
+	my ($time,$url,$inhibit_continue,$to_opener,$skip_enc_check) = @{$args->{'redirect'}};
+        if (!$skip_enc_check) {
+            $url = &Apache::lonenc::check_encrypt($url);
+        }
 	if (!$inhibit_continue) {
 	    $env{'internal.head.redirect'} = $url;
 	}
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.678 loncom/interface/londocs.pm:1.679
--- loncom/interface/londocs.pm:1.678	Thu Apr 29 17:45:22 2021
+++ loncom/interface/londocs.pm	Tue Sep 13 12:22:14 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.678 2021/04/29 17:45:22 raeburn Exp $
+# $Id: londocs.pm,v 1.679 2022/09/13 12:22:14 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3968,7 +3968,7 @@
     my $line=&Apache::loncommon::start_data_table_row();
     my ($form_start,$form_end,$form_common,$form_param);
 # Edit commands
-    my ($esc_path, $path, $symb, $curralias);
+    my ($esc_path, $path, $symb, $shownsymb, $curralias);
     if ($env{'form.folderpath'}) {
 	$esc_path=&escape($env{'form.folderpath'});
 	$path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
@@ -4242,7 +4242,7 @@
                 }
             }
             if (&Apache::lonnet::symbverify($symb,$url)) {
-                my $shownsymb = $symb;
+                $shownsymb = $symb;
                 if ($isexternal) {
                     $url =~ s/\#[^#]+$//;
                     if ($container eq 'page') {
@@ -4277,7 +4277,7 @@
                     }
                 }
                 if ($checkencrypt) {
-                    my $shownsymb = &Apache::lonenc::encrypted($symb);
+                    $shownsymb = &Apache::lonenc::encrypted($symb);
                     my $shownurl = &Apache::lonenc::encrypted($url);
                     if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
                         $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
@@ -4451,7 +4451,7 @@
                     &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
                                                             $switchserver,
                                                             $forceedit,
-                                                            undef,$symb,
+                                                            undef,$symb,$shownsymb,
                                                             &escape($env{'form.folderpath'}),
                                                             $renametitle,$hostname,
                                                             '','',1,$suppanchor);
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.405 loncom/interface/lonhtmlcommon.pm:1.406
--- loncom/interface/lonhtmlcommon.pm:1.405	Thu Jun 30 21:04:14 2022
+++ loncom/interface/lonhtmlcommon.pm	Tue Sep 13 12:22:14 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.405 2022/06/30 21:04:14 raeburn Exp $
+# $Id: lonhtmlcommon.pm,v 1.406 2022/09/13 12:22:14 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3535,7 +3535,10 @@
 sub javascript_jumpto_resource {
     my $confirm_switch = &mt("Editing requires switching to the resource's home server.")."\n".
                          &mt('Switch server?');
+    my $confirm_new_tab = &mt("Editing requires using the resource's home server.")."\n".
+                          &mt('Open a new browser tab?');
     &js_escape(\$confirm_switch);
+    &js_escape(\$confirm_new_tab);
     return (<<ENDUTILITY)
 
 function go(url) {
@@ -3556,9 +3559,13 @@
    }
 }
 
-function need_switchserver(url) {
+function need_switchserver(url,target) {
     if (url!='' && url!= null) {
-        if (confirm("$confirm_switch")) {
+        if (target == '_blank') {
+            if (confirm("$confirm_new_tab")) {
+                window.open(url,target);
+            }
+        } else if (confirm("$confirm_switch")) {
             go(url);
         }
     }
@@ -3570,15 +3577,35 @@
 }
 
 sub jump_to_editres {
-    my ($cfile,$home,$switchserver,$forceedit,$forcereg,$symb,$folderpath,
-        $title,$hostname,$idx,$suppurl,$todocs,$suppanchor) = @_;
-    my ($jscall,$anchor,$usehttp,$usehttps,$is_ext);
+    my ($cfile,$home,$switchserver,$forceedit,$forcereg,$symb,$shownsymb,
+        $folderpath,$title,$hostname,$idx,$suppurl,$todocs,$suppanchor) = @_;
+    my ($jscall,$anchor,$usehttp,$usehttps,$is_ext,$target);
     if ($switchserver) {
         if ($home) {
+            my $resedit;
+            if ($cfile =~ m{^/priv/($match_domain)/($match_username)/}) {
+                my ($audom,$auname) = ($1,$2);
+                unless (&Apache::lonnet::is_course($audom,$auname)) {
+                    unless ((&Apache::lonnet::will_trust('othcoau',$env{'user.domain'},$audom)) &&
+                            (&Apache::lonnet::will_trust('coaurem',$audom,$env{'user.domain'}))) {
+                       return;
+                    }
+                    if (($symb ne '') && ($env{'request.course.id'}) &&
+                        (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
+                        unless (&Apache::lonnet::can_switchserver($env{'user.domain'},$home)) {
+                            $target = '_blank';
+                            $resedit = 1;
+                        }
+                    }
+                }
+            }
             $cfile = '/adm/switchserver?otherserver='.$home.'&role='.
                      &HTML::Entities::encode($env{'request.role'},'"<>&');
-            if ($symb) {
-                $cfile .= '&symb='.&HTML::Entities::encode($symb,'"<>&');
+            if ($shownsymb) {
+                $cfile .= '&symb='.&HTML::Entities::encode($shownsymb,'"<>&');
+                if ($resedit) {
+                    $cfile .= '&edit=1';
+                }
             } elsif ($folderpath) {
                 $cfile .= '&folderpath='.&HTML::Entities::encode($folderpath,'"<>&');
             }
@@ -3588,7 +3615,7 @@
             if ($forcereg) {
                 $cfile .= '&register=1';
             }
-            $jscall = "need_switchserver('".&Apache::loncommon::escape_single($cfile)."');";
+            $jscall = "need_switchserver('".&Apache::loncommon::escape_single($cfile)."','$target')";
         }
     } else {
         unless ($cfile =~ m{^/priv/}) {
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.526 loncom/interface/lonmenu.pm:1.527
--- loncom/interface/lonmenu.pm:1.526	Thu Jul  7 15:28:08 2022
+++ loncom/interface/lonmenu.pm	Tue Sep 13 12:22:14 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.526 2022/07/07 15:28:08 raeburn Exp $
+# $Id: lonmenu.pm,v 1.527 2022/09/13 12:22:14 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1371,8 +1371,12 @@
         if ($env{'form.folderpath'}) {
             $suppanchor = $env{'form.anchor'};
         }
+        my $shownsymb;
+        if ($env{'request.symb'}) {
+            $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
+        }
         $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
-                                                $forceedit,$forcereg,$env{'request.symb'},
+                                                $forceedit,$forcereg,$env{'request.symb'},$shownsymb,
                                                 &escape($env{'form.folderpath'}),
                                                 &escape($env{'form.title'}),$hostname,
                                                 $env{'form.idx'},&escape($env{'form.suppurl'}),
Index: loncom/auth/switchserver.pm
diff -u loncom/auth/switchserver.pm:1.62 loncom/auth/switchserver.pm:1.63
--- loncom/auth/switchserver.pm:1.62	Wed Aug 24 20:58:50 2022
+++ loncom/auth/switchserver.pm	Tue Sep 13 12:22:14 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Switch Servers Handler
 #
-# $Id: switchserver.pm,v 1.62 2022/08/24 20:58:50 raeburn Exp $
+# $Id: switchserver.pm,v 1.63 2022/09/13 12:22:14 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -62,7 +62,7 @@
     }
     my $start_page = 
 	&Apache::loncommon::start_page('Switching Server ...',undef,
-				       {'redirect'       => [$delay,$url,'',$write_to_opener],
+				       {'redirect'       => [$delay,$url,'',$write_to_opener,1],
 					'only_body'      => $only_body,});
     my $end_page   = &Apache::loncommon::end_page();
     $r->print($start_page.$extra_text.$end_page);
@@ -102,7 +102,7 @@
     if (!defined($handle)) { return FORBIDDEN; }
 
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-				['otherserver','role','origurl','symb','lcssowin']);
+				['otherserver','role','origurl','symb','lcssowin','edit']);
 
     my $switch_to=&Apache::lonnet::hostname($env{'form.otherserver'});
     if (! $env{'form.otherserver'}) {
@@ -167,26 +167,69 @@
     }
 
     unless ($skip_canhost_check) {
-        my $canhost = 1;
-        my $uprimary_id = &Apache::lonnet::domain($env{'user.domain'},'primary');
-        my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
-        my @intdoms;
-        my $internet_names = &Apache::lonnet::get_internet_names($env{'form.otherserver'});
-        if (ref($internet_names) eq 'ARRAY') {
-            @intdoms = @{$internet_names};
-        }
-        unless ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/, at intdoms)) {
-            my $serverhomeID = &Apache::lonnet::get_server_homeID($switch_to);
-            my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
-            my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
-            my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
-            my $remoterev = &Apache::lonnet::get_server_loncaparev($env{'user.domain'},$env{'form.otherserver'});
-            $canhost = 
-                &Apache::lonnet::can_host_session($env{'user.domain'},
-                                                  $env{'form.otherserver'},
-                                                  $remoterev,
-                                                  $udomdefaults{'remotesessions'},
-                                                  $defdomdefaults{'hostedsessions'});
+        my $canhost = &Apache::lonnet::can_switchserver($env{'user.domain'},$env{'form.otherserver'});
+        unless ($canhost) {
+            if (($env{'request.course.id'}) && ($env{'form.symb'} ne '') &&
+                (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
+                my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+                my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+                if (($cdom ne '') && ($cnum ne '') && ($env{'form.role'} =~ m{^([^.]+)\Q./$cdom/$cnum\E$})) {
+                    my $symb = &Apache::lonnet::symbclean($env{'form.symb'});
+                    my ($map,$idx,$url) = &Apache::lonnet::decode_symb($symb);
+                    if (&Apache::lonnet::symbverify($symb,$url)) {
+                        my $fileloc = &Apache::lonnet::declutter(&Apache::lonnet::filelocation("",$url));
+                        my $resurl = &Apache::lonnet::clutter($url);
+                        if ($resurl =~ m{^/res/($match_domain)/($match_username)/}) {
+                            my ($audom,$auname) = ($1,$2);
+                            if (&Apache::lonnet::homeserver($auname,$audom) eq $env{'form.otherserver'}) {
+                                my @possroles = ("user.role.au./$audom/","user.role.ca./$audom/$auname","user.role.aa./$audom/$auname");
+                                my $hasrole;
+                                foreach my $rolekey (@possroles) {
+                                    if (exists($env{$rolekey})) {
+                                        my ($start,$end) = split(/\./,$env{$rolekey});
+                                        unless (($start && $start > $now) || ($end && $end < $now)) {
+                                            if ($rolekey eq "user.role.au./$audom/") {
+                                                $hasrole = $rolekey;
+                                            } elsif ((&Apache::lonnet::will_trust('othcoau',$env{'user.domain'},$audom)) &&
+                                                     (&Apache::lonnet::will_trust('coaurem',$audom,$env{'user.domain'}))) {
+                                                $hasrole = $rolekey;
+                                            }
+                                        }
+                                        if ($hasrole) {
+                                            $hasrole =~ s/^\Quser.role.\E//;
+                                            last;
+                                        }
+                                    }
+                                }
+                                if ($hasrole) {
+                                    $env{'form.role'} = $hasrole;
+                                    $env{'form.origurl'} = &Apache::lonnet::deversion($resurl);
+                                    $env{'form.origurl'} =~ s{^/res/}{/priv/};
+                                    delete($env{'form.symb'});
+                                    $canhost = 1;
+                                    if ($env{'form.edit'}) {
+                                        my $ip = &Apache::lonnet::get_requestor_ip($r,REMOTE_NOLOOKUP);
+                                        my %info=('ip'            => $ip,
+                                                  'domain'        => $env{'user.domain'},
+                                                  'username'      => $env{'user.name'},
+                                                  'home'          => $env{'user.home'},
+                                                  'role'          => $env{'form.role'},
+                                                  'server'        => $r->dir_config('lonHostID'),
+                                                  'origurl'       => $env{'form.origurl'});
+                                        &Apache::loncommon::content_type($r,'text/html');
+                                        my $token = &Apache::lonnet::tmpput(\%info,$env{'form.otherserver'});
+                                        my $url = $protocol.'://'.$switch_to.'/adm/login?'.
+                                                                 'domain='.$env{'user.domain'}.
+                                                                 '&username='.$env{'user.name'}.
+                                                                 '&token='.$token;
+                                        return &do_redirect($r,$url,0);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
         }
         unless ($canhost) { return FORBIDDEN; }
     }
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1490 loncom/lonnet/perl/lonnet.pm:1.1491
--- loncom/lonnet/perl/lonnet.pm:1.1490	Tue Sep 13 02:32:58 2022
+++ loncom/lonnet/perl/lonnet.pm	Tue Sep 13 12:22:15 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1490 2022/09/13 02:32:58 raeburn Exp $
+# $Id: lonnet.pm,v 1.1491 2022/09/13 12:22:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1378,6 +1378,29 @@
     return 'no_host';
 }
 
+sub can_switchserver {
+    my ($udom,$home) = @_;
+    my ($canswitch, at intdoms);
+    my $internet_names = &get_internet_names($home);
+    if (ref($internet_names) eq 'ARRAY') {
+        @intdoms = @{$internet_names};
+    }
+    my $uint_dom = &internet_dom(&domain($udom,'primary'));
+    if ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/, at intdoms)) {
+        $canswitch = 1;
+    } else {
+         my $serverhomeID = &get_server_homeID(&hostname($home));
+         my $serverhomedom = &host_domain($serverhomeID);
+         my %defdomdefaults = &get_domain_defaults($serverhomedom);
+         my %udomdefaults = &get_domain_defaults($udom);
+         my $remoterev = &get_server_loncaparev('',$home);
+         $canswitch = &can_host_session($udom,$home,$remoterev,
+                                        $udomdefaults{'remotesessions'},
+                                        $defdomdefaults{'hostedsessions'});
+    }
+    return $canswitch;
+}
+
 sub can_host_session {
     my ($udom,$lonhost,$remoterev,$remotesessions,$hostedsessions) = @_;
     my $canhost = 1;
Index: rat/lonpage.pm
diff -u rat/lonpage.pm:1.140 rat/lonpage.pm:1.141
--- rat/lonpage.pm:1.140	Wed Jun 29 17:51:10 2022
+++ rat/lonpage.pm	Tue Sep 13 12:22:15 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Page Handler
 #
-# $Id: lonpage.pm,v 1.140 2022/06/29 17:51:10 raeburn Exp $
+# $Id: lonpage.pm,v 1.141 2022/09/13 12:22:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -993,16 +993,18 @@
     my $symb=&Apache::lonnet::encode_symb($hash->{'map_id_'.$mapid},
 					  $resid,
 					  $hash->{'src_'.$rid});
-    my $aname;
+    my ($aname,$shownsymb);
     if (($hash->{'encrypted_'.$rid}) && (!$env{'request.role.adv'})) {
         $aname = 'LC_'.$rid;
+        $shownsymb = &Apache::lonenc::encrypted($symb);
     } else {
-        my $shownsymb = $symb;
+        $shownsymb = $symb;
+        my $dispsymb = $symb;
         if ($symb =~ /\#([^\#]+)$/) {
             my $escan = &escape('#');
-            $shownsymb =~ s/#([^\#]+)$/$escan$1/;
+            $dispsymb =~ s/#([^\#]+)$/$escan$1/;
         }
-        $aname = &escape($shownsymb);
+        $aname = &escape($dispsymb);
     }
     my $metainfo = '<a name="'.$aname.'"></a>';
     unless ($env{'request.role.adv'}) {
@@ -1085,8 +1087,8 @@
                 &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,$hash->{'src_'.$rid},$symb);
             if ($cfile ne '') {
                 my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
-                                                                     $forceedit,1,$symb,undef,
-                                                                     &escape($env{'form.title'}),
+                                                                     $forceedit,1,$symb,$shownsymb,
+                                                                     undef,&escape($env{'form.title'}),
                                                                      $hostname);
                 if ($jscall) {
                     $editbutton = 1;


More information about the LON-CAPA-cvs mailing list