--- loncom/interface/loncreateuser.pm 2022/11/23 02:55:37 1.465 +++ loncom/interface/loncreateuser.pm 2023/08/01 15:56:32 1.469 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.465 2022/11/23 02:55:37 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.469 2023/08/01 15:56:32 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -3978,7 +3978,7 @@ sub update_roles { my $now=time; my @rolechanges; my (%disallowed,%got_role_approvals,%got_instdoms,%process_by,%instdoms, - %pending,%reject,%notifydc); + %pending,%reject,%notifydc,%status,%unauthorized,%currqueued); $got_role_approvals{$context} = ''; $process_by{$context} = {}; my @domroles = &Apache::lonuserutils::domain_roles(); @@ -4101,7 +4101,8 @@ sub update_roles { next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom, $uname,$role,$now,0,$cdom,$cnum,$csec,$credits, \%process_by,\%instdoms,\%got_role_approvals, - \%got_instdoms,\%reject,\%pending,\%notifydc)); + \%got_instdoms,\%reject,\%pending,\%notifydc, + \%status,\%unauthorized,\%currqueued)); } my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits); if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) { @@ -4131,7 +4132,7 @@ sub update_roles { next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom, $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by, \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject, - \%pending,\%notifydc)); + \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)); } } my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'}, @@ -4160,7 +4161,7 @@ sub update_roles { next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom, $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by, \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject, - \%pending,\%notifydc)); + \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)); } } my $result = &Apache::lonnet::assigncustomrole( @@ -4203,7 +4204,7 @@ sub update_roles { next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom, $uname,$role,$start,$end,$one,$two,'','',\%process_by, \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject, - \%pending,\%notifydc)); + \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)); } $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context)); } else { @@ -4223,7 +4224,7 @@ sub update_roles { next if (&Apache::lonuserutils::restricted_dom($context,$secid,$udom, $uname,$role,$start,$end,$one,$two,$sec,'',\%process_by, \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject, - \%pending,\%notifydc)); + \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)); } $numchanges ++; $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context)); @@ -4245,7 +4246,6 @@ sub update_roles { 0 ); my $url='/'.$one.'/'.$two; my $id = $url.'_'.$three; - my $type = 'three'; # split multiple sections my %sections = (); my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three); @@ -4266,7 +4266,7 @@ sub update_roles { next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom, $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by, \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject, - \%pending,\%notifydc)); + \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)); } $numchanges ++; $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits)); @@ -4290,7 +4290,7 @@ sub update_roles { $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom, $uname,$three,$start,$end,$one,$two,$sec,$credits,\%process_by, \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject, - \%pending,\%notifydc); + \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued); next if ($restricted); } $numchanges ++; @@ -4305,7 +4305,7 @@ sub update_roles { $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom, $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by, \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject, - \%pending,\%notifydc); + \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued); next if ($restricted); } $numchanges ++; @@ -4329,6 +4329,7 @@ sub update_roles { my $two = $2; my $url='/'.$one.'/'; my $id = $url.'_'.$two; + my ($cdom,$cnum) = split(/\//,$one); # split multiple sections my %sections = (); my ($restricted,$numchanges); @@ -4336,9 +4337,9 @@ sub update_roles { if ($num_sections == 0) { unless ($udom eq $one) { $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom, - $uname,$two,$start,$end,$one,$two,'','',\%process_by, + $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by, \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject, - \%pending,\%notifydc); + \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued); next if ($restricted); } $numchanges ++; @@ -4352,9 +4353,9 @@ sub update_roles { unless ($udom eq $one) { undef($restricted); $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom, - $uname,$two,$start,$end,$one,$two,$sec,'',\%process_by, + $uname,$two,$start,$end,$cdom,$cnum,$sec,'',\%process_by, \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject, - \%pending,\%notifydc); + \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued); next if ($restricted); } $numchanges ++; @@ -4367,9 +4368,9 @@ sub update_roles { unless ($udom eq $one) { undef($restricted); $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom, - $uname,$two,$start,$end,$one,$two,'','',\%process_by, + $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by, \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject, - \%pending,\%notifydc); + \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued); next if ($restricted); } $numchanges ++; @@ -4399,11 +4400,11 @@ sub update_roles { } } } # End of foreach (keys(%env)) - if (keys(%reject)) { - $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject)); + if ((keys(%reject)) || (keys(%unauthorized))) { + $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized)); } - if (keys(%pending)) { - $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc)); + if ((keys(%pending)) || (keys(%currqueued))) { + $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued)); } # Flush the course logs so reverse user roles immediately updated $r->register_cleanup(\&Apache::lonnet::flushcourselogs); @@ -4460,7 +4461,8 @@ sub enroll_single_student { } } my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form(); - my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,%pending,%reject,%notifydc); + my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,%pending,%reject,%notifydc, + %status,%unauthorized,%currqueued); unless ($env{'form.ccdomain'} eq $env{'course.'.$env{'request.course.id'}.'.domain'}) { my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; @@ -4473,12 +4475,12 @@ sub enroll_single_student { if (&Apache::lonuserutils::restricted_dom($context,$id,$env{'form.ccdomain'},$env{'form.ccuname'}, 'st',$startdate,$enddate,$cdom,$cnum,$csec,$credits, \%process_by,\%instdoms,\%got_role_approvals,\%got_instdoms, - \%reject,\%pending,\%notifydc)) { - if (keys(%reject)) { - $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject)); + \%reject,\%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)) { + if ((keys(%reject)) || (keys(%unauthorized))) { + $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized)); } - if (keys(%pending)) { - $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc)); + if ((keys(%pending)) || (keys(%currqueued))) { + $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued)); } return; } @@ -4918,7 +4920,7 @@ sub handler { if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) { push(@allhelp,'Course_Automated_Enrollment'); } - if ($permission->{'selfenrolladmin'}) { + if (($permission->{'selfenrolladmin'}) || ($permission->{'selfenrollview'})) { push(@allhelp,'Course_Approve_Selfenroll'); } } @@ -5458,8 +5460,9 @@ sub handler { ''.&mt('You do not have permission to modify dates or sections for users').''); } } elsif ($env{'form.action'} eq 'selfenroll') { - if ($permission->{selfenrolladmin}) { - my %currsettings = ( + my %currsettings; + if ($permission->{selfenrolladmin} || $permission->{selfenrollview}) { + %currsettings = ( selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'}, selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'}, selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'}, @@ -5475,6 +5478,8 @@ sub handler { default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'}, uniquecode => $env{'course.'.$cid.'.internal.uniquecode'}, ); + } + if ($permission->{selfenrolladmin}) { push(@{$brcrum}, {href => '/adm/createuser?action=selfenroll', text => "Configure Self-enrollment", @@ -5495,6 +5500,16 @@ sub handler { $r->print('

'.&mt('Self-enrollment with a student role').'

'."\n"); &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings); } + } elsif ($permission->{selfenrollview}) { + push(@{$brcrum}, + {href => '/adm/createuser?action=selfenroll', + text => "View Self-enrollment configuration", + help => 'Course_Self_Enrollment'}); + $args = { bread_crumbs => $brcrum, + bread_crumbs_component => 'Self-enrollment Settings'}; + $r->print(&header(undef,$args)); + $r->print('

'.&mt('Self-enrollment with a student role').'

'."\n"); + &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings,'',1); } else { $r->print(&header(undef,{'no_nav_bar' => 1}). ''.&mt('You do not have permission to configure self-enrollment').''); @@ -6026,7 +6041,7 @@ sub print_main_menu { icon => 'selfenrl-queue.png', #help => 'Course_Approve_Selfenroll', url => '/adm/createuser?action=selfenrollqueue', - permission => $permission->{'selfenrolladmin'}, + permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'}, linktitle =>'Approve or reject enrollment requests.', }, ); @@ -6053,7 +6068,7 @@ sub print_main_menu { icon => 'self_enroll.png', #help => 'Course_Self_Enrollment', url => '/adm/createuser?action=selfenroll', - permission => $permission->{'selfenrolladmin'}, + permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'}, linktitle => 'Configure user self-enrollment.', }, ); @@ -6324,8 +6339,7 @@ ENDSCRIPT '// ]]>'."\n". ''."\n". '

'.$lt->{'selfenroll'}.'

'."\n"; - - my $visactions = &cat_visibility(); + my $visactions = &cat_visibility($cdom); my ($cathash,%cattype); my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom); if (ref($domconfig{'coursecategories'}) eq 'HASH') { @@ -6871,6 +6885,7 @@ sub visible_in_stdcat { } sub cat_visibility { + my ($cdom) = @_; my %visactions = &Apache::lonlocal::texthash( vis => 'This course/community currently appears in the Course/Community Catalog for this domain.', gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.', @@ -6883,13 +6898,24 @@ sub cat_visibility { dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.', dc_setcode => 'Ask a domain coordinator to assign a six character code to the course', dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.', - dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".', + dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".', dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).', dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.', dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.', dc_chgcat => 'Ask a domain coordinator to change the category assigned to the course, as the one currently assigned is no longer used in the domain', dc_addcat => 'Ask a domain coordinator to assign a category to the course.', ); + if ($env{'request.role'} eq "dc./$cdom/") { + $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»'); + $visactions{'dc_setcode'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to assign a six character code to the course.','»'); + $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»'); + $visactions{'dc_addinst'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to enable catalog display of "Official courses (with institutional codes)".','»'); + $visactions{'dc_instcode'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify course owner, institutional code ... " to assign an institutional code (if this is an official course).','»'); + $visactions{'dc_catalog'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to enable or create at least one course category in the domain.','»'); + $visactions{'dc_categories'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to create a hierarchy of categories and sub categories for courses in the domain.','»'); + $visactions{'dc_chgcat'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify catalog settings for course" to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','»'); + $visactions{'dc_addcat'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify catalog settings for course" to assign a category to the course.','»'); + } $visactions{'unhide'} = &mt('Use [_1]Categorize course[_2] to change the "Exclude from course catalog" setting.','','"'); $visactions{'chgcat'} = &mt('Use [_1]Categorize course[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"','"'); $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"','"'); @@ -7068,12 +7094,13 @@ ENDSCRIPT chgcontext => 'any', rolelog_start_date => $defstart, rolelog_end_date => $now, + approvals => 'any', ); my $more_records = 0; # set current my %curr; - foreach my $item ('show','page','role','chgcontext') { + foreach my $item ('show','page','role','chgcontext','approvals') { $curr{$item} = $env{'form.'.$item}; } my ($startdate,$enddate) = @@ -7147,6 +7174,11 @@ ENDSCRIPT if (($context eq 'course') && ($viewablesec ne '')) { next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec); } + if ($curr{'approvals'} eq 'none') { + next if ($roleslog{$id}{'logentry'}{'approval'}); + } elsif ($curr{'approvals'} ne 'any') { + next if ($roleslog{$id}{'logentry'}{'approval'} ne $curr{'approvals'}); + } $count ++; next if ($count < $minshown); unless ($showntableheader) { @@ -7193,11 +7225,30 @@ ENDSCRIPT if ($chgcontext ne '' && $lt{$chgcontext} ne '') { $chgcontext = $lt{$chgcontext}; } + my ($showreqby,%reqby); + if (($roleslog{$id}{'logentry'}{'approval'}) && + ($roleslog{$id}{'logentry'}{'requester'})) { + if ($reqby{$roleslog{$id}{'logentry'}{'requester'}} eq '') { + my ($requname,$requdom) = split(/:/,$roleslog{$id}{'logentry'}{'requester'}); + $reqby{$roleslog{$id}{'logentry'}{'requester'}} = + &Apache::loncommon::plainname($requname,$requdom); + } + $showreqby = &mt('Requester').': '.$reqby{$roleslog{$id}{'logentry'}{'requester'}}.'
'; + if ($roleslog{$id}{'logentry'}{'approval'} eq 'domain') { + $showreqby .= &mt('Adjudicator').': '. + $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}. + ''; + } else { + $showreqby .= ''.&mt('User approved').''; + } + } else { + $showreqby = $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}; + } $r->print( &Apache::loncommon::start_data_table_row() .''.$count.'' .''.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'' - .''.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'' + .''.$showreqby.'' .''.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'' .''.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).''); if ($context eq 'course') { @@ -7551,7 +7602,7 @@ sub activity_display_filter { my $nolink = 1; my $output = ''; my $startform = @@ -7638,14 +7689,10 @@ sub userlogdisplay_navlinks { sub role_display_filter { my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_; - my $lctype; - if ($context eq 'course') { - $lctype = lc($crstype); - } my $nolink = 1; my $output = '
'. ''.&mt('Actions/page:').'
'. - &Apache::lonmeta::selectbox('show',$curr->{'show'},undef, + &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef, (&mt('all'),5,10,20,50,100,1000,10000)). '
  
'; my $startform = @@ -7669,7 +7716,7 @@ sub role_display_filter { if ($curr->{'role'} eq 'any') { $output .= ' selected="selected"'; } - $output .= '>'.&mt('Any').''."\n"; + $output .= '>'.&mt('Any').''."\n"; my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype); foreach my $role (@roles) { my $plrole; @@ -7690,7 +7737,7 @@ sub role_display_filter { &mt('Context:').'
' - .'
'. ''.&mt('Changes/page:').'
'. - &Apache::lonmeta::selectbox('show',$curr->{'show'},undef, + &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef, (&mt('all'),5,10,20,50,100,1000,10000)). '
  
'; + my @possapprovals = ('any','none','domain','user'); + my %apptxt = &approval_types(); + $output .= ''. + '  '. + ''. + &mt('Approvals:').'
'; # Update Display button $output .= '

' @@ -7746,6 +7805,7 @@ sub rolechg_contexts { domain => 'User Management in domain', selfenroll => 'Self-enrolled', requestcourses => 'Course Request', + ltienroll => 'Enrollment via LTI', ); if ($crstype eq 'Community') { $lt{'createcourse'} = &mt('Community Creation'); @@ -7770,6 +7830,15 @@ sub rolechg_contexts { return %lt; } +sub approval_types { + return &Apache::lonlocal::texthash ( + any => 'Any', + none => 'No approval needed', + user => 'Role recipient approval', + domain => 'Domain coordinator approval', + ); +} + sub print_helpdeskaccess_display { my ($r,$permission,$brcrum) = @_; my $formname = 'helpdeskaccess'; @@ -9906,7 +9975,7 @@ sub update_selfenroll_config { } else { $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.')); } - my $visactions = &cat_visibility(); + my $visactions = &cat_visibility($cdom); my ($cathash,%cattype); my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom); if (ref($domconfig{'coursecategories'}) eq 'HASH') {