--- loncom/auth/lonroles.pm 2016/11/08 23:15:34 1.322 +++ loncom/auth/lonroles.pm 2017/01/21 19:58:05 1.324 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.322 2016/11/08 23:15:34 raeburn Exp $ +# $Id: lonroles.pm,v 1.324 2017/01/21 19:58:05 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -311,11 +311,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}); @@ -399,18 +397,9 @@ sub handler { # 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)) { + 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)) { @@ -566,7 +555,7 @@ ENDENTERKEY $env{'user.name'}, $env{'user.home'}, "Role ".$trolecode); - + &Apache::lonnet::appenv( {'request.role' => $trolecode, 'request.role.domain' => $cdom, @@ -575,6 +564,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); @@ -1047,7 +1045,7 @@ ENDHEADER 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') { @@ -1118,9 +1116,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)\./($match_domain)/$}) { + $output .= &adhoc_customroles_row($1,$2,'recent',$update,$then); } } elsif ($numdc > 0) { unless ($role =~/^error\:/) { @@ -1149,7 +1146,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; @@ -1226,6 +1223,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=''; @@ -1329,8 +1327,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]; } @@ -1507,7 +1524,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) { @@ -1531,9 +1548,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)\./($match_domain)/}) { + $output .= &adhoc_customroles_row($1,$2,'',$update,$then); } } } @@ -1817,8 +1833,11 @@ sub check_for_adhoc { $numdc++; } else { $dhroles->{$roledom} = $envkey; - if ($env{'environment.adhocroles.'.$roledom} ne '') { - $numadhoc ++; + my %domdefaults = &Apache::lonnet::get_domain_defaults($roledom); + if (ref($domdefaults{'adhocroles'}) eq 'HASH') { + if (keys(%{$domdefaults{'adhocroles'}})) { + $numadhoc ++; + } } $numdh++; } @@ -2042,20 +2061,25 @@ sub adhoc_roles_row { } sub adhoc_customroles_row { - my ($dhdom,$rowtype) = @_; - my $output = &Apache::loncommon::continue_data_table_row() - .'