--- loncom/auth/lonroles.pm 2022/01/01 19:28:28 1.269.2.39.2.1 +++ loncom/auth/lonroles.pm 2021/11/30 15:55:40 1.359 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.269.2.39.2.1 2022/01/01 19:28:28 raeburn Exp $ +# $Id: lonroles.pm,v 1.359 2021/11/30 15:55:40 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -140,10 +140,14 @@ use Apache::lonnavdisplay(); use Apache::loncoursequeueadmin; use Apache::longroup; use Apache::lonrss; +use Apache::lonplacementtest; use GDBM_File; use LONCAPA qw(:DEFAULT :match); use HTML::Entities; - + +my $registered_cleanup; +my $rosterupdates; + sub start_loading_course { my ($r,$title) = @_; &Apache::loncommon::content_type($r,'text/html'); @@ -204,27 +208,27 @@ sub redirect_user { &Apache::loncommon::content_type($r,'text/html'); &Apache::loncommon::no_cache($r); $r->send_http_header; - my $swinfo=&Apache::lonmenu::rawconfig(); - # Breadcrumbs - my $brcrum = [{'href' => $url, - 'text' => 'Switching Role'},]; - my $start_page = &Apache::loncommon::start_page('Switching Role',undef, - {'redirect' => [1,$url], - 'bread_crumbs' => $brcrum,}); - my $end_page = &Apache::loncommon::end_page(); + my $start_page; + if ($env{'request.lti.login'}) { + $start_page = &Apache::loncommon::start_page(undef,undef, + {'redirect' => [0,$url],}).$msg; + } else { + # Breadcrumbs + my $brcrum = [{'href' => $url, + 'text' => 'Switching Role'},]; + $start_page = &Apache::loncommon::start_page('Switching Role',undef, + {'redirect' => [1,$url], + 'bread_crumbs' => $brcrum,}). + "\n

$msg

"; + } + my $end_page = &Apache::loncommon::end_page(); # Note to style police: # This must only replace the spaces, nothing else, or it bombs elsewhere. $url=~s/ /\%20/g; $r->print(< -// - -

$msg

$end_page ENDREDIR return; @@ -394,6 +398,8 @@ sub handler { } } + $registered_cleanup=0; + @{$rosterupdates}=(); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); # -------------------------------------------------- Check if setting hot list @@ -427,13 +433,19 @@ sub handler { my $envkey; my %dcroles = (); - my %helpdeskroles = (); - my ($numdc,$numhelpdesk,$numadhoc) = + my %helpdeskroles = (); + my ($numdc,$numhelpdesk,$numadhoc) = &check_for_adhoc(\%dcroles,\%helpdeskroles,$update,$then); my $loncaparev = $r->dir_config('lonVersion'); # ================================================================== Roles Init if ($env{'form.selectrole'}) { + if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq '')) { + if ($env{'form.ltitarget'} eq 'iframe') { + &Apache::lonnet::appenv({'request.lti.target' => 'iframe'}); + delete($env{'form.ltitarget'}); + } + } my $locknum=&Apache::lonnet::get_locks(); if ($locknum) { return 409; } @@ -486,7 +498,7 @@ sub handler { if ($custom_adhoc) { my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum,1); if (ref($possroles) eq 'ARRAY') { - if (grep(/^\Q$rolename\E$/,@{$possroles})) { + if (grep(/^\Q$rolename\E$/,@{$possroles})) { if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now, "cr/$cdom/$cdom".'-domainconfig/'.$rolename,undef,$sec)) { &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time}); @@ -498,8 +510,8 @@ sub handler { # Check if user is a DC trying to enter a course or author space and needs privs to be created # Check if user is a DH or DA trying to enter a course and needs privs to be created foreach my $envkey (keys(%env)) { - if ($numdc) { # Is this an ad-hoc Coordinator role? + if ($numdc) { if (my ($ccrole,$domain,$coursenum) = ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) { if ($dcroles{$domain}) { @@ -590,10 +602,9 @@ sub handler { } last; } - } + } } } - foreach $envkey (keys(%env)) { next if ($envkey!~/^user\.role\./); my ($where,$trolecode,$role,$tstatus,$tend,$tstart); @@ -790,7 +801,7 @@ ENDCLOSE $furl = '/adm/roles?tryagain=1'; } else { &Apache::lonnet::appenv({'request.course.timechecked'=>$now}); - unless (($env{'form.switchrole'}) || + unless (($env{'form.switchrole'}) || ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) { &Apache::lonnet::put('nohist_crslastlogin', {$env{'user.name'}.':'.$env{'user.domain'}. @@ -832,7 +843,7 @@ ENDCLOSE } if (($env{'form.orgurl'}) && ($env{'form.orgurl'}!~/^\/adm\/flip/) && - ($env{'form.orgurl'} ne '/adm/roles')) { + ($env{'form.orgurl'} ne '/adm/roles')) { my $dest=$env{'form.orgurl'}; if ($env{'form.symb'}) { if ($dest =~ /\?/) { @@ -853,14 +864,14 @@ ENDCLOSE } } if (($ferr) && ($tadv)) { - &error_page($r,$ferr,$furl); + &error_page($r,$ferr,$furl); } else { if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { if (($env{'form.orgurl'} ne '') && ($env{'form.symb'} ne '')) { unless (&Apache::lonnet::symbverify($env{'form.symb'},$env{'form.orgurl'})) { $dest=$env{'form.orgurl'}; } - } + } } if ($dest =~ m{^/adm/coursedocs\?folderpath}) { if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { @@ -882,6 +893,10 @@ ENDCLOSE &Apache::loncommon::end_page()); } } else { + if (($env{'request.lti.login'}) && + ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) { + &process_lti($r,$cdom,$cnum); + } $msg = '

