--- loncom/auth/lonroles.pm 2016/11/09 17:48:38 1.269.2.29 +++ loncom/auth/lonroles.pm 2020/09/08 04:33:36 1.269.2.37.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.269.2.29 2016/11/09 17:48:38 raeburn Exp $ +# $Id: lonroles.pm,v 1.269.2.37.2.1 2020/09/08 04:33:36 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -209,7 +209,7 @@ sub handler { my $r = shift; # Check for critical messages and redirect if present. - my ($redirect,$url) = &Apache::loncommon::critical_redirect(300); + my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'roles'); if ($redirect) { &Apache::loncommon::content_type($r,'text/html'); $r->header_out(Location => $url); @@ -260,8 +260,9 @@ sub handler { my $envkey; my %dcroles = (); - my %dhroles = (); - my ($numdc,$numdh,$numadhoc) = &check_for_adhoc(\%dcroles,\%dhroles,$update,$then); + my %helpdeskroles = (); + my ($numdc,$numhelpdesk,$numadhoc) = + &check_for_adhoc(\%dcroles,\%helpdeskroles,$update,$then); my $loncaparev = $r->dir_config('lonVersion'); # ================================================================== Roles Init @@ -273,9 +274,9 @@ sub handler { my $custom_adhoc; if ($env{'form.newrole'}) { $env{'form.'.$env{'form.newrole'}}=1; -# Check if this is a Domain Helpdesk role trying to enter a course +# Check if this is a Domain Helpdesk or Domain Helpdesk Assistant role trying to enter a course if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) { - if ($dhroles{$1}) { + if ($helpdeskroles{$1}) { $custom_adhoc = 1; } } @@ -316,11 +317,9 @@ sub handler { my $cnum = $3; my $sec = $4; if ($custom_adhoc) { - my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'}, - 'adhocroles.'.$cdom); - if (keys(%adhocroles)) { - my @adhoc = split(',',$adhocroles{'adhocroles.'.$cdom}); - if (grep(/^\Q$rolename\E$/,@adhoc)) { + my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum,1); + if (ref($possroles) eq 'ARRAY') { + 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}); @@ -328,9 +327,9 @@ sub handler { } } } - } elsif (($numdc > 0) || ($numdh > 0)) { + } elsif (($numdc > 0) || ($numhelpdesk > 0)) { # 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 trying to enter a course 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? @@ -400,22 +399,13 @@ sub handler { last; } } - if ($numdh) { + if ($numhelpdesk) { # Is this an ad hoc custom role in a course/community? if (my ($domain,$rolename,$coursenum,$sec) = ($envkey =~ m{^form\.cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)(?:/(\w+)|$)})) { - if ($dhroles{$domain}) { - my @adhoc; - if ($env{'environment.adhocroles.'.$domain}) { - @adhoc = split(',',$env{'environment.adhocroles.'.$domain}); - } else { - my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'}, - 'adhocroles.'.$domain); - if (keys(%adhocroles)) { - @adhoc = split(',',$adhocroles{'adhocroles.'.$domain}); - } - } - if ((@adhoc > 0) && ($rolename ne '')) { - if (grep(/^\Q$rolename\E$/,@adhoc)) { + if ($helpdeskroles{$domain}) { + my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($domain.'_'.$coursenum,1); + if (ref($possroles) eq 'ARRAY') { + if (grep(/^\Q$rolename\E$/,@{$possroles})) { if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,$update,$refresh,$now, "cr/$domain/$domain".'-domainconfig/'.$rolename, undef,$sec)) { @@ -572,7 +562,7 @@ ENDENTERKEY $env{'user.name'}, $env{'user.home'}, "Role ".$trolecode); - + &Apache::lonnet::appenv( {'request.role' => $trolecode, 'request.role.domain' => $cdom, @@ -581,6 +571,15 @@ ENDENTERKEY my $tadv=0; if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) { + if ($role =~ m{^\Qcr/$cdom/$cdom\E\-domainconfig/(\w+)$}) { + my $rolename = $1; + my %domdef = &Apache::lonnet::get_domain_defaults($cdom); + if (ref($domdef{'adhocroles'}) eq 'HASH') { + if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') { + &Apache::lonnet::appenv({'request.role.desc' => $domdef{'adhocroles'}{$rolename}{'desc'}}); + } + } + } my $msg; my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum); @@ -591,6 +590,25 @@ ENDENTERKEY {$env{'user.name'}.':'.$env{'user.domain'}. ':'.$csec.':'.$role => $now},$cdom,$cnum); } + if (($env{"environment.internal.$cdom.$cnum.$role.adhoc"}) && + (&Apache::lonnet::allowed('vxc',$cdom.'_'.$cnum))) { + my $owner = $env{'course.'.$cdom.'_'.$cnum.'.internal.courseowner'}; + my @coowners = split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}); + my %auaccess; + foreach my $user ($owner,@coowners) { + my ($cpname,$cpdom) = split(/:/,$user); + my %auroles = &Apache::lonnet::get_my_roles($cpname,$cpdom,'userroles',undef,['au','ca','aa'],[$cdom]); + foreach my $key (keys(%auroles)) { + my ($auname,$audom,$aurole) = split(/:/,$key); + if ($aurole eq 'au') { + $auaccess{$cpname} = 1; + } else { + $auaccess{$auname} = 1; + } + } + } + &Apache::lonnet::appenv({'request.course.adhocsrcaccess' => join(',',sort(keys(%auaccess))) }); + } my ($feeds,$syllabus_time); &Apache::lonrss::advertisefeeds($cnum,$cdom,undef,\$feeds); &Apache::lonnet::appenv({'request.course.feeds' => $feeds}); @@ -670,6 +688,17 @@ ENDENTERKEY } } } + if (($dest =~ m{^\Q/public/$cdom/$cnum/syllabus\E.*(\?|\&)usehttp=1}) || + ($dest =~ m{^\Q/adm/wrapper/ext/\E(?!https:)})) { + if ($ENV{'SERVER_PORT'} == 443) { + unless (&Apache::lonnet::uses_sts()) { + my $hostname = $r->hostname(); + if ($hostname ne '') { + $dest = 'http://'.$hostname.$dest; + } + } + } + } if ($dest =~ m{^/enc/}) { if ($env{'request.role.adv'}) { $dest = &Apache::lonenc::unencrypted($dest); @@ -702,7 +731,7 @@ ENDENTERKEY unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) { if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) { my $esc_symb = &escape($destsymb); - $dest .= '?symb='.$esc_symb; + $dest .= (($dest =~/\?/)? '&':'?').'symb='.$esc_symb; } } &redirect_user($r, &mt('Entering [_1]', @@ -780,6 +809,12 @@ ENDENTERKEY $redirect_url); return OK; } + if ($role eq 'da') { + my $redirect_url = '/adm/menu/'; + &redirect_user($r,&mt('Loading Domain Helpdesk Assistant Menu'), + $redirect_url); + return OK; + } if ($role eq 'sc') { my $redirect_url = '/adm/grades?command=scantronupload'; &redirect_user($r,&mt('Loading Data Upload Page'), @@ -995,14 +1030,18 @@ ENDHEADER # No active roles if ($countactive==0) { - &requestcourse_advice($r,$cattype,$inrole); + my $elapsed = 0; + if ($now && $update) { + $elapsed = $now - $update; + } + &requestcourse_advice($r,$cattype,$inrole,$elapsed); $r->print(''); if ($countfuture) { $r->print(&mt('The following [quant,_1,role,roles] will become active in the future:',$countfuture)); my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole, $nochoose); &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles, - \%roletext); + \%roletext,$update,$then); my $tremark=''; my $tbg; if ($env{'request.role'} eq 'cm') { @@ -1027,10 +1066,12 @@ ENDHEADER } # ----------------------------------------------------------------------- Table - if (($numdc > 0) || (($numdh > 0) && ($numadhoc > 0))) { - $r->print(&coursepick_jscript()); - $r->print(&Apache::loncommon::coursebrowser_javascript(). - &Apache::loncommon::authorbrowser_javascript()); + if (($numdc > 0) || (($numhelpdesk > 0) && ($numadhoc > 0))) { + $r->print(&coursepick_jscript(). + &Apache::loncommon::coursebrowser_javascript()); + } + if ($numdc > 0) { + $r->print(&Apache::loncommon::authorbrowser_javascript()); } unless ((!&Apache::loncommon::show_course()) || ($nochoose) || ($countactive==1)) { @@ -1063,9 +1104,8 @@ ENDHEADER if ($role =~ m{^dc\./($match_domain)/$} && $dcroles{$1}) { $output .= &adhoc_roles_row($1,'recent'); - } elsif ($role =~ m{^dh\./($match_domain)/$} - && ($env{'environment.adhocroles.'.$1} ne '')) { - $output .= &adhoc_customroles_row($1,'recent'); + } elsif ($role =~ m{^(dh|da)\./($match_domain)/$}) { + $output .= &adhoc_customroles_row($1,$2,'recent',$update,$then); } } elsif ($numdc > 0) { unless ($role =~/^error\:/) { @@ -1094,7 +1134,7 @@ ENDHEADER $doheaders ++; } } - &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext); + &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext,$update,$then); if ($countactive > 1) { my $tremark=''; my $tbg; @@ -1171,6 +1211,7 @@ sub gather_roles { my $tryagain = $env{'form.tryagain'}; my @ids = &Apache::lonnet::current_machine_ids(); if (ref($roles_in_env) eq 'HASH') { + my %adhocdesc; foreach my $envkey (sort(keys(%{$roles_in_env}))) { my $button = 1; my $switchserver=''; @@ -1273,8 +1314,27 @@ sub gather_roles { $ttype = &Apache::loncommon::course_type($tcourseid); if ($role !~ /^cr/) { $trole = &Apache::lonnet::plaintext($role,$ttype,$tcourseid); - } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) { - $trole = &mt('Helpdesk[_1]',' '.$2); + } elsif ($role =~ m{^\Qcr/$tdom/$tdom\E\-domainconfig/(\w+)$}) { + my $rolename = $1; + my $desc; + if (ref($adhocdesc{$tdom}) eq 'HASH') { + $desc = $adhocdesc{$tdom}{$rolename}; + } else { + my %domdef = &Apache::lonnet::get_domain_defaults($tdom); + if (ref($domdef{'adhocroles'}) eq 'HASH') { + 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}; + } + } + } + } + if ($desc ne '') { + $trole = $desc; + } else { + $trole = &mt('Helpdesk[_1]',' '.$rolename); + } } else { $trole = (split(/\//,$role,4))[-1]; } @@ -1446,7 +1506,7 @@ sub roletypes { } sub print_rolerows { - my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext) = @_; + my ($r,$doheaders,$roleclass,$sortrole,$dcroles,$roletext,$update,$then) = @_; if ((ref($roleclass) eq 'HASH') && (ref($sortrole) eq 'HASH')) { my @types = &roletypes(); foreach my $type (@types) { @@ -1470,9 +1530,8 @@ sub print_rolerows { $output .= &adhoc_roles_row($1,''); } } - } elsif (($sortrole->{$which} =~ m{^user\.role\.dh\./($match_domain)/}) && - ($env{'environment.adhocroles.'.$1} ne '')) { - $output .= &adhoc_customroles_row($1,''); + } elsif ($sortrole->{$which} =~ m{^user\.role\.(dh|da)\./($match_domain)/}) { + $output .= &adhoc_customroles_row($1,$2,'',$update,$then); } } } @@ -1493,20 +1552,26 @@ sub print_rolerows { } sub findcourse_advice { - my ($r,$cattype) = @_; + my ($r,$cattype,$elapsed) = @_; my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description'); my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); if (&Apache::lonnet::auto_run(undef,$env{'user.domain'})) { - $r->print(&mt('If you were expecting to see an active role listed for a particular course in the [_1] domain, it may be missing for one of the following reasons:',$domdesc).' + $r->print('

