--- loncom/interface/lonuserutils.pm 2020/10/15 13:47:45 1.183.2.1
+++ loncom/interface/lonuserutils.pm 2024/08/24 23:49:48 1.184.4.10.2.8
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.183.2.1 2020/10/15 13:47:45 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.184.4.10.2.8 2024/08/24 23:49:48 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -103,7 +103,7 @@ sub modifystudent {
sub modifyuserrole {
my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
$first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
- $end,$start,$checkid,$inststatus) = @_;
+ $end,$start,$checkid,$inststatus,$emptyok) = @_;
my ($scope,$userresult,$authresult,$roleresult,$idresult);
if ($setting eq 'course' || $context eq 'course') {
$scope = '/'.$cid;
@@ -114,7 +114,11 @@ sub modifyuserrole {
} elsif ($context eq 'domain') {
$scope = '/'.$env{'request.role.domain'}.'/';
} elsif ($context eq 'author') {
- $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
+ if ($env{'request.role'} =~ m{^ca\.(/$match_domain/$match_username)$}) {
+ $scope = $1;
+ } else {
+ $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
+ }
}
if ($context eq 'domain') {
my $uhome = &Apache::lonnet::homeserver($uname,$udom);
@@ -134,6 +138,25 @@ sub modifyuserrole {
generation => $gene,
id => $uid,
);
+
+ # When "Update ID in user's course(s)" and "Force change of existing ID"
+ # checkboxes both checked, prevent replacement of name information
+ # in classlist.db file(s) for the user's course(s) with blank(s),
+ # in the case where the uploaded csv file was without column(s) for
+ # the particular field. Fields are: First Name, Middle Names/Initials,
+ # Last Name (or the composite: Last Name, First Names), and Generation.
+
+ my %emptyallowed;
+ if ((ref($emptyok) eq 'HASH') && (keys(%{$emptyok}) > 0)) {
+ %emptyallowed = %{$emptyok};
+ }
+ foreach my $field (keys(%userupdate)) {
+ if ($userupdate{$field} eq '') {
+ unless ($emptyallowed{$field}) {
+ delete($userupdate{$field});
+ }
+ }
+ }
$idresult = &propagate_id_change($uname,$udom,\%userupdate);
}
}
@@ -438,7 +461,7 @@ sub javascript_validations {
} elsif ($context eq 'domain') {
$setsection_call = 'setCourse()';
$setsections_js = &dc_setcourse_js($param{'formname'},$mode,
- $context,$showcredits);
+ $context,$showcredits,$domain);
}
$finish = " var checkSec = $setsection_call\n".
" if (checkSec == 'ok') {\n".
@@ -510,7 +533,7 @@ END
";
} elsif ($mode eq 'modifycourse') {
$auth_checks .= "
- if (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '') {
+ if ((current.argfield !== null) && (current.argfield !== undefined) && (current.argfield !== '') && (vf.elements[current.argfield].value == null || vf.elements[current.argfield].value == '')) {
";
}
if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
@@ -531,19 +554,25 @@ END
/* regexp here to check for non \d \. in credits */
END
} else {
+ my ($numrules,$intargjs) =
+ &Apache::loncommon::passwd_validation_js('vf.elements[current.argfield].value',$domain);
$auth_checks .= (< '.&mt('Error').': '.
+ &mt('Invalid datatoken').' '
- .''
.'
'.
@@ -1722,12 +1790,31 @@ sub print_userlist {
} else {
my (%cstr_roles,%dom_roles);
if ($context eq 'author') {
- # List co-authors and assistant co-authors
my @possroles = &roles_by_context($context);
- %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
- \@statuses,\@possroles);
- &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
- \%cstr_roles,$permission);
+ my @allowedroles;
+ # List co-authors and assistant co-authors
+ my ($auname,$audom);
+ if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
+ ($audom,$auname) = ($1,$2);
+ foreach my $role (@possroles) {
+ if ((&Apache::lonnet::allowed('v'.$role,"$audom/$auname")) ||
+ (&Apache::lonnet::allowed('c'.$role,"$audom/$auname"))) {
+ push(@allowedroles,$role);
+ }
+ }
+ } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
+ if ($1 eq $env{'user.domain'}) {
+ $auname = $env{'user.name'};
+ $audom = $env{'user.domain'};
+ }
+ @allowedroles = @possroles;
+ }
+ if (($auname ne '') && ($audom ne '')) {
+ %cstr_roles = &Apache::lonnet::get_my_roles($auname,$audom,undef,
+ \@statuses,\@allowedroles);
+ &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
+ \%cstr_roles,$permission);
+ }
} elsif ($context eq 'domain') {
if ($env{'form.roletype'} eq 'domain') {
if (grep(/^authorusage$/,@cols)) {
@@ -2018,14 +2105,17 @@ sub get_cols_array {
push(@cols,'photo');
}
if ($context eq 'domain') {
- push (@cols,('authorusage','authorquota','extent'));
+ push(@cols,('authorusage','authorquota','extent'));
+ }
+ if ($context eq 'author') {
+ push(@cols,'manager');
}
}
return @cols;
}
sub column_checkboxes {
- my ($context,$mode,$formname,$showcredits) = @_;
+ my ($context,$mode,$formname,$showcredits,$showstart,$showend) = @_;
my @cols = &get_cols_array($context,$mode,$showcredits);
my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
my (%disabledchk,%unchecked);
@@ -2038,11 +2128,21 @@ sub column_checkboxes {
if ($showcredits) {
$unchecked{'credits'} = 1;
}
- } elsif ($context eq 'domain') {
+ my %curr_groups = &Apache::longroup::coursegroups();
+ unless (keys(%curr_groups)) {
+ $unchecked{'groups'} = 1;
+ }
+ } elsif ($context eq 'domain') {
$unchecked{'extent'} = 1;
}
- $unchecked{'start'} = 1;
- $unchecked{'end'} = 1;
+ if ($showstart) {
+ $unchecked{'lastlogin'} = 1;
+ } else {
+ $unchecked{'start'} = 1;
+ }
+ unless ($showend) {
+ $unchecked{'end'} = 1;
+ }
} else {
if ($env{'form.Status'} ne 'Any') {
$disabledchk{'status'} = 1;
@@ -2059,6 +2159,11 @@ sub column_checkboxes {
} elsif ($env{'form.roletype'} eq 'domain') {
$disabledchk{'extent'} = 1;
}
+ } elsif ($context eq 'author') {
+ if (($env{'form.Status'} eq 'Expired') ||
+ ($env{'form.showrole'} eq 'aa')) {
+ $disabledchk{'manager'} = 1;
+ }
}
}
my $numposs = scalar(@cols);
@@ -2150,6 +2255,7 @@ sub get_column_names {
'ca' => "check all",
'ua' => "uncheck all",
'clicker' => "clicker-ID",
+ 'manager' => "co-author manager",
);
if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
$lt{'extent'} = &mt('course(s): description, section(s), status');
@@ -2279,7 +2385,6 @@ sub build_user_record {
sub courses_selector {
my ($cdom,$formname) = @_;
- my %coursecodes = ();
my %codes = ();
my @codetitles = ();
my %cat_titles = ();
@@ -2292,14 +2397,15 @@ sub courses_selector {
my $jscript = '';
my $totcodes = 0;
- $totcodes =
- &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,
- $cdom,$totcodes);
- if ($totcodes > 0) {
- $format_reply =
- &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
- \%codes,\@codetitles,\%cat_titles,\%cat_order);
- if ($format_reply eq 'ok') {
+ my $instcats = &Apache::lonnet::get_dom_instcats($cdom);
+ if (ref($instcats) eq 'HASH') {
+ if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
+ (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
+ %codes = %{$instcats->{'codes'}};
+ @codetitles = @{$instcats->{'codetitles'}};
+ %cat_titles = %{$instcats->{'cat_titles'}};
+ %cat_order = %{$instcats->{'cat_order'}};
+ $totcodes = scalar(keys(%codes));
my $numtypes = @codetitles;
&Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
@@ -2336,7 +2442,8 @@ function setCourseCat(formname) {
}
courseSet('$codetitles[1]');
for (var j=0; j
'."\n".
+ $output .= "\n".''."\n".
&Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row();
if ($mode eq 'autoenroll') {
@@ -2824,6 +2935,7 @@ END
foreach my $idx (@$keylist) {
$index{$idx} = $i++;
}
+ my $now = time;
my $usercount = 0;
my ($secfilter,$grpfilter);
if ($context eq 'course') {
@@ -2841,10 +2953,12 @@ END
Future => 'Future',
Expired => 'Expired',
);
- # If this is for a single course get last course "log-in".
- my %crslogins;
+ my (%crslogins,%camanagers);
if ($context eq 'course') {
+ # If this is for a single course get last course "log-in".
%crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
+ } elsif ($context eq 'author') {
+ map { $camanagers{$_.':ca'} = 1; } split(/,/,$env{'environment.authormanagers'});
}
# Get groups, role, permanent e-mail so we can sort on them if
# necessary.
@@ -2944,6 +3058,16 @@ END
}
}
}
+ if ($context eq 'author') {
+ if (($camanagers{$user}) &&
+ ((!defined($userlist->{$user}->[$index{'end'}])) ||
+ ($userlist->{$user}->[$index{'end'}] == 0) ||
+ ($userlist->{$user}->[$index{'end'}] > $now))) {
+ $userlist->{$user}->[$index{'manager'}] = &mt('Yes');
+ } else {
+ $userlist->{$user}->[$index{'manager'}] = &mt('No');
+ }
+ }
my %emails = &Apache::loncommon::getemails($uname,$udom);
if ($emails{'permanentemail'} =~ /\S/) {
$userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
@@ -3512,6 +3636,8 @@ END
setSections(formname,'$crstype');
if (seccheck == 'ok') {
opener.document.$callingform.newsecs.value = formname.sections.value;
+ } else {
+ return;
}
END
} else {
@@ -4096,7 +4222,7 @@ sub print_first_users_upload_form {
.&Apache::lonhtmlcommon::end_pick_box();
$str .= '
\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.')."
\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.'). + "\n"); } else { $r->print(''.&mt('No roles added').'
'); } @@ -4834,6 +5043,7 @@ sub upfile_drop_add { $counts{'auth'})."\n"); } $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules)); + $r->print(&passwdrule_alerts($domain,\%showpasswdrules)); ##################################### # Display list of students to drop # ##################################### @@ -4842,10 +5052,9 @@ sub upfile_drop_add { # Get current classlist my $classlist = &Apache::loncoursedata::get_classlist(); if (! defined($classlist)) { - $r->print(''."\n"); + $r->print(''. + &mt('There are no students with current/future access to the course.'). + '
'."\n"); } elsif (ref($classlist) eq 'HASH') { # Remove the students we just added from the list of students. foreach my $line (@userdata) { @@ -4861,9 +5070,7 @@ sub upfile_drop_add { } } } # end of unless - if ($env{'form.fullup'} ne 'yes') { - $r->print(''); - } + return 'ok'; } sub print_namespacing_alerts { @@ -4906,6 +5113,42 @@ sub print_namespacing_alerts { } } +sub passwdrule_alerts { + my ($domain,$passwdrules) = @_; + my $warning; + if (ref($passwdrules) eq 'HASH') { + my %showrules = %{$passwdrules}; + if (keys(%showrules)) { + my %passwdconf = &Apache::lonnet::get_passwdconf($domain); + $warning = ''.&mt('Password requirement(s) unmet for one or more users:').'