Diff for /loncom/interface/lonuserutils.pm between versions 1.189 and 1.195

version 1.189, 2017/08/11 18:58:16 version 1.195, 2019/04/29 22:19:24
Line 546  END Line 546  END
             case 'fsys':              case 'fsys':
                 alertmsg = '';                  alertmsg = '';
                 break;                  break;
               case 'lti':
             default:              default:
                 alertmsg = '';                  alertmsg = '';
         }          }
Line 898  sub print_upload_manager_footer { Line 899  sub print_upload_manager_footer {
     my $krbform = &Apache::loncommon::authform_kerberos(%param);      my $krbform = &Apache::loncommon::authform_kerberos(%param);
     my $intform = &Apache::loncommon::authform_internal(%param);      my $intform = &Apache::loncommon::authform_internal(%param);
     my $locform = &Apache::loncommon::authform_local(%param);      my $locform = &Apache::loncommon::authform_local(%param);
       my $ltiform = &Apache::loncommon::authform_lti(%param);
     my $date_table = &date_setting_table(undef,undef,$context,undef,      my $date_table = &date_setting_table(undef,undef,$context,undef,
                                          $formname,$permission,$crstype);                                           $formname,$permission,$crstype);
   
Line 926  sub print_upload_manager_footer { Line 928  sub print_upload_manager_footer {
             &Apache::loncommon::help_open_topic('Auth_Options').              &Apache::loncommon::help_open_topic('Auth_Options').
             "</p>\n";              "</p>\n";
     }      }
     $Str .= &set_login($defdom,$krbform,$intform,$locform);      $Str .= &set_login($defdom,$krbform,$intform,$locform,$ltiform);
   
     my ($home_server_pick,$numlib) =      my ($home_server_pick,$numlib) =
         &Apache::loncommon::home_server_form_item($defdom,'lcserver',          &Apache::loncommon::home_server_form_item($defdom,'lcserver',
Line 1132  sub print_upload_manager_form { Line 1134  sub print_upload_manager_form {
             &Apache::loncommon::load_tmp_file($r,$datatoken);              &Apache::loncommon::load_tmp_file($r,$datatoken);
         }          }
     }      }
       if ($datatoken eq '') {
           $r->print('<p class="LC_error">'.&mt('Error').': '.
                     &mt('Invalid datatoken').'</p>');
           return 'missingdata';
       }
     my @records=&Apache::loncommon::upfile_record_sep();      my @records=&Apache::loncommon::upfile_record_sep();
     if($env{'form.noFirstLine'}){      if($env{'form.noFirstLine'}){
         $firstLine=shift(@records);          $firstLine=shift(@records);
Line 1214  sub print_upload_manager_form { Line 1221  sub print_upload_manager_form {
     }      }
     &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,      &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
                                  $context,$permission,$crstype,$showcredits);                                   $context,$permission,$crstype,$showcredits);
       return 'ok';
 }  }
   
 sub setup_date_selectors {  sub setup_date_selectors {
Line 4133  sub upfile_drop_add { Line 4141  sub upfile_drop_add {
             $fields{$env{'form.f'.$i}}=$keyfields[$i];              $fields{$env{'form.f'.$i}}=$keyfields[$i];
         }          }
     }      }
     if ($env{'form.fullup'} ne 'yes') {  
         $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".  
                   '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');  
     }  
     #      #
     # Store the field choices away      # Store the field choices away
     my @storefields = qw/username names fname mname lname gen id       my @storefields = qw/username names fname mname lname gen id 
Line 4174  sub upfile_drop_add { Line 4178  sub upfile_drop_add {
     my $domain;      my $domain;
     if ($env{'form.defaultdomain'} ne '') {      if ($env{'form.defaultdomain'} ne '') {
         if (($context eq 'course') || ($setting eq 'course')) {          if (($context eq 'course') || ($setting eq 'course')) {
             unless ($env{'form.defaultdomain'} eq $crsdom) {              if ($env{'form.defaultdomain'} eq $crsdom) {
                   $domain = $env{'form.defaultdomain'};
               } else {
                 if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {                  if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
                     $domain = $env{'form.defaultdomain'};                      $domain = $env{'form.defaultdomain'};
                 } else {                  } else {
                     $r->print('<span class="LC_error">'.&mt('Error').                      $r->print('<span class="LC_error">'.&mt('Error').': '.
                               &mt('Enrollment of users not permitted for specified default domain: [_1].',                                &mt('Enrollment of users not permitted for specified default domain: [_1].',
                                   &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');                                    &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
                     $r->print(&Apache::loncommon::end_page());                      return 'untrusted';
                 }                  }
                 return;  
             }              }
         } elsif ($context eq 'author') {          } elsif ($context eq 'author') {
             unless ($env{'form.defaultdomain'} eq $defdom) {              if ($env{'form.defaultdomain'} eq $defdom) {
                   $domain = $env{'form.defaultdomain'}; 
               } else {
                 if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&                  if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
                     (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {                      (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
                     $domain = $env{'form.defaultdomain'};                      $domain = $env{'form.defaultdomain'};
                 } else {                  } else {
                     $r->print('<span class="LC_error">'.&mt('Error').                      $r->print('<span class="LC_error">'.&mt('Error').': '.
                               &mt('Addition of users not permitted for specified default domain: [_1].',                                &mt('Addition of users not permitted for specified default domain: [_1].',
                                   &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');                                    &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
                     $r->print(&Apache::loncommon::end_page());                      return 'untrusted';
                 }                  }
                 return;   
             }              }
         } elsif (($context eq 'domain') && ($setting eq 'domain')) {          } elsif (($context eq 'domain') && ($setting eq 'domain')) {
             unless ($env{'form.defaultdomain'} eq $defdom) {              if ($env{'form.defaultdomain'} eq $defdom) {
                   $domain = $env{'form.defaultdomain'};
               } else {
                 if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {                  if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
                     $domain = $env{'form.defaultdomain'};                      $domain = $env{'form.defaultdomain'};
                 } else {                  } else {
                     $r->print('<span class="LC_error">'.&mt('Error').                      $r->print('<span class="LC_error">'.&mt('Error').': '.
                               &mt('Addition of users not permitted for specified default domain: [_1].',                                &mt('Addition of users not permitted for specified default domain: [_1].',
                                   &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');                                    &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
                     $r->print(&Apache::loncommon::end_page());                      return 'untrusted';
                 }                  }
             }              }
         }          }
Line 4219  sub upfile_drop_add { Line 4227  sub upfile_drop_add {
     } else {      } else {
         my %home_servers = &Apache::lonnet::get_servers($defdom,'library');          my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
         if (! exists($home_servers{$desiredhost})) {          if (! exists($home_servers{$desiredhost})) {
             $r->print('<span class="LC_error">'.&mt('Error').              $r->print('<p class="LC_error">'.&mt('Error').': '.
                       &mt('Invalid home server specified').'</span>');                        &mt('Invalid home server specified').'</p>');
             $r->print(&Apache::loncommon::end_page());              return 'invalidhome';
             return;  
         }          }
     }      }
     # Determine authentication mechanism      # Determine authentication mechanism
Line 4246  sub upfile_drop_add { Line 4253  sub upfile_drop_add {
         if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {          if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
             $genpwd=$env{'form.locarg'};              $genpwd=$env{'form.locarg'};
         }          }
       } elsif ($env{'form.login'} eq 'lti') {
           $amode='lti';
     }      }
     if ($amode =~ /^krb/) {      if ($amode =~ /^krb/) {
         if (! defined($genpwd) || $genpwd eq '') {          if (! defined($genpwd) || $genpwd eq '') {
Line 4322  sub upfile_drop_add { Line 4331  sub upfile_drop_add {
             }              }
         }          }
     }      }
       if ($datatoken eq '') {
           $r->print('<p class="LC_error">'.&mt('Error').': '.
                     &mt('Invalid datatoken').'</p>');
           return 'missingdata';
       }
     if ( $domain eq &LONCAPA::clean_domain($domain)      if ( $domain eq &LONCAPA::clean_domain($domain)
         && ($amode ne '')) {          && ($amode ne '')) {
         #######################################          #######################################
Line 4615  sub upfile_drop_add { Line 4629  sub upfile_drop_add {
                                 &mt('The user does not already exist, and you may not create a new user in a different domain.');                                  &mt('The user does not already exist, and you may not create a new user in a different domain.');
                             next;                              next;
                         } else {                          } else {
                             unless ($password || $env{'form.login'} eq 'loc') {                              unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
                                 $disallow{$counter} =                                  $disallow{$counter} =
                                     &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',                                      &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
                                         '<b>'.$username.'</b>');                                          '<b>'.$username.'</b>');
Line 4897  sub upfile_drop_add { Line 4911  sub upfile_drop_add {
                   "</p>\n");                    "</p>\n");
         if ($counts{'role'} > 0) {          if ($counts{'role'} > 0) {
             $r->print("<p>\n".              $r->print("<p>\n".
                       &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.&mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.')."</p>\n");                        &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.
                         &mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.').
                         "</p>\n");
         } else {          } else {
             $r->print('<p>'.&mt('No roles added').'</p>');              $r->print('<p>'.&mt('No roles added').'</p>');
         }          }
Line 4915  sub upfile_drop_add { Line 4931  sub upfile_drop_add {
             #  Get current classlist              #  Get current classlist
             my $classlist = &Apache::loncoursedata::get_classlist();              my $classlist = &Apache::loncoursedata::get_classlist();
             if (! defined($classlist)) {              if (! defined($classlist)) {
                 $r->print('<form name="studentform" method="post" action="/adm/createuser">'.                  $r->print('<p class="LC_info">'.
                           '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.                            &mt('There are no students with current/future access to the course.').
                           '<p class="LC_info">'.&mt('There are no students with current/future access to the course.').'</p>'.                            '</p>'."\n");
                           '</form>'."\n");  
             } elsif (ref($classlist) eq 'HASH') {              } elsif (ref($classlist) eq 'HASH') {
                 # Remove the students we just added from the list of students.                  # Remove the students we just added from the list of students.
                 foreach my $line (@userdata) {                  foreach my $line (@userdata) {
Line 4934  sub upfile_drop_add { Line 4949  sub upfile_drop_add {
             }              }
         }          }
     } # end of unless      } # end of unless
     if ($env{'form.fullup'} ne 'yes') {      return 'ok';
         $r->print('</form>');  
     }  
 }  }
   
 sub print_namespacing_alerts {  sub print_namespacing_alerts {
Line 5482  END Line 5495  END
 }  }
   
 sub set_login {  sub set_login {
     my ($dom,$authformkrb,$authformint,$authformloc) = @_;      my ($dom,$authformkrb,$authformint,$authformloc,$authformlti) = @_;
     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);      my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
     my $response;      my $response;
     my ($authnum,%can_assign) =      my ($authnum,%can_assign) =
Line 5504  sub set_login { Line 5517  sub set_login {
                          '<td>'.$authformloc.'</td>'.                           '<td>'.$authformloc.'</td>'.
                          &Apache::loncommon::end_data_table_row()."\n";                           &Apache::loncommon::end_data_table_row()."\n";
         }          }
           if ($can_assign{'lti'}) {
               $response .= &Apache::loncommon::start_data_table_row().
                            '<td>'.$authformlti.'</td>'.
                            &Apache::loncommon::end_data_table_row()."\n";
           }
         $response .= &Apache::loncommon::end_data_table();          $response .= &Apache::loncommon::end_data_table();
     }      }
     return $response;      return $response;
Line 5848  sub can_modify_userinfo { Line 5866  sub can_modify_userinfo {
     return %canmodify;      return %canmodify;
 }  }
   
   sub can_change_internalpass {
       my ($uname,$udom,$crstype,$permission) = @_;
       my $canchange;
       if (&Apache::lonnet::allowed('mau',$udom)) {
           $canchange = 1;
       } elsif ((ref($permission) eq 'HASH') && ($permission->{'mip'}) &&
                ($udom eq $env{'request.role.domain'})) {
           unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
               my ($cnum,$cdom) = &get_course_identity();
               if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
                   my $noupdate;
                   my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
                                                             $env{'user.name'}.':'.$env{'user.domain'},
                                                             undef,undef,undef,'.');
                   my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                                                                 ['active','future']);
                   foreach my $key (keys(%roleshash)) {
                       my ($name,$domain,$role) = split(/:/,$key);
                       if ($role eq 'st') {
                           next if (($name eq $cnum) && ($domain eq $cdom));
                           if ($owned{$domain.'_'.$name}) {
                               if (ref($owned{$domain.'_'.$name}) eq 'HASH') {
                                   if ($owned{$domain.'_'.$name}{'nopasswdchg'}) {
                                       $noupdate = 1;
                                       last;
                                   }
                               }
                           } else {
                               $noupdate = 1;
                               last;
                           }
                       } else {
                           $noupdate = 1;
                           last;
                       }
                   }
                   unless ($noupdate) {
                       $canchange = 1;
                   }
               }
           }
       }
       return $canchange;
   }
   
 sub check_usertype {  sub check_usertype {
     my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;      my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
     my $usertype;      my $usertype;
Line 5970  sub get_permission { Line 6033  sub get_permission {
             }              }
         }          }
         if ($env{'request.course.id'}) {          if ($env{'request.course.id'}) {
             my $user = $env{'user.name'}.':'.$env{'user.domain'};              my $user;
               if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
                   $user = $env{'user.name'}.':'.$env{'user.domain'};
               }
             if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq              if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
                                   $user)) {                                    $user)) {
                 $permission{'owner'} = 1;                  $permission{'owner'} = 1;
                   if (&Apache::lonnet::allowed('mip',$env{'request.course.id'})) {
                       $permission{'mip'} = 1;
                   }
             } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {              } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {
                 if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {                  if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {
                     $permission{'co-owner'} = 1;                      $permission{'co-owner'} = 1;

Removed from v.1.189  
changed lines
  Added in v.1.195


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