'.&mt('If you were expecting to see an active role listed for a particular course in the [_1] domain, it may be missing for one of the following reasons:',$domdesc).'

'); +
  • '.&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.').'
    '); + $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.'). + '
    '. + &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').'

    '. @@ -1518,7 +1583,7 @@ sub findcourse_advice { } sub requestcourse_advice { - my ($r,$cattype,$inrole) = @_; + my ($r,$cattype,$inrole,$elapsed) = @_; my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description'); my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); my (%can_request,%request_doms,$output); @@ -1579,7 +1644,7 @@ sub requestcourse_advice { } else { $r->print('

    '.&mt('Currently no active roles, courses or communities').'

    '); } - &findcourse_advice($r,$cattype); + &findcourse_advice($r,$cattype,$elapsed); } return; } @@ -1642,9 +1707,11 @@ sub privileges_info { sub build_roletext { my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$trole,$twhere, $tpstart,$tpend,$nochoose,$button,$switchserver,$reinit,$switchwarning) = @_; - my ($roletext,$roletext_end); - my $is_dc=($trolecode =~ m/^dc\./); - my $rowspan=($is_dc) ? '' + my ($roletext,$roletext_end,$poss_adhoc); + if ($trolecode =~ m/^d(c|h|a)\./) { + $poss_adhoc = 1; + } + my $rowspan=($poss_adhoc) ? '' : ' rowspan="2" '; unless ($nochoose) { @@ -1705,7 +1772,7 @@ sub build_roletext { .''.$twhere.'' .''.$tpstart.'' .''.$tpend.''; - if (!$is_dc) { + unless ($poss_adhoc) { $roletext_end = ''. $tremark.' '. ''; @@ -1731,21 +1798,20 @@ sub check_author_homeserver { } sub check_for_adhoc { - my ($dcroles,$dhroles,$update,$then) = @_; + my ($dcroles,$helpdeskroles,$update,$then) = @_; my $numdc = 0; - my $numdh = 0; + my $numhelpdesk = 0; my $numadhoc = 0; my $num_custom_adhoc = 0; - if ($env{'user.adv'}) { + if (($env{'user.adv'}) || ($env{'user.rar'})) { foreach my $envkey (sort(keys(%env))) { - if ($envkey=~/^user\.role\.(dc|dh)\.\/($match_domain)\/$/) { + if ($envkey=~/^user\.role\.(dc|dh|da)\.\/($match_domain)\/$/) { my $role = $1; my $roledom = $2; my $liverole = 1; my ($tstart,$tend)=split(/\./,$env{$envkey}); my $limit = $update; - if ((($role eq 'dc') && ($env{'request.role'} eq 'dc./'.$roledom.'/')) || - (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$roledom.'/'))) { + if ($env{'request.role'} eq "$role./$roledom/") { $limit = $then; } if ($tstart && $tstart>$limit) { $liverole = 0; } @@ -1755,17 +1821,20 @@ sub check_for_adhoc { $dcroles->{$roledom} = $envkey; $numdc++; } else { - $dhroles->{$roledom} = $envkey; - if ($env{'environment.adhocroles.'.$roledom} ne '') { - $numadhoc ++; + $helpdeskroles->{$roledom} = $envkey; + my %domdefaults = &Apache::lonnet::get_domain_defaults($roledom); + if (ref($domdefaults{'adhocroles'}) eq 'HASH') { + if (keys(%{$domdefaults{'adhocroles'}})) { + $numadhoc ++; + } } - $numdh++; + $numhelpdesk++; } } } } } - return ($numdc,$numdh,$numadhoc); + return ($numdc,$numhelpdesk,$numadhoc); } sub adhoc_course_role { @@ -1964,9 +2033,9 @@ sub adhoc_roles_row { my ($dcdom,$rowtype) = @_; my $output = &Apache::loncommon::continue_data_table_row() .' ' - .&mt('[_1]Ad hoc[_2] roles in domain [_3] --' + .&mt('[_1]Ad hoc[_2] roles in domain [_3]' ,'','',$dcdom) - .' '; + .' -- '; my $role = 'cc'; my $selectcclink = &courselink($dcdom,$rowtype,$role); my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1); @@ -1979,20 +2048,25 @@ sub adhoc_roles_row { } sub adhoc_customroles_row { - my ($dhdom,$rowtype) = @_; - my $output = &Apache::loncommon::continue_data_table_row() - .' ' - .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3] --', - '','',$dhdom); - my @customroles = split(/,/,$env{'environment.adhocroles.'.$dhdom}); - my $count = 0; - foreach my $role (@customroles) { - next if (($role eq '') || ($role =~ /\W/)); - $output .= ' '.$role.': '.&courselink($dhdom,$rowtype,$role).' |'; - $count ++; - } - if ($count) { - return $output; + my ($role,$dhdom,$rowtype,$update,$then) = @_; + my $liverole = 1; + my ($tstart,$tend)=split(/\./,$env{"user.role.$role./$dhdom/"}); + my $limit = $update; + if (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$dhdom.'/')) { + $limit = $then; + } + if ($tstart && $tstart>$limit) { $liverole = 0; } + if ($tend && $tend <$limit) { $liverole = 0; } + return unless ($liverole); + 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() + .' ' + .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3]', + '','',$dhdom) + .' -- '.&courselink($dhdom,$rowtype,$role); + } } return; }