--- loncom/interface/lonuserutils.pm 2017/11/16 17:05:49 1.184.2.2 +++ loncom/interface/lonuserutils.pm 2017/11/04 20:23:23 1.192 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.184.2.2 2017/11/16 17:05:49 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.192 2017/11/04 20:23:23 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -943,8 +943,14 @@ sub print_upload_manager_footer { &Apache::lonhtmlcommon::row_closure(); } + my ($trusted,$untrusted); + if ($context eq 'course') { + ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom); + } elsif ($context eq 'author') { + ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom); + } $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain')) - .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1) + .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trusted,$untrusted) .&Apache::lonhtmlcommon::row_closure(); $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates')) @@ -1126,11 +1132,6 @@ sub print_upload_manager_form { &Apache::loncommon::load_tmp_file($r,$datatoken); } } - if ($datatoken eq '') { - $r->print('

'.&mt('Error').': '. - &mt('Invalid datatoken').'

'); - return 'missingdata'; - } my @records=&Apache::loncommon::upfile_record_sep(); if($env{'form.noFirstLine'}){ $firstLine=shift(@records); @@ -1213,7 +1214,6 @@ sub print_upload_manager_form { } &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear, $context,$permission,$crstype,$showcredits); - return 'ok'; } sub setup_date_selectors { @@ -2344,7 +2344,8 @@ function setCourseCat(formname) { } courseSet('$codetitles[1]'); for (var j=0; jprint(''.&mt('Error').': '. + &mt('Enrollment of users not permitted for specified default domain: [_1].', + &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).''); + return; + } + } + } elsif ($context eq 'author') { + if ($env{'form.defaultdomain'} eq $defdom) { + $domain = $env{'form.defaultdomain'}; + } else { + if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) && + (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) { + $domain = $env{'form.defaultdomain'}; + } else { + $r->print(''.&mt('Error').': '. + &mt('Addition of users not permitted for specified default domain: [_1].', + &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).''); + return; + } + } + } elsif (($context eq 'domain') && ($setting eq 'domain')) { + if ($env{'form.defaultdomain'} eq $defdom) { + $domain = $env{'form.defaultdomain'}; + } else { + if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) { + $domain = $env{'form.defaultdomain'}; + } else { + $r->print(''.&mt('Error').': '. + &mt('Addition of users not permitted for specified default domain: [_1].', + &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).''); + return; + } + } + } } else { $domain = $defdom; } @@ -4176,10 +4219,9 @@ sub upfile_drop_add { } else { my %home_servers = &Apache::lonnet::get_servers($defdom,'library'); if (! exists($home_servers{$desiredhost})) { - $r->print('

'.&mt('Error').': '. - &mt('Invalid home server specified').'

'); - $r->print(&Apache::loncommon::end_page()); - return 'invalidhome'; + $r->print(''.&mt('Error').': '. + &mt('Invalid home server specified').''); + return; } } # Determine authentication mechanism @@ -4206,7 +4248,7 @@ sub upfile_drop_add { } if ($amode =~ /^krb/) { if (! defined($genpwd) || $genpwd eq '') { - $r->print(''. + $r->print(''.': '. &mt('Unable to enroll users').' '. &mt('No Kerberos domain was specified.').'

'); $amode = ''; # This causes the loop below to be skipped @@ -4279,11 +4321,6 @@ sub upfile_drop_add { } } } - if ($datatoken eq '') { - $r->print('

'.&mt('Error').': '. - &mt('Invalid datatoken').'

'); - return 'missingdata'; - } if ( $domain eq &LONCAPA::clean_domain($domain) && ($amode ne '')) { ####################################### @@ -4355,6 +4392,7 @@ sub upfile_drop_add { # Get new users list my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname); my $counter = -1; + my (%willtrust,%trustchecked); foreach my $line (@userdata) { $counter ++; my @secs; @@ -4402,6 +4440,28 @@ sub upfile_drop_add { '"'.$entries{$fields{'domain'}}.'"', $fname,$mname,$lname,$gen); next; + } elsif ($entries{$fields{'domain'}} ne $domain) { + my $possdom = $entries{$fields{'domain'}}; + if ($context eq 'course' || $setting eq 'course') { + unless ($trustchecked{$possdom}) { + $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom); + $trustchecked{$possdom} = 1; + } + } elsif ($context eq 'author') { + unless ($trustchecked{$possdom}) { + $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom); + } + if ($willtrust{$possdom}) { + $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain); + } + } + unless ($willtrust{$possdom}) { + $disallow{$counter} = + &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]', + '"'.$possdom.'"', + $fname,$mname,$lname,$gen); + next; + } } my $username = $entries{$fields{'username'}}; my $userdomain = $entries{$fields{'domain'}}; @@ -4874,7 +4934,6 @@ sub upfile_drop_add { } } } # end of unless - return 'ok'; } sub print_namespacing_alerts {