--- loncom/auth/lonroles.pm 2024/09/07 01:49:32 1.269.2.39.2.10
+++ loncom/auth/lonroles.pm 2023/06/20 14:04:02 1.370
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.269.2.39.2.10 2024/09/07 01:49:32 raeburn Exp $
+# $Id: lonroles.pm,v 1.370 2023/06/20 14:04:02 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,$only_body) = @_;
&Apache::loncommon::content_type($r,'text/html');
@@ -186,26 +190,6 @@ sub finish_loading_course {
&HTML::Entities::encode($url,'"<>&').'">'.&mt('Continue').'';
my $end_page = &Apache::loncommon::end_page();
my $js_url = &js_escape($url);
- my $remote_js;
- if ($env{'environment.remote'} eq 'on') {
- my ($menucoll,$deeplinkmenu,$menuref) = &Apache::loncommon::menucoll_in_effect();
- if ($menucoll) {
- &Apache::lonnet::put('environment',{'remote' => 'off'});
- &Apache::lonnet::appenv({'environment.remote' => 'off'});
- my $menu_name = &Apache::lonmenu::get_menu_name();
- $remote_js = <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;
@@ -428,6 +411,8 @@ sub handler {
}
}
+ $registered_cleanup=0;
+ @{$rosterupdates}=();
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
# -------------------------------------------------- Check if setting hot list
@@ -459,15 +444,27 @@ sub handler {
$reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
}
+# ------------------------------------------------- Check for approval results
+ my $approvalresult;
+ if (($env{'form.approvals'} eq 'show') && ($env{'form.state'} eq 'done')) {
+ $approvalresult = &Apache::loncoursequeueadmin::update_request_queue('othdombyuser',
+ $env{'user.domain'});
+ }
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; }
@@ -521,7 +518,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});
@@ -533,8 +530,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}) {
@@ -625,10 +622,9 @@ sub handler {
}
last;
}
- }
+ }
}
}
-
foreach $envkey (keys(%env)) {
next if ($envkey!~/^user\.role\./);
my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
@@ -707,7 +703,7 @@ sub handler {
$env{'user.name'},
&mt('Assigned from [_1] at [_2] for [_3]'
,$ip
- ,&Apache::lonlocal::locallocaltime($now)
+ ,&Apache::lonlocal::locallocaltime()
,$trolecode)
);
unless ($assignresult eq 'ok') {
@@ -836,7 +832,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'}.
@@ -877,7 +873,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 =~ /\?/) {
@@ -900,14 +896,14 @@ ENDCLOSE
&set_supplemental_access($cnum,$cdom);
}
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) {
@@ -929,6 +925,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);
+ }
if ($env{'request.deeplink.login'}) {
&set_deeplink_target($cnum,$cdom);
}
@@ -944,12 +944,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.',
@@ -960,6 +960,10 @@ ENDCLOSE
}
} else {
&set_supplemental_access($cnum,$cdom);
+ if (($env{'request.lti.login'}) &&
+ ($env{'request.lti.rosterid'} || $env{'request.lti.passbackid'})) {
+ &process_lti($r,$cdom,$cnum);
+ }
if ($env{'request.deeplink.login'}) {
&set_deeplink_target($cnum,$cdom);
}
@@ -970,6 +974,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 = '
';
&finish_loading_course($r,$msg,'/adm/whatsnew?refpage=start',$only_body);
$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);
@@ -1098,13 +1115,18 @@ ENDCLOSE
$furl = '/adm/navmaps?showOnlyHomework=1';
}
}
- $msg = '
';
+ &finish_loading_course($r,$msg,$furl,$only_body);
+ }
}
$r->rflush();
- return OK;
+ return OK;
}
}
#
@@ -1190,16 +1212,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,$domdefs{'userapprovals'});
+ 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.').' ';
@@ -1229,11 +1277,15 @@ function enterrole (thisform,rolecode,bu
}
function rolesView (caller) {
- if ((caller == 'showall') || (caller == 'noshowall')) {
+ if (caller == 'approvals') {
+ document.rolechoice.approvals.value = 'show';
+ } else if (caller == 'noapprovals') {
+ document.rolechoice.approvals.value = 'hide';
+ } else if ((caller == 'showall') || (caller == 'noshowall')) {
document.rolechoice.display.value = caller;
} else {
if ((caller == 'doupdate') || (caller == 'requestauthor') ||
- (caller == 'queued')) {
+ (caller == 'queued')) {
document.rolechoice.state.value = caller;
}
}
@@ -1312,7 +1364,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) {
@@ -1330,17 +1382,26 @@ ENDHEADER
$r->print($showresult);
} elsif ($env{'form.state'} eq 'queued') {
$r->print(&get_queued());
+ } elsif ($env{'form.approvals'} eq 'show') {
+ if ($env{'form.state'} eq 'done') {
+ $r->print($approvalresult).' ';
+ }
+ $r->print(' ');
}
if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
$fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
}
my $display = ($env{'form.display'} =~ /^(showall)$/);
+ my $approvals = ($env{'form.approvals'} =~ /^(show)$/);
$r->print('');
+ $r->rflush();
+ $r->print('');
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
}
# ----------------------------------------------------------------------- Table
@@ -1584,6 +1669,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}))) {
@@ -1652,10 +1738,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);
@@ -1664,7 +1763,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
@@ -1700,9 +1801,9 @@ sub gather_roles {
foreach my $rolename (sort(keys(%{$domdef{'adhocroles'}}))) {
if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') {
$adhocdesc{$tdom}{$rolename} = $domdef{'adhocroles'}{$rolename}{'desc'};
+ $desc = $adhocdesc{$tdom}{$rolename};
}
}
- $desc = $adhocdesc{$tdom}{$rolename};
}
}
if ($desc ne '') {
@@ -1763,6 +1864,9 @@ sub gather_roles {
$skipcal = 1;
}
}
+ if ($ttype eq 'Placement') {
+ $ttype = 'Placement Test';
+ }
if ($tsection) {
$twhere.=' '.&mt('Section').': '.$tsection;
}
@@ -1878,7 +1982,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;
}
@@ -1940,7 +2044,7 @@ 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.').'
');
@@ -1948,7 +2052,7 @@ sub findcourse_advice {
$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.').'