--- loncom/interface/lontiny.pm 2021/08/10 15:28:14 1.7 +++ loncom/interface/lontiny.pm 2021/11/03 01:04:03 1.8 @@ -2,7 +2,7 @@ # Extract domain, courseID, and symb from a shortened URL, # and switch role to a role in designated course. # -# $Id: lontiny.pm,v 1.7 2021/08/10 15:28:14 raeburn Exp $ +# $Id: lontiny.pm,v 1.8 2021/11/03 01:04:03 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -67,9 +67,10 @@ sub handler { if ($cnum =~ /^$match_courseid$/) { my $chome = &Apache::lonnet::homeserver($cnum,$cdom); if ($chome ne 'no_host') { - # Check for ltoken or linkkey - my $newlauncher = &launch_check($r->uri,$symb,$cnum,$cdom); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['ttoken']); if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { + # Check for ttoken + my $newlauncher = &launch_check($r->uri,$symb); my ($map,$resid,$url) = &Apache::lonnet::decode_symb($symb); if (&Apache::lonnet::is_on_map($url)) { my $realuri; @@ -207,6 +208,9 @@ sub handler { } my $destination .= '/adm/roles?selectrole=1&'.$newrole.'=1'. '&destinationurl='.&HTML::Entities::encode($r->uri); + if ($env{'form.ttoken'}) { + $destination .= '&ttoken='.$env{'form.ttoken'}; + } &do_redirect($r,$destination); } elsif (keys(%possroles) > 1) { if (grep(/^(cc|co)$/,@allposs)) { @@ -219,6 +223,9 @@ sub handler { $newrole .= "./$cdom/$cnum"; my $destination .= '/adm/roles?selectrole=1&'.$newrole.'=1'. '&destinationurl='.&HTML::Entities::encode($r->uri); + if ($env{'form.ttoken'}) { + $destination .= '&ttoken='.$env{'form.ttoken'}; + } &do_redirect($r,$destination); } else { my $hascustom; @@ -243,13 +250,12 @@ sub handler { } sub launch_check { - my ($linkuri,$symb,$cnum,$cdom) = @_; - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['ltoken','linkkey']); + my ($linkuri,$symb) = @_; my ($linkprotector,$linkproturi,$linkkey,$newlauncher); - if ($env{'form.ltoken'}) { - my %link_info = &Apache::lonnet::tmpget($env{'form.ltoken'}); - &Apache::lonnet::tmpdel($env{'form.ltoken'}); - delete($env{'form.ltoken'}); + if ($env{'form.ttoken'}) { + my %link_info = &Apache::lonnet::tmpget($env{'form.ttoken'}); + &Apache::lonnet::tmpdel($env{'form.ttoken'}); + delete($env{'form.ttoken'}); if ($link_info{'linkprot'}) { ($linkprotector,$linkproturi) = split(/:/,$link_info{'linkprot'},2); if ($env{'user.linkprotector'}) { @@ -272,84 +278,101 @@ sub launch_check { } else { &Apache::lonnet::appenv({'user.linkproturi' => $linkproturi}); } - } - } elsif ($env{'form.linkkey'}) { - $linkkey = $env{'form.linkkey'}; - my $keyedlinkuri = $linkuri; - if ($env{'user.deeplinkkey'}) { - my @linkkeys = split(/,/,$env{'user.deeplinkkey'}); - unless (grep(/^\Q$linkkey\E$/,@linkkeys)) { - push(@linkkeys,$linkkey); - &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))}); - } - } else { - &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey}); - } - if ($env{'user.keyedlinkuri'}) { - my @keyeduris = split(/,/,$env{'user.keyedlinkuri'}); - unless (grep(/^\Q$keyedlinkuri\E$/,@keyeduris)) { - push(@keyeduris,$keyedlinkuri); - &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))}); + } elsif ($link_info{'linkkey'} ne '') { + $linkkey = $link_info{'linkkey'}; + my $keyedlinkuri = $linkuri; + if ($env{'user.deeplinkkey'} ne '') { + my @linkkeys = split(/,/,$env{'user.deeplinkkey'}); + unless (grep(/^\Q$linkkey\E$/,@linkkeys)) { + push(@linkkeys,$linkkey); + &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))}); + } + } else { + &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey}); } - } else { - &Apache::lonnet::appenv({'user.keyedlinkuri' => $keyedlinkuri}); - } - delete($env{'form.linkkey'}); - } - if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { - my $currdeeplinklogin = $env{'request.deeplink.login'}; - if ($linkprotector || $linkkey) { - my $deeplink; - if ($symb =~ /\.(page|sequence)$/) { - my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($symb))[2]); - my $navmap = Apache::lonnavmaps::navmap->new(); - if (ref($navmap)) { - $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink'); + if ($env{'user.keyedlinkuri'}) { + my @keyeduris = split(/,/,$env{'user.keyedlinkuri'}); + unless (grep(/^\Q$keyedlinkuri\E$/,@keyeduris)) { + push(@keyeduris,$keyedlinkuri); + &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))}); } } else { - $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb); + &Apache::lonnet::appenv({'user.keyedlinkuri' => $keyedlinkuri}); } - if ($deeplink ne '') { - my $disallow; - my ($state,$others,$listed,$scope,$protect) = split(/,/,$deeplink); - if (($protect ne 'none') && ($protect ne '')) { - my ($acctype,$item) = split(/:/,$protect); - if ($acctype =~ /lti(c|d)$/) { - unless ($linkprotector.':'.$linkproturi eq $item.$1.':'.$linkuri) { - $disallow = 1; - } - } elsif ($acctype eq 'key') { - unless ($linkkey eq $item) { - $disallow = 1; - } + } + if ($link_info{'checklaunch'}) { + $newlauncher = 1; + } + } + my $currdeeplinklogin = $env{'request.deeplink.login'}; + my $deeplink; + if ($symb =~ /\.(page|sequence)$/) { + my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($symb))[2]); + my $navmap = Apache::lonnavmaps::navmap->new(); + if (ref($navmap)) { + $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink'); + } + } else { + $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb); + } + if ($deeplink ne '') { + my $disallow; + my ($state,$others,$listed,$scope,$protect) = split(/,/,$deeplink); + if (($protect ne 'none') && ($protect ne '')) { + my ($acctype,$item) = split(/:/,$protect); + if ($acctype =~ /lti(c|d)$/) { + my $ltitype = $1; + if ($linkprotector) { + unless ($linkprotector.':'.$linkproturi eq $item.$ltitype.':'.$linkuri) { + $disallow = 1; } + } else { + $disallow = 1; } - if ($disallow) { - if ($currdeeplinklogin eq $linkuri) { - &Apache::lonnet::delenv('request.deeplink.login'); + } elsif ($acctype eq 'key') { + if ($linkkey ne '') { + unless ($linkkey eq $item) { + $disallow = 1; } } else { - unless ($currdeeplinklogin eq $linkuri) { - if ($linkprotector) { - &Apache::lonnet::appenv({'request.linkprot' => $linkprotector.':'.$linkproturi}); - } elsif ($linkkey) { - &Apache::lonnet::appenv({'request.linkkey' => $linkkey}); - } - $newlauncher = 1; - } - &Apache::lonnet::appenv({'request.deeplink.login' => $linkuri}); + $disallow = 1; } } + } + if ($disallow) { + if ($currdeeplinklogin eq $linkuri) { + &Apache::lonnet::delenv('request.deeplink.login'); + } } else { + unless ($currdeeplinklogin eq $linkuri) { + if (($linkprotector) || ($linkkey ne '')) { + if ($linkprotector) { + &Apache::lonnet::appenv({'request.linkprot' => $linkprotector.':'.$linkproturi}); + } elsif ($env{'request.linkprot'}) { + &Apache::lonnet::delenv({'request.linkprot'}); + } + if ($linkkey ne '') { + &Apache::lonnet::appenv({'request.linkkey' => $linkkey}); + } elsif ($env{'request.linkkey'} ne '') { + &Apache::lonnet::delenv({'request.linkkey'}); + } + $newlauncher = 1; + } + } &Apache::lonnet::appenv({'request.deeplink.login' => $linkuri}); } } else { - &Apache::lonnet::appenv({'request.deeplink.login' => $linkuri}); if ($linkprotector) { &Apache::lonnet::appenv({'request.linkprot' => $linkprotector.':'.$linkproturi}); - } elsif ($linkkey) { + } elsif ($env{'request.linkprot'}) { + &Apache::lonnet::delenv({'request.linkprot'}); + } + if ($linkkey ne '') { &Apache::lonnet::appenv({'request.linkkey' => $linkkey}); + } else { + &Apache::lonnet::delenv({'request.linkkey'}); } + &Apache::lonnet::appenv({'request.deeplink.login' => $linkuri}); } return $newlauncher; } @@ -402,12 +425,15 @@ sub show_roles { $preamble = &mt('You have the following active roles in this course:'); } $datatable = '
'. - ''. - ''. - ''. - &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(). - ''.&mt('User role').''; + ''."\n". + ''."\n". + ''."\n"; + if ($env{'form.ttoken'}) { + $datatable .= ''."\n"; + } + $datatable .= &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ''.&mt('User role').''; if ($hassection) { $datatable .= ''.&mt('Section').''; }