--- loncom/auth/lonroles.pm 2017/01/22 14:28:20 1.269.2.30 +++ loncom/auth/lonroles.pm 2019/07/28 13:57:36 1.269.2.36 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.269.2.30 2017/01/22 14:28:20 raeburn Exp $ +# $Id: lonroles.pm,v 1.269.2.36 2019/07/28 13:57:36 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -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; } } @@ -326,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? @@ -398,10 +399,10 @@ 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}) { + 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})) { @@ -589,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}); @@ -668,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); @@ -700,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]', @@ -778,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'), @@ -1025,10 +1062,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)) { @@ -1061,7 +1100,7 @@ ENDHEADER if ($role =~ m{^dc\./($match_domain)/$} && $dcroles{$1}) { $output .= &adhoc_roles_row($1,'recent'); - } elsif ($role =~ m{^(dh)\./($match_domain)/$}) { + } elsif ($role =~ m{^(dh|da)\./($match_domain)/$}) { $output .= &adhoc_customroles_row($1,$2,'recent',$update,$then); } } elsif ($numdc > 0) { @@ -1487,7 +1526,7 @@ sub print_rolerows { $output .= &adhoc_roles_row($1,''); } } - } elsif ($sortrole->{$which} =~ m{^user\.role\.(dh)\./($match_domain)/}) { + } elsif ($sortrole->{$which} =~ m{^user\.role\.(dh|da)\./($match_domain)/}) { $output .= &adhoc_customroles_row($1,$2,'',$update,$then); } } @@ -1520,6 +1559,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.').'
  • '); } 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.').'
    '); @@ -1658,9 +1698,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) { @@ -1721,7 +1763,7 @@ sub build_roletext { .''.$twhere.'' .''.$tpstart.'' .''.$tpend.''; - if (!$is_dc) { + unless ($poss_adhoc) { $roletext_end = ''. $tremark.' '. ''; @@ -1747,21 +1789,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; } @@ -1771,20 +1812,20 @@ sub check_for_adhoc { $dcroles->{$roledom} = $envkey; $numdc++; } else { - $dhroles->{$roledom} = $envkey; + $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 { @@ -1983,9 +2024,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); @@ -2013,9 +2054,9 @@ sub adhoc_customroles_row { if (scalar(keys(%{$domdefaults{'adhocroles'}})) > 0) { return &Apache::loncommon::continue_data_table_row() .' ' - .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3] --', + .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3]', '','',$dhdom) - .' '.&courselink($dhdom,$rowtype,$role); + .' -- '.&courselink($dhdom,$rowtype,$role); } } return;