--- loncom/auth/lonroles.pm 2016/10/27 22:53:48 1.269.2.28 +++ loncom/auth/lonroles.pm 2015/04/13 18:32:43 1.311 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.269.2.28 2016/10/27 22:53:48 raeburn Exp $ +# $Id: lonroles.pm,v 1.311 2015/04/13 18:32:43 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -143,7 +143,7 @@ use Apache::lonrss; use GDBM_File; use LONCAPA qw(:DEFAULT :match); use HTML::Entities; - + sub redirect_user { my ($r,$title,$url,$msg) = @_; @@ -151,7 +151,6 @@ 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, @@ -166,11 +165,6 @@ sub redirect_user { $url=~s/ /\%20/g; $r->print(< -// -

$msg

$end_page ENDREDIR @@ -229,7 +223,7 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); -# -------------------------------------------------- Check if setting hot list +# -------------------------------------------------- Check if setting hot list my $hotlist; if ($env{'form.action'} eq 'verify_and_change_rolespref') { $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r); @@ -260,8 +254,7 @@ sub handler { my $envkey; my %dcroles = (); - my %dhroles = (); - my ($numdc,$numdh,$numadhoc) = &check_for_adhoc(\%dcroles,\%dhroles,$update,$then); + my $numdc = &check_fordc(\%dcroles,$update,$then); my $loncaparev = $r->dir_config('lonVersion'); # ================================================================== Roles Init @@ -270,15 +263,8 @@ sub handler { my $locknum=&Apache::lonnet::get_locks(); if ($locknum) { return 409; } - 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 - if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) { - if ($dhroles{$1}) { - $custom_adhoc = 1; - } - } } if ($env{'request.course.id'}) { # Check if user is CC trying to select a course role @@ -309,129 +295,75 @@ sub handler { "request.role" => 'cm', "request.role.adv" => $env{'user.adv'}, "request.role.domain" => $env{'user.domain'}}); -# Check if Domain Helpdesk role trying to enter a course needs privs to be created - if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)$}) { - my $cdom = $1; - my $rolename = $2; - my $cnum = $3; - 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)) { - if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now, - "cr/$cdom/$cdom".'-domainconfig/'.$rolename)) { - &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time}); - } - } - } - } - } elsif (($numdc > 0) || ($numdh > 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 + if ($numdc > 0) { foreach my $envkey (keys(%env)) { - if ($numdc) { # Is this an ad-hoc Coordinator role? - if (my ($ccrole,$domain,$coursenum) = - ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) { - if ($dcroles{$domain}) { - if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum, - $update,$refresh,$now,$ccrole)) { - &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time}); - } + if (my ($ccrole,$domain,$coursenum) = + ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) { + if ($dcroles{$domain}) { + if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum, + $update,$refresh,$now,$ccrole)) { + &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time}); } - last; } + last; + } # Is this an ad-hoc CA-role? - if (my ($domain,$user) = - ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) { - if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) { - delete($env{$envkey}); - $env{'form.au./'.$domain.'/'} = 1; + if (my ($domain,$user) = + ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) { + if (($domain eq $env{'user.domain'}) && ($user eq $env{'user.name'})) { + delete($env{$envkey}); + $env{'form.au./'.$domain.'/'} = 1; + my ($server_status,$home) = &check_author_homeserver($user,$domain); + if ($server_status eq 'switchserver') { + my $trolecode = 'au./'.$domain.'/'; + my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; + $r->internal_redirect($switchserver); + return OK; + } + last; + } + if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) { + if (((($castart) && ($castart < $now)) || !$castart) && + ((!$caend) || (($caend) && ($caend > $now)))) { my ($server_status,$home) = &check_author_homeserver($user,$domain); if ($server_status eq 'switchserver') { - my $trolecode = 'au./'.$domain.'/'; + my $trolecode = 'ca./'.$domain.'/'.$user; my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; $r->internal_redirect($switchserver); return OK; } last; } - if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) { - if (((($castart) && ($castart < $now)) || !$castart) && - ((!$caend) || (($caend) && ($caend > $now)))) { - my ($server_status,$home) = &check_author_homeserver($user,$domain); - if ($server_status eq 'switchserver') { - my $trolecode = 'ca./'.$domain.'/'.$user; - my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode; - $r->internal_redirect($switchserver); - return OK; - } - last; - } - } - # Check if author blocked ca-access - my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user); - if ($blocked{'domcoord.author'} eq 'blocked') { - delete($env{$envkey}); - $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access'; - last; - } - if ($dcroles{$domain}) { - my ($server_status,$home) = &check_author_homeserver($user,$domain); - if (($server_status eq 'ok') || ($server_status eq 'switchserver')) { - &Apache::lonnet::check_adhoc_privs($domain,$user,$update, - $refresh,$now,'ca'); - if ($server_status eq 'switchserver') { - my $trolecode = 'ca./'.$domain.'/'.$user; - my $switchserver = '/adm/switchserver?' - .'otherserver='.$home.'&role='.$trolecode; - $r->internal_redirect($switchserver); - return OK; - } - } else { - delete($env{$envkey}); - } - } else { - delete($env{$envkey}); - } + } + # Check if author blocked ca-access + my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user); + if ($blocked{'domcoord.author'} eq 'blocked') { + delete($env{$envkey}); + $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access'; last; } - } - if ($numdh) { -# Is this an ad hoc custom role in a course/community? - if (my ($domain,$rolename,$coursenum) = ($envkey =~ m{^form\.cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)$})) { - 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 (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,$update,$refresh,$now, - "cr/$domain/$domain".'-domainconfig/'.$rolename)) { - &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.cr/$domain/$domain". - '-domainconfig/'."$rolename.adhoc" => time}); - } - } else { - delete($env{$envkey}); - } - } else { - delete($env{$envkey}); + if ($dcroles{$domain}) { + my ($server_status,$home) = &check_author_homeserver($user,$domain); + if (($server_status eq 'ok') || ($server_status eq 'switchserver')) { + &Apache::lonnet::check_adhoc_privs($domain,$user,$update, + $refresh,$now,'ca'); + if ($server_status eq 'switchserver') { + my $trolecode = 'ca./'.$domain.'/'.$user; + my $switchserver = '/adm/switchserver?' + .'otherserver='.$home.'&role='.$trolecode; + $r->internal_redirect($switchserver); + return OK; } } else { delete($env{$envkey}); } - last; + } else { + delete($env{$envkey}); } - } + last; + } } } @@ -580,10 +512,10 @@ ENDENTERKEY if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) { my $msg; - my ($furl,$ferr)= - &Apache::lonuserstate::readmap($cdom.'/'.$cnum); + my ($furl,$ferr)= + &Apache::lonuserstate::readmap($cdom.'/'.$cnum); unless ($ferr) { - 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'}. @@ -606,7 +538,7 @@ ENDENTERKEY } 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 =~ /\?/) { @@ -672,7 +604,7 @@ ENDENTERKEY if ($env{'request.role.adv'}) { $dest = &Apache::lonenc::unencrypted($dest); if ($destsymb eq '') { - ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); + ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); $destsymb = &unescape($destsymb); } } @@ -697,7 +629,7 @@ ENDENTERKEY } } } - 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 .= '?symb='.$esc_symb; @@ -772,12 +704,6 @@ ENDENTERKEY $redirect_url); return OK; } - if ($role eq 'dh') { - my $redirect_url = '/adm/menu/'; - &redirect_user($r,&mt('Loading Domain Helpdesk Menu'), - $redirect_url); - return OK; - } if ($role eq 'sc') { my $redirect_url = '/adm/grades?command=scantronupload'; &redirect_user($r,&mt('Loading Data Upload Page'), @@ -806,7 +732,7 @@ ENDENTERKEY $crumbtext = 'Courses'; $pagetitle = 'My Courses'; $recent = &mt('Recent Courses'); - $standby = &mt('Course selected. Please stand by.'); + $standby = &mt('Course selected. Please stand by.'); } my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}]; @@ -814,20 +740,14 @@ ENDENTERKEY my $showcount = &roles_from_env(\%roles_in_env,$update); my $swinfo=&Apache::lonmenu::rawconfig(); + my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum}); my %domdefs=&Apache::lonnet::get_domain_defaults($env{'user.domain'}); my $cattype = 'std'; if ($domdefs{'catauth'}) { $cattype = $domdefs{'catauth'}; } my $funcs = &get_roles_functions($showcount,$cattype); - my $crumbsright; - if ($env{'browser.mobile'}) { - $crumbsright = $funcs; - undef($funcs); - } - my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum, - bread_crumbs_component=>$crumbsright}); - &js_escape(\$standby); + $standby=~s/\n/\\n/g; 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.').'