'.&mt('Entering [_1] ...', $env{'course.'.$cdom.'_'.$cnum.'.description'}). '

'; @@ -894,12 +909,12 @@ ENDCLOSE if (!$env{'request.course.id'}) { &Apache::lonnet::appenv( {"request.course.id" => $cdom.'_'.$cnum}); - } + } if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; } &Apache::lonnet::appenv({'request.role.adv'=>$tadv}); - if ($ferr) { + if ($ferr) { if ($tadv) { - &error_page($r,$ferr,$furl); + &error_page($r,$ferr,$furl); } else { $r->print('

'. &mt('Could not initialize [_1] at this time.', @@ -909,6 +924,10 @@ ENDCLOSE &Apache::loncommon::end_page()); } } else { + if (($env{'request.lti.login'}) && + ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) { + &process_lti($r,$cdom,$cnum); + } # Check to see if the user is a CC entering a course # for the first time if ((($role eq 'cc') || ($role eq 'co')) @@ -916,6 +935,19 @@ ENDCLOSE $furl = "/adm/helper/course.initialization.helper"; # Send the user to the course they selected } elsif ($env{'request.course.id'}) { + if ((&Apache::loncommon::course_type() eq 'Placement') && + (!$env{'request.role.adv'})) { + my ($score,$incomplete) = + &Apache::lonplacementtest::check_completion(undef,undef,1); + if (($incomplete) && ($incomplete < 100)) { + $msg = '

'.&mt('Entering [_1] ...', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '

'; + &finish_loading_course($r,$msg,'/adm/placement'); + $r->rflush(); + return OK; + } + } my ($dest,$destsymb,$checkenc); $dest = $env{'form.destinationurl'}; $destsymb = $env{'form.destsymb'}; @@ -944,7 +976,7 @@ ENDCLOSE if ($env{'request.role.adv'}) { $dest = &Apache::lonenc::unencrypted($dest); if ($destsymb eq '') { - ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); + ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); $destsymb = &unescape($destsymb); } } @@ -969,18 +1001,20 @@ ENDCLOSE } } } - unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) { + unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) { if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) { my $esc_symb = &escape($destsymb); $dest .= (($dest =~/\?/)? '&':'?').'symb='.$esc_symb; } } - $msg = '

'.&mt('Entering [_1] ...', - $env{'course.'.$cdom.'_'.$cnum.'.description'}). - '

'; if ($env{'form.ttoken'}) { $dest .= (($dest =~/\?/)? '&':'?').'ttoken='.$env{'form.ttoken'}; } + unless ($env{'request.lti.login'}) { + $msg = '

'.&mt('Entering [_1] ...', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '

'; + } &finish_loading_course($r,$msg,$dest); $r->rflush(); return OK; @@ -998,18 +1032,18 @@ ENDCLOSE '

'; &finish_loading_course($r,$msg,'/adm/whatsnew?refpage=start'); $r->rflush(); - return OK; + return OK; } } } # Are we allowed to look at the first resource? # # $furl returned by lonuserstate::readmap() has format: - # $url?symb=escaped($symb). If the resource has the + # $url?symb=escaped($symb). If the resource has the # encrypturl parameter in effect, the entire string # $url?symb=escaped($symb) is encrypted as a string # beginning /enc/. - # + # my ($access,$unencfurl,$unencsymb); if ($furl =~ m{^(.+)(?:\?|\&)symb=([^&]+)(?:$|&)}) { my ($poss_url,$poss_symb) = ($1,$2); @@ -1042,13 +1076,18 @@ ENDCLOSE $furl = '/adm/navmaps?showOnlyHomework=1'; } } - $msg = '

'.&mt('Entering [_1] ...', - $env{'course.'.$cdom.'_'.$cnum.'.description'}). - '

'; - &finish_loading_course($r,$msg,$furl); + if ($env{'request.lti.login'}) { + undef($msg); + &finish_loading_course($r,$msg,$furl); + } else { + $msg = '

'.&mt('Entering [_1] ...', + $env{'course.'.$cdom.'_'.$cnum.'.description'}). + '

'; + &finish_loading_course($r,$msg,$furl); + } } $r->rflush(); - return OK; + return OK; } } # @@ -1128,16 +1167,42 @@ ENDCLOSE if ($domdefs{'catauth'}) { $cattype = $domdefs{'catauth'}; } - my ($funcs,$crumbsright); - unless (($norolelist) && ((split(/:/,$env{'user.error.msg'}))[2])) { - $funcs = &get_roles_functions($showcount,$cattype); - if ($env{'browser.mobile'}) { - $crumbsright = $funcs; - undef($funcs); + my $placementonly; + if ($showcount == 1) { + if ($env{'request.course.id'}) { + if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') { + $placementonly = 1; + } + } else { + foreach my $rolecode (keys(%roles_in_env)) { + my ($cid) = ($rolecode =~ m{^\Quser.role.st./\E($match_domain/$match_courseid)(?:/|$)}); + if ($cid) { + my %coursedescription = + &Apache::lonnet::coursedescription($cid,{'one_time' => '1'}); + if ($coursedescription{'type'} eq 'Placement') { + $placementonly = 1; + } + last; + } + } + } + } + my ($start_page,$funcs); + if ($placementonly) { + $start_page=&Apache::loncommon::start_page($pagetitle,undef, + {bread_crumbs=>$brcrum,crstype=>'Placement'}); + } else { + my $crumbsright; + unless (($norolelist) && ((split(/:/,$env{'user.error.msg'}))[2])) { + $funcs = &get_roles_functions($showcount,$cattype); + if ($env{'browser.mobile'}) { + $crumbsright = $funcs; + undef($funcs); + } } + $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum, + bread_crumbs_component=>$crumbsright}); } - my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum, - bread_crumbs_component=>$crumbsright}); &js_escape(\$standby); my $noscript='
'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'
'.&mt('As this is not the case, most functionality in the system will be unavailable.').'

'; @@ -1171,7 +1236,7 @@ function rolesView (caller) { document.rolechoice.display.value = caller; } else { if ((caller == 'doupdate') || (caller == 'requestauthor') || - (caller == 'queued')) { + (caller == 'queued')) { document.rolechoice.state.value = caller; } } @@ -1250,7 +1315,7 @@ ENDHEADER &mt('You may need to login to LON-CAPA directly, or re-launch from a different external system.'). ''); } - $r->print(&Apache::loncommon::end_page()); + $r->print(&Apache::loncommon::end_page()); return OK; } else { if ($updateresult || $reqauthor || $hotlist) { @@ -1263,7 +1328,7 @@ ENDHEADER } if ($hotlist) { $showresult .= $hotlist; - } + } $showresult .= ''; $r->print($showresult); } elsif ($env{'form.state'} eq 'queued') { @@ -1298,7 +1363,21 @@ ENDHEADER \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev); $refresh = $now; &Apache::lonnet::appenv({'user.refresh.time' => $refresh}); - if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'})) { + if ($countactive == 1) { + if ($env{'request.course.id'}) { + if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') { + $placementonly = 1; + } + } elsif ($possiblerole) { + if ($possiblerole =~ m{^st\./($match_domain)/($match_courseid)(?:/|$)}) { + if ($env{'course.'.$1.'_'.$2.'.type'} eq 'Placement') { + $placementonly = 1; + } + } + } + } + if ((($cattype eq 'std') || ($cattype eq 'domonly')) && (!$env{'user.adv'}) && + (!$placementonly)) { if ($countactive > 0) { my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description'); my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); @@ -1375,6 +1454,16 @@ ENDHEADER } $r->print(&Apache::loncommon::end_page()); return OK; + } elsif (($placementonly) && ($env{'request.role'} eq 'cm')) { + $r->print('

'.&mt('Please stand by.').'

+ + '); + $r->rflush(); + $r->print(''); + $r->print(&Apache::loncommon::end_page()); + return OK; } # ----------------------------------------------------------------------- Table @@ -1522,6 +1611,7 @@ sub gather_roles { my $advanced = $env{'user.adv'}; my $tryagain = $env{'form.tryagain'}; my @ids = &Apache::lonnet::current_machine_ids(); + my (%willtrust,%trustchecked); if (ref($roles_in_env) eq 'HASH') { my %adhocdesc; foreach my $envkey (sort(keys(%{$roles_in_env}))) { @@ -1590,10 +1680,23 @@ sub gather_roles { if (($role eq 'ca') || ($role eq 'aa')) { my $home = &Apache::lonnet::homeserver($trest,$tdom); my $allowed=0; + my $prohibited; foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } if (!$allowed) { $button=0; - $switchserver='otherserver='.$home.'&role='.$trolecode; + unless ($trustchecked{$tdom}) { + if ((&Apache::lonnet::will_trust('othcoau',$env{'user.domain'},$tdom)) && + (&Apache::lonnet::will_trust('coaurem',$tdom,$env{'user.domain'}))) { + $willtrust{$tdom} = 1; + $trustchecked{$tdom} = 1; + } + } + if ($willtrust{$tdom}) { + $switchserver='otherserver='.$home.'&role='.$trolecode; + } else { + $prohibited = 1; + $tremark .= &mt('Session switch required but prohibited.'); + } } #next if ($home eq 'no_host'); $home = &Apache::lonnet::hostname($home); @@ -1602,7 +1705,9 @@ sub gather_roles { ': '.$tdom.'
'. ' '.&mt('Server').': '.$home; $env{'course.'.$tdom.'_'.$trest.'.description'}='ca'; - $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/'); + unless ($prohibited) { + $tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$trest.'/'); + } $sortkey=$role."$trest:$tdom"; } elsif ($role eq 'au') { # Authors @@ -1701,6 +1806,9 @@ sub gather_roles { $skipcal = 1; } } + if ($ttype eq 'Placement') { + $ttype = 'Placement Test'; + } if ($tsection) { $twhere.='
'.&mt('Section').': '.$tsection; } @@ -1816,7 +1924,7 @@ sub roletable_headers { } sub roletypes { - my @types = ('Domain','Authoring Space','Course','Community','Unavailable','System'); + my @types = ('Domain','Authoring Space','Course','Placement Test','Community','Unavailable','System'); return @types; } @@ -1878,15 +1986,15 @@ sub findcourse_advice {
  • '.&mt('You are in a section of course for which automatic enrollment in the corresponding LON-CAPA course is not active.').'
  • '.&mt('The start date for automated enrollment has yet to be reached.').'
  • '.&mt('You registered for the course recently and there is a time lag between the time you register, and the time this information becomes available for the update of LON-CAPA course rosters.').'
  • -
  • '.&mt('Automated enrollment added you to the course in the time since you last logged-in.').' '.&mt('If that is the case you can use the "Check for changes" link in the gray Functions bar to update the list of your available course roles.').'
  • +
  • '.&mt('Automated enrollment added you to the course in the time since you last logged-in.').' '.&mt('If that is the case you can use the "Check for changes" link in the gray Functions bar to update the list of your available course roles.').'
  • '); } else { $r->print('

    '.&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').'

    '); if ($elapsed > 600) { - $r->print('

    '.&mt('You may also have been assigned to a course in the time since you last logged-in, or checked for changes.'). + $r->print('

    '.&mt('You may also have been assigned to a course in the time since you last logged-in, or checked for changes'). '
    '. &mt('If that is the case you can use the "Check for changes" link in the gray Functions bar to update the list of your available course roles.').'

    '); - } + } } if (($cattype eq 'std') || ($cattype eq 'domonly')) { $r->print('

    '.&mt('Self-Enrollment').'

    '. @@ -2079,7 +2187,7 @@ sub build_roletext { $trolecode."','".$buttonname.'\');" />'; } } - if (($trolecode !~ m/^(dc|ca|au|aa)\./) && (!$skipcal)) { + if (($trolecode !~ m/^(dc|ca|au|aa)\./) && (!$skipcal)) { $tremark.=&Apache::lonannounce::showday(time,1, &Apache::lonannounce::readcalendar($tdom.'_'.$trest)); } @@ -2117,7 +2225,7 @@ sub check_for_adhoc { my $numdc = 0; my $numhelpdesk = 0; my $numadhoc = 0; - my $num_custom_adhoc = 0; + my $num_custom_adhoc = 0; if (($env{'user.adv'}) || ($env{'user.rar'})) { foreach my $envkey (sort(keys(%env))) { if ($envkey=~/^user\.role\.(dc|dh|da)\.\/($match_domain)\/$/) { @@ -2336,7 +2444,7 @@ sub display_cc_role { } else { $twhere=&mt('Currently not available'); $env{'course.'.$tcourseid.'.description'}=$twhere; - $skipcal = 1; + $skipcal = 1; } my $trole = &Apache::lonnet::plaintext($ccrole,$ttype,$tcourseid); $twhere.="
    ".&mt('Domain').":".$tdom; @@ -2361,7 +2469,7 @@ sub display_curr_role { my $ttype = $env{'course.'.$cid.'.type'}; my $skipcal = 1; my $tbg='LC_roles_is'; - my $twhere = $env{'course.'.$cid.'.description'}. + my $twhere = $env{'course.'.$cid.'.description'}. ' '. &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$cnum,$cdom). ''; @@ -2407,7 +2515,7 @@ sub adhoc_customroles_row { if ($tstart && $tstart>$limit) { $liverole = 0; } if ($tend && $tend <$limit) { $liverole = 0; } return unless ($liverole); - my %domdefaults = &Apache::lonnet::get_domain_defaults($dhdom); + my %domdefaults = &Apache::lonnet::get_domain_defaults($dhdom); if (ref($domdefaults{'adhocroles'}) eq 'HASH') { if (scalar(keys(%{$domdefaults{'adhocroles'}})) > 0) { return &Apache::loncommon::continue_data_table_row() @@ -2737,7 +2845,7 @@ sub update_session_roles { &curr_role_status($currstart,$currend,$refresh,$update); my ($rolekey) = ($envkey =~ /^user\.role\.(.+)$/); my ($role,$rest)=split(m{\./},$rolekey,2); - $rest = '/'.$rest; + $rest = '/'.$rest; if (&Apache::lonnet::delenv($envkey,undef,[$role])) { if ($status_in_env eq 'active') { if ($role eq 'gr') { @@ -2937,15 +3045,15 @@ sub update_session_roles { } my $groupdesc; unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') { - %{$curr_groups{$cdom.'_'.$cnum}} = + %{$curr_groups{$cdom.'_'.$cnum}} = &Apache::longroup::coursegroups($cdom,$cnum); } unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') && ($groupdescs{$cdom.'_'.$cnum}{$group})) { - my %groupinfo = + my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group}); - $groupdescs{$cdom.'_'.$cnum}{$group} = + $groupdescs{$cdom.'_'.$cnum}{$group} = &unescape($groupinfo{'description'}); } $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group}; @@ -3064,7 +3172,7 @@ sub update_session_roles { my $cdom = $env{'course.'.$cid.'.domain'}; my $cnum = $env{'course.'.$cid.'.num'}; my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum); - my %groupdesc; + my %groupdesc; if (ref($groupchange{$crs}) eq 'HASH') { $groupchgmsg .= '
  • '.&mt('Course/Community: [_1]',''.$crsdesc.'