Diff for /loncom/auth/lonroles.pm between versions 1.315 and 1.320

version 1.315, 2016/10/05 13:30:16 version 1.320, 2016/10/27 22:51:08
Line 255  sub handler { Line 255  sub handler {
   
     my $envkey;      my $envkey;
     my %dcroles = ();      my %dcroles = ();
     my $numdc = &check_fordc(\%dcroles,$update,$then);      my %dhroles = ();
       my ($numdc,$numdh,$numadhoc) = &check_for_adhoc(\%dcroles,\%dhroles,$update,$then);
     my $loncaparev = $r->dir_config('lonVersion');      my $loncaparev = $r->dir_config('lonVersion');
   
 # ================================================================== Roles Init  # ================================================================== Roles Init
Line 269  sub handler { Line 270  sub handler {
             $env{'form.'.$env{'form.newrole'}}=1;              $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 role trying to enter a course
             if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) {              if ($env{'form.newrole'} =~ m{^cr/($match_domain)/\1\-domainconfig/\w+\./\1/$match_courseid$}) {
                 if (&Apache::lonnet::allowed('rar',$1)) {                  if ($dhroles{$1}) {
                     $custom_adhoc = 1;                      $custom_adhoc = 1;
                 }                  }
             }              }
Line 316  sub handler { Line 317  sub handler {
                     if (grep(/^\Q$rolename\E$/,@adhoc)) {                      if (grep(/^\Q$rolename\E$/,@adhoc)) {
                         if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now,                          if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now,
                                                                "cr/$cdom/$cdom".'-domainconfig/'.$rolename)) {                                                                 "cr/$cdom/$cdom".'-domainconfig/'.$rolename)) {
                             &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig'."$rolename.adhoc" => time});                              &Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time});
                         }                          }
                     }                      }
                 }                  }
             }              }
         } elsif ($numdc > 0) {          } 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 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
             foreach my $envkey (keys(%env)) {              foreach my $envkey (keys(%env)) {
 # Is this an ad-hoc Coordinator role?  # Is this an ad-hoc Coordinator role?
                 if (my ($ccrole,$domain,$coursenum) =                  if ($numdc) {
     ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {                      if (my ($ccrole,$domain,$coursenum) =
                     if ($dcroles{$domain}) {          ($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
                         if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,                          if ($dcroles{$domain}) {
                                                            $update,$refresh,$now,$ccrole)) {                              if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
                             &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});                                                                     $update,$refresh,$now,$ccrole)) {
                         }                                  &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});
                     }                              }
                     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;  
                         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;                          last;
                     }                      }
                     if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {  # Is this an ad-hoc CA-role?
                         if (((($castart) && ($castart < $now)) || !$castart) &&                       if (my ($domain,$user) =
                             ((!$caend) || (($caend) && ($caend > $now)))) {          ($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);                              my ($server_status,$home) = &check_author_homeserver($user,$domain);
                             if ($server_status eq 'switchserver') {                              if ($server_status eq 'switchserver') {
                                 my $trolecode = 'ca./'.$domain.'/'.$user;                                  my $trolecode = 'au./'.$domain.'/';
                                 my $switchserver = '/adm/switchserver?otherserver='.$home.'&amp;role='.$trolecode;                                  my $switchserver = '/adm/switchserver?otherserver='.$home.'&amp;role='.$trolecode;
                                 $r->internal_redirect($switchserver);                                  $r->internal_redirect($switchserver);
                                 return OK;                                  return OK;
                             }                              }
                             last;                              last;
                         }                          }
                     }                          if (my ($castart,$caend) = ($env{'user.role.ca./'.$domain.'/'.$user} =~ /^(\d*)\.(\d*)$/)) {
                     # Check if author blocked ca-access                              if (((($castart) && ($castart < $now)) || !$castart) && 
                     my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);                                  ((!$caend) || (($caend) && ($caend > $now)))) {
                     if ($blocked{'domcoord.author'} eq 'blocked') {                                  my ($server_status,$home) = &check_author_homeserver($user,$domain);
                         delete($env{$envkey});                                  if ($server_status eq 'switchserver') {
                         $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';                                      my $trolecode = 'ca./'.$domain.'/'.$user;
                                       my $switchserver = '/adm/switchserver?otherserver='.$home.'&amp;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.'&amp;role='.$trolecode;
                                       $r->internal_redirect($switchserver);
                                       return OK;
                                   }
                               } else {
                                   delete($env{$envkey});
                               }
                           } else {
                               delete($env{$envkey});
                           }
                         last;                          last;
                     }                      }
                     if ($dcroles{$domain}) {                  }
                         my ($server_status,$home) = &check_author_homeserver($user,$domain);                  if ($numdh) {
                         if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {  # Is this an ad hoc custom role in a course/community?
                             &Apache::lonnet::check_adhoc_privs($domain,$user,$update,                      if (my ($domain,$rolename,$coursenum) = ($envkey =~ m{^form\.cr/($match_domain)/\1\-domainconfig/(\w+)\./\1/($match_courseid)$})) {
                                                                $refresh,$now,'ca');                          if ($dhroles{$domain}) { 
                             if ($server_status eq 'switchserver') {                              my @adhoc; 
                                 my $trolecode = 'ca./'.$domain.'/'.$user;                               if ($env{'environment.adhocroles.'.$domain}) {
                                 my $switchserver = '/adm/switchserver?'                                  @adhoc = split(',',$env{'environment.adhocroles.'.$domain});
                                                   .'otherserver='.$home.'&amp;role='.$trolecode;                              } else {
                                 $r->internal_redirect($switchserver);                                  my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
                                 return OK;                                                                                    '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});
                             }                              }
                         } else {                          } else {
                             delete($env{$envkey});                              delete($env{$envkey});
                         }                          }
                     } else {                          last;
                         delete($env{$envkey});  
                     }                      }
                     last;  
                 }                  }
             }              }
         }          }
   
         foreach $envkey (keys(%env)) {          foreach $envkey (keys(%env)) {
             next if ($envkey!~/^user\.role\./);              next if ($envkey!~/^user\.role\./);
             my ($where,$trolecode,$role,$tstatus,$tend,$tstart);              my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
Line 1044  ENDHEADER Line 1080  ENDHEADER
     }      }
 # ----------------------------------------------------------------------- Table  # ----------------------------------------------------------------------- Table
   
     if ($numdc > 0) {      if (($numdc > 0) || (($numdh > 0) && ($numadhoc > 0))) {
         $r->print(&coursepick_jscript());          $r->print(&coursepick_jscript());
         $r->print(&Apache::loncommon::coursebrowser_javascript().          $r->print(&Apache::loncommon::coursebrowser_javascript().
                   &Apache::loncommon::authorbrowser_javascript());                    &Apache::loncommon::authorbrowser_javascript());
Line 1077  ENDHEADER Line 1113  ENDHEADER
                                $roletext{'user.role.'.$role}->[1].                                 $roletext{'user.role.'.$role}->[1].
                                &Apache::loncommon::end_data_table_row();                                 &Apache::loncommon::end_data_table_row();
                 }                  }
                 if ($role =~ m{dc\./($match_domain)/}                   if ($role =~ m{^dc\./($match_domain)/$} 
     && $dcroles{$1}) {      && $dcroles{$1}) {
     $output .= &adhoc_roles_row($1,'recent');      $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) {      } elsif ($numdc > 0) {
                 unless ($role =~/^error\:/) {                  unless ($role =~/^error\:/) {
Line 1476  sub print_rolerows { Line 1515  sub print_rolerows {
                                            &Apache::loncommon::end_data_table_row();                                             &Apache::loncommon::end_data_table_row();
                             }                              }
                         }                          }
                         if ($sortrole->{$which} =~ m-dc\./($match_domain)/-) {                          if ($sortrole->{$which} =~ m{^user\.role\.dc\./($match_domain)/}) {
                             if (ref($dcroles) eq 'HASH') {                              if (ref($dcroles) eq 'HASH') {
                                 if ($dcroles->{$1}) {                                  if ($dcroles->{$1}) {
                                     $output .= &adhoc_roles_row($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,'');
                         }                          }
                     }                      }
                 }                  }
Line 1739  sub check_author_homeserver { Line 1781  sub check_author_homeserver {
     }      }
 }  }
   
 sub check_fordc {  sub check_for_adhoc {
     my ($dcroles,$update,$then) = @_;      my ($dcroles,$dhroles,$update,$then) = @_;
     my $numdc = 0;      my $numdc = 0;
       my $numdh = 0;
       my $numadhoc = 0;
       my $num_custom_adhoc = 0; 
     if ($env{'user.adv'}) {      if ($env{'user.adv'}) {
         foreach my $envkey (sort(keys(%env))) {          foreach my $envkey (sort(keys(%env))) {
             if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {              if ($envkey=~/^user\.role\.(dc|dh)\.\/($match_domain)\/$/) {
                 my $dcdom = $1;                  my $role = $1;
                 my $livedc = 1;                  my $roledom = $2;
                   my $liverole = 1;
                 my ($tstart,$tend)=split(/\./,$env{$envkey});                  my ($tstart,$tend)=split(/\./,$env{$envkey});
                 my $limit = $update;                  my $limit = $update;
                 if ($env{'request.role'} eq 'dc./'.$dcdom.'/') {                  if ((($role eq 'dc') && ($env{'request.role'} eq 'dc./'.$roledom.'/')) ||
                       (($role eq 'dh') && ($env{'request.role'} eq 'dh./'.$roledom.'/'))) {
                     $limit = $then;                      $limit = $then;
                 }                  }
                 if ($tstart && $tstart>$limit) { $livedc = 0; }                  if ($tstart && $tstart>$limit) { $liverole = 0; }
                 if ($tend   && $tend  <$limit) { $livedc = 0; }                  if ($tend   && $tend  <$limit) { $liverole = 0; }
                 if ($livedc) {                  if ($liverole) {
                     $$dcroles{$dcdom} = $envkey;                      if ($role eq 'dc') {
                     $numdc++;                          $dcroles->{$roledom} = $envkey;
                           $numdc++;
                       } else {
                           $dhroles->{$roledom} = $envkey;
                           if ($env{'environment.adhocroles.'.$roledom} ne '') {
                               $numadhoc ++;
                           }
                           $numdh++;
                       }
                 }                  }
             }              }
         }          }
     }      }
     return $numdc;      return ($numdc,$numdh,$numadhoc);
 }  }
   
 sub adhoc_course_role {  sub adhoc_course_role {
Line 1853  sub check_forcc { Line 1908  sub check_forcc {
 }  }
   
 sub courselink {  sub courselink {
     my ($dcdom,$rowtype) = @_;      my ($roledom,$rowtype,$role) = @_;
     my $courseform=&Apache::loncommon::selectcourse_link      my $courseform=&Apache::loncommon::selectcourse_link
                    ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,                     ('rolechoice','course'.$rowtype.'_'.$roledom.'_'.$role,
                     'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.                      'domain'.$rowtype.'_'.$roledom.'_'.$role,
                     $dcdom,$dcdom,undef,'Course/Community');                      'coursedesc'.$rowtype.'_'.$roledom.'_'.$role,
     my $hiddenitems = '<input type="hidden" name="dcdomain'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.                      $roledom.':'.$role,undef,'Course/Community');
                       '<input type="hidden" name="origdom'.$rowtype.'_'.$dcdom.'" value="'.$dcdom.'" />'.      my $hiddenitems = '<input type="hidden" name="domain'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
                       '<input type="hidden" name="dccourse'.$rowtype.'_'.$dcdom.'" value="" />'.                        '<input type="hidden" name="origdom'.$rowtype.'_'.$roledom.'_'.$role.'" value="'.$roledom.'" />'.
                       '<input type="hidden" name="coursedesc'.$rowtype.'_'.$dcdom.'" value="" />';                        '<input type="hidden" name="course'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />'.
                         '<input type="hidden" name="coursedesc'.$rowtype.'_'.$roledom.'_'.$role.'" value="" />';
     return $courseform.$hiddenitems;      return $courseform.$hiddenitems;
 }  }
   
Line 1958  sub adhoc_roles_row { Line 2014  sub adhoc_roles_row {
                  .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'                   .&mt('[_1]Ad hoc[_2] roles in domain [_3] --'
                      ,'<span class="LC_cusr_emph">','</span>',$dcdom)                       ,'<span class="LC_cusr_emph">','</span>',$dcdom)
                  .' ';                   .' ';
     my $selectcclink = &courselink($dcdom,$rowtype);      my $role = 'cc';
       my $selectcclink = &courselink($dcdom,$rowtype,$role);
     my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);      my $ccrole = &Apache::lonnet::plaintext('co',undef,undef,1);
     my $carole = &Apache::lonnet::plaintext('ca');      my $carole = &Apache::lonnet::plaintext('ca');
     my $selectcalink = &coauthorlink($dcdom,$rowtype);      my $selectcalink = &coauthorlink($dcdom,$rowtype);
Line 1968  sub adhoc_roles_row { Line 2025  sub adhoc_roles_row {
     return $output;      return $output;
 }  }
   
   sub adhoc_customroles_row {
       my ($dhdom,$rowtype) = @_;
       my $output = &Apache::loncommon::continue_data_table_row()
                    .' <td colspan="5" class="LC_textsize_mobile">'
                    .&mt('[_1]Ad hoc[_2] course/community roles in domain [_3] --',
                         '<span class="LC_cusr_emph">','</span>',$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;
       }
       return;
   }
   
 sub recent_filename {  sub recent_filename {
     my $area=shift;      my $area=shift;
     return 'nohist_recent_'.&escape($area);      return 'nohist_recent_'.&escape($area);

Removed from v.1.315  
changed lines
  Added in v.1.320


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>