'; $r->print(<print($showresult); } elsif ($env{'form.state'} eq 'queued') { @@ -1025,7 +945,7 @@ ENDHEADER } # ----------------------------------------------------------------------- Table - if (($numdc > 0) || (($numdh > 0) && ($numadhoc > 0))) { + if ($numdc > 0) { $r->print(&coursepick_jscript()); $r->print(&Apache::loncommon::coursebrowser_javascript(). &Apache::loncommon::authorbrowser_javascript()); @@ -1058,12 +978,9 @@ ENDHEADER $roletext{'user.role.'.$role}->[1]. &Apache::loncommon::end_data_table_row(); } - if ($role =~ m{^dc\./($match_domain)/$} + 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 ($numdc > 0) { unless ($role =~/^error\:/) { @@ -1405,7 +1322,7 @@ sub roletable_headers { my $doheaders; if ((ref($sortrole) eq 'HASH') && (ref($roleclass) eq 'HASH')) { $r->print('
' - .&Apache::loncommon::start_data_table('LC_textsize_mobile') + .&Apache::loncommon::start_data_table() .&Apache::loncommon::start_data_table_header_row() ); if (!$nochoose) { $r->print(' '); } @@ -1454,15 +1371,12 @@ sub print_rolerows { &Apache::loncommon::end_data_table_row(); } } - if ($sortrole->{$which} =~ m{^user\.role\.dc\./($match_domain)/}) { + if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) { if (ref($dcroles) eq 'HASH') { if ($dcroles->{$1}) { $output .= &adhoc_roles_row($1,''); } } - } elsif (($sortrole->{$which} =~ m{^user\.role\.dh\./($match_domain)/}) && - ($env{'environment.adhocroles.'.$1} ne '')) { - $output .= &adhoc_customroles_row($1,''); } } } @@ -1719,42 +1633,29 @@ sub check_author_homeserver { } } -sub check_for_adhoc { - my ($dcroles,$dhroles,$update,$then) = @_; +sub check_fordc { + my ($dcroles,$update,$then) = @_; my $numdc = 0; - my $numdh = 0; - my $numadhoc = 0; - my $num_custom_adhoc = 0; if ($env{'user.adv'}) { foreach my $envkey (sort(keys(%env))) { - if ($envkey=~/^user\.role\.(dc|dh)\.\/($match_domain)\/$/) { - my $role = $1; - my $roledom = $2; - my $liverole = 1; + if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) { + my $dcdom = $1; + my $livedc = 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 'dc./'.$dcdom.'/') { $limit = $then; } - if ($tstart && $tstart>$limit) { $liverole = 0; } - if ($tend && $tend <$limit) { $liverole = 0; } - if ($liverole) { - if ($role eq 'dc') { - $dcroles->{$roledom} = $envkey; - $numdc++; - } else { - $dhroles->{$roledom} = $envkey; - if ($env{'environment.adhocroles.'.$roledom} ne '') { - $numadhoc ++; - } - $numdh++; - } + if ($tstart && $tstart>$limit) { $livedc = 0; } + if ($tend && $tend <$limit) { $livedc = 0; } + if ($livedc) { + $$dcroles{$dcdom} = $envkey; + $numdc++; } } } } - return ($numdc,$numdh,$numadhoc); + return $numdc; } sub adhoc_course_role { @@ -1846,25 +1747,23 @@ sub check_forcc { } sub courselink { - my ($roledom,$rowtype,$role) = @_; + my ($dcdom,$rowtype) = @_; my $courseform=&Apache::loncommon::selectcourse_link - ('rolechoice','course'.$rowtype.'_'.$roledom.'_'.$role, - 'domain'.$rowtype.'_'.$roledom.'_'.$role, - 'coursedesc'.$rowtype.'_'.$roledom.'_'.$role, - $roledom.':'.$role,undef,'Course/Community'); - my $hiddenitems = ''. - ''. - ''. - ''; + ('rolechoice','dccourse'.$rowtype.'_'.$dcdom, + 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'. + $dcdom,$dcdom,undef,'Course/Community'); + my $hiddenitems = ''. + ''. + ''. + ''; return $courseform.$hiddenitems; } sub coursepick_jscript { - my %js_lt = &Apache::lonlocal::texthash( + my %lt = &Apache::lonlocal::texthash( plsu => "Please use the 'Select Course/Community' link to open a separate pick course window where you may select the course or community you wish to enter.", youc => 'You can only use this screen to select courses and communities in the current domain.', ); - &js_escape(\%js_lt); my $verify_script = <<"END";