--- loncom/interface/lonmodifycourse.pm 2019/04/29 22:19:24 1.94
+++ loncom/interface/lonmodifycourse.pm 2023/06/05 02:22:29 1.100
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# handler for DC-only modifiable course settings
#
-# $Id: lonmodifycourse.pm,v 1.94 2019/04/29 22:19:24 raeburn Exp $
+# $Id: lonmodifycourse.pm,v 1.100 2023/06/05 02:22:29 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -39,6 +39,9 @@ use Apache::lonpickcourse;
use lib '/home/httpd/lib/perl';
use LONCAPA qw(:DEFAULT :match);
+my $registered_cleanup;
+my $modified_dom;
+
sub get_dc_settable {
my ($type,$cdom) = @_;
if ($type eq 'Community') {
@@ -427,6 +430,8 @@ sub print_modification_menu {
'setanon' => 'View/Modify responders threshold for anonymous survey submissions display',
'selfenroll' => 'View/Modify Self-Enrollment configuration',
'setpostsubmit' => 'View/Modify submit button behavior, post-submission',
+ 'setltiauth' => 'View/Modify re-authentication requirement for LTI launch of deep-linked item',
+ 'setexttool' => 'View/Modify External Tools permissions',
);
} else {
%linktext = (
@@ -434,6 +439,8 @@ sub print_modification_menu {
'setanon' => 'View responders threshold for anonymous survey submissions display',
'selfenroll' => 'View Self-Enrollment configuration',
'setpostsubmit' => 'View submit button behavior, post-submission',
+ 'setltiauth' => 'View re-authentication requirement for LTI launch of deep-linked item',
+ 'setexttool' => 'View External Tools permissions',
);
}
if ($type eq 'Community') {
@@ -472,6 +479,8 @@ sub print_modification_menu {
my $anon_text = &mt('Responder threshold required to display anonymous survey submissions.');
my $postsubmit_text = &mt('Override defaults for submit button behavior post-submission for this specific course.');
my $mysqltables_text = &mt('Override default for lifetime of "temporary" MySQL tables containing student performance data.');
+ my $ltiauth_text = &mt('Override default for requirement for re-authentication for LTI-limited launch of deep-linked item.');
+ my $exttool_text = &mt('Override default permissions for external tools use for this specific course.');
$linktext{'viewparms'} = 'Display current settings for automated enrollment';
my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
@@ -553,6 +562,22 @@ sub print_modification_menu {
permission => $permission->{'setpostsubmit'},
linktitle => '',
},
+ {
+ linktext => $linktext{'setltiauth'},
+ icon => 'system-lock-screen.png',
+ #help => '',
+ url => &phaseurl('setltiauth'),
+ permission => $permission->{'setltiauth'},
+ linktitle => '',
+ },
+ {
+ linktext => $linktext{'setexttool'},
+ icon => 'exttool.png',
+ #help => '',
+ url => &phaseurl('setexttool'),
+ permission => $permission->{'setexttool'},
+ linktitle => '',
+ },
]
},
);
@@ -583,7 +608,9 @@ sub print_modification_menu {
'
'.$setquota_text.''."\n".
''.$setuploadquota_text.''."\n".
''.$anon_text.''."\n".
- ''.$postsubmit_text.''."\n";
+ ''.$postsubmit_text.''."\n".
+ ''.$ltiauth_text.''."\n".
+ ''.$exttool_text.''."\n";
my ($categories_link_start,$categories_link_end);
if ($permission->{'catsettings'} eq 'edit') {
$categories_link_start = '';
@@ -681,9 +708,34 @@ sub print_settings_display {
"$lt{'dcon'} | \n".
&Apache::loncommon::end_data_table_header_row()."\n";
foreach my $item (@items) {
+ my $shown = $enrollvar{$item};
+ if ($item eq 'crosslistings') {
+ my (@xlists,@lcsecs);
+ foreach my $entry (split(/,/,$enrollvar{$item})) {
+ my ($xlist,$lc_sec) = split(/:/,$entry);
+ push(@xlists,$xlist);
+ push(@lcsecs,$lc_sec);
+ }
+ if (@xlists) {
+ my $crskey = $cnum.':'.$enrollvar{'coursecode'};
+ my %reformatted =
+ &Apache::lonnet::auto_instsec_reformat($cdom,'declutter',
+ {$crskey => \@xlists});
+ if (ref($reformatted{$crskey}) eq 'ARRAY') {
+ my @show;
+ my @xlcodes = @{$reformatted{$crskey}};
+ for (my $i=0; $i<@xlcodes; $i++) {
+ push(@show,$xlcodes[$i].':'.$lcsecs[$i]);
+ }
+ if (@show) {
+ $shown = join(',',@show);
+ }
+ }
+ }
+ }
$disp_table .= &Apache::loncommon::start_data_table_row()."\n".
"$longtype{$item} | \n".
- "$enrollvar{$item} | \n";
+ "$shown | \n";
if (grep(/^\Q$item\E$/,@modifiable_params)) {
$disp_table .= ''.&mt('Yes').' | '."\n";
} else {
@@ -904,15 +956,7 @@ ENDDOCUMENT
sub domain_postsubtimeout {
my ($cdom,$type,$settings) = @_;
return unless (ref($settings) eq 'HASH');
- my $lctype = lc($type);
- unless (($type eq 'Community') || ($type eq 'Placement')) {
- $lctype = 'unofficial';
- if ($settings->{'internal.coursecode'}) {
- $lctype = 'official';
- } elsif ($settings->{'internal.textbook'}) {
- $lctype = 'textbook';
- }
- }
+ my $lctype = &get_lctype($type,$settings);
my %domconfig =
&Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
my $postsubtimeout = 60;
@@ -928,6 +972,22 @@ sub domain_postsubtimeout {
return $postsubtimeout;
}
+sub get_lctype {
+ my ($type,$settings) = @_;
+ my $lctype = lc($type);
+ unless (($type eq 'Community') || ($type eq 'Placement')) {
+ $lctype = 'unofficial';
+ if (ref($settings) eq 'HASH') {
+ if ($settings->{'internal.coursecode'}) {
+ $lctype = 'official';
+ } elsif ($settings->{'internal.textbook'}) {
+ $lctype = 'textbook';
+ }
+ }
+ }
+ return $lctype;
+}
+
sub print_catsettings {
my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
&print_header($r,$type);
@@ -1233,6 +1293,199 @@ sub print_selfenrollconfig {
return;
}
+sub print_set_ltiauth {
+ my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
+ my %lt = &Apache::lonlocal::texthash(
+ 'requ' => 'Requirement for re-authentication for student LTI-limited launch of deep-linked item',
+ 'link' => 'Link protection can be set to accept username for an enrolled student (if sent by Consumer)',
+ 'logi' => 'Login needed, regardless of user information sent by LTI Consumer in (signed) parameters',
+ 'used' => 'Use domain default',
+ 'cour' => 'Use course-specific setting',
+ 'curd' => 'Current domain default is',
+ 'valu' => 'Value for this course',
+ 'modi' => 'Save',
+ 'back' => 'Pick another action',
+ );
+ my ($domdef,$checkeddom,$checkedcrs,$domdefdisplay,$divsty,$authok,$authno);
+ $domdef = 0;
+ $checkeddom = ' checked="checked"';
+ $domdefdisplay = $lt{'logi'};
+ $divsty = 'display:none';
+ $authno = ' checked="checked"';
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
+ if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
+ $domdef = $domconfig{'coursedefaults'}{'ltiauth'};
+ }
+ if ($domdef) {
+ $domdefdisplay = $lt{'link'};
+ }
+ my %settings = &Apache::lonnet::get('environment',['internal.ltiauth'],$cdom,$cnum);
+ my $ltiauth = $settings{'internal.ltiauth'};
+
+ if ($ltiauth ne '') {
+ $checkedcrs = $checkeddom;
+ $checkeddom = '';
+ $divsty = 'display:inline-block';
+ if ($ltiauth) {
+ $authok = ' checked="checked"';
+ }
+ }
+ &print_header($r,$type);
+ my $hidden_elements = &hidden_form_elements();
+ my ($disabled,$submit);
+ if ($readonly) {
+ $disabled = ' disabled="disabled"';
+ } else {
+ $submit = '';
+ }
+ my $helpitem = &Apache::loncommon::help_open_topic('Modify_Course_LTI_Authen');
+ $r->print(<
+$helpitem $lt{'requ'} $cdesc
+$lt{'curd'}: $domdefdisplay
+
+
+
+
+
+$submit
+
+$hidden_elements
+$lt{'back'}
+
+ENDDOCUMENT
+ return;
+}
+
+sub print_set_exttool {
+ my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
+ my %titles = &exttool_titles($type);
+ my ($domdef,$domdefdom,$checkeddom,$checkedcrs,$domdefdisplay,$divsty);
+ $domdef = 0;
+ $domdefdom = 1;
+ $checkeddom = ' checked="checked"';
+ $divsty = 'display:none';
+ my %settings = &Apache::lonnet::get('environment',['internal.coursecode',
+ 'internal.textbook'],$cdom,$cnum);
+ my $lctype = &get_lctype($type,\%settings);
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
+ if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
+ if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
+ if (exists($domconfig{'coursedefaults'}{'exttool'}{$lctype})) {
+ $domdef = $domconfig{'coursedefaults'}{'exttool'}{$lctype};
+ }
+ }
+ if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
+ if (exists($domconfig{'coursedefaults'}{'domexttool'}{$lctype})) {
+ $domdefdom = $domconfig{'coursedefaults'}{'domexttool'}{$lctype};
+ }
+ }
+ }
+ if ($domdef && $domdefdom) {
+ $domdefdisplay = $titles{'both'};
+ } elsif ($domdef) {
+ $domdefdisplay = $titles{'crs'};
+ } elsif ($domdefdom) {
+ $domdefdisplay = $titles{'dom'};
+ } else {
+ $domdefdisplay = $titles{'none'};
+ }
+ my %settings = &Apache::lonnet::get('environment',['internal.exttool'],$cdom,$cnum);
+ my $crsexttool = $settings{'internal.exttool'};
+ my %crschecked = (
+ both => ' checked="checked"',
+ dom => '',
+ crs => '',
+ none => '',
+ );
+ if ($crsexttool ne '') {
+ $checkedcrs = $checkeddom;
+ $checkeddom = '';
+ $divsty = 'display:inline-block';
+ foreach my $option ('both','dom','crs','none') {
+ if ($crsexttool eq $option) {
+ $crschecked{$option} = ' checked="checked"';
+ } else {
+ $crschecked{$option} = '';
+ }
+ }
+ }
+ &print_header($r,$type);
+ my $hidden_elements = &hidden_form_elements();
+ my ($disabled,$submit);
+ if ($readonly) {
+ $disabled = ' disabled="disabled"';
+ } else {
+ $submit = '';
+ }
+ my $helpitem = &Apache::loncommon::help_open_topic('Modify_Course_External_Tool');
+ $r->print(<
+$helpitem $titles{'extt'}
+$type: $cdesc
+$titles{'curd'}: $domdefdisplay
+
+
+
+
+
+$submit
+
+$hidden_elements
+$titles{'back'}
+
+ENDDOCUMENT
+ return;
+}
+
+sub exttool_titles {
+ my ($type) = @_;
+ my %titles = &Apache::lonlocal::texthash(
+ 'extt' => 'External Tool permissions',
+ 'none' => 'Use of external tools not permitted',
+ 'crs' => 'Only external tools defined in course may be used',
+ 'dom' => 'Only external tools defined in domain may be used',
+ 'both' => 'External tools defined/configured in either domain or course may be used',
+ 'used' => 'Use domain default',
+ 'cour' => 'Use course-specific setting',
+ 'curd' => 'Current domain default is',
+ 'valu' => 'Value for this course',
+ 'modi' => 'Save',
+ 'back' => 'Pick another action',
+ );
+ if ($type eq 'Community') {
+ $titles{'crs'} = &mt('Only external tools defined in community may be used');
+ $titles{'both'} = &mt('External tools defined/configured in either domain or community may be used');
+ $titles{'cour'} = &mt('Use community-specific setting');
+ $titles{'valu'} = &mt('Value for this community');
+ }
+ return %titles;
+}
+
sub modify_selfenrollconfig {
my ($r,$type,$cdesc,$coursehash) = @_;
return unless(ref($coursehash) eq 'HASH');
@@ -1484,6 +1737,18 @@ sub modify_course {
my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
if (($putres eq 'ok') && (($changed{'owner'} || $changed{'code'}))) {
&update_coowners($cdom,$cnum,$chome,\%settings,\%newattr);
+ if ($changed{'code'}) {
+ &Apache::lonnet::devalidate_cache_new('instcats',$cdom);
+ # Update cache of self-cataloging courses on institution's server(s).
+ if (&Apache::lonnet::shared_institution($cdom)) {
+ unless ($registered_cleanup) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\&devalidate_remote_instcats,@{$handlers}]);
+ $registered_cleanup=1;
+ $modified_dom = $cdom;
+ }
+ }
+ }
}
}
}
@@ -2218,6 +2483,217 @@ sub modify_catsettings {
return;
}
+sub modify_ltiauth {
+ my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
+ my %lt = &Apache::lonlocal::texthash(
+ 'requ' => 'Requirement for re-authentication for student LTI-limited launch of deep-linked item',
+ 'link' => 'Link protection can be set to accept username for an enrolled student (if sent by Consumer)',
+ 'logi' => 'Login needed, regardless of user information sent by LTI Consumer in (signed) parameters',
+ 'used' => 'Use domain default',
+ 'cour' => 'Use course-specific setting',
+ 'modi' => 'Save',
+ 'back' => 'Pick another action',
+ );
+ &print_header($r,$type);
+ $r->print('');
+ return;
+}
+
+sub modify_exttool {
+ my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
+ my %titles = &exttool_titles($type);
+ &print_header($r,$type);
+ $r->print('');
+ return;
+}
+
sub print_header {
my ($r,$type,$javascript_validations) = @_;
my $phase = "start";
@@ -2373,6 +2849,64 @@ function togglePostsubmit(caller) {
ENDSCRIPT
+ } elsif ($phase eq 'setltiauth') {
+ $js .= <<"ENDJS";
+function toggleLTIOptions(form) {
+ var radioname = 'ltiauthset';
+ var divid = 'crsltiauth';
+ var num = form.elements[radioname].length;
+ if (num) {
+ var setvis = '';
+ for (var i=0; i {'onload' => "hide_searching(); courseSet(document.filterpicker.official, 'load');"},
};
+ } elsif ($env{'form.phase'} eq 'setltiauth') {
+ $starthash = {
+ add_entries => {'onload' => "toggleLTIOptions(document.setltiauth);"},
+ };
+ } elsif ($env{'form.phase'} eq 'setexttool') {
+ $starthash = {
+ add_entries => {'onload' => "toggleExtToolOptions(document.setexttool);"},
+ };
}
$r->print(&Apache::loncommon::start_page('View/Modify Course/Community Settings',
&Apache::lonhtmlcommon::scripttag($js),
@@ -2482,8 +3024,8 @@ sub hidden_form_elements {
'locarg','krbarg','krbver','counter','hidefromcat','usecategory',
'threshold','postsubmit','postsubtimeout','defaultcredits','uploadquota',
'selfenrollmgrdc','selfenrollmgrcc','action','state','currsec_st',
- 'sections','newsec','mysqltables','nopasswdchg'],
- ['^selfenrollmgr_','^selfenroll_'])."\n".
+ 'sections','newsec','mysqltables','nopasswdchg','ltiauth','ltiauthset',
+ 'exttoolset','exttool'],['^selfenrollmgr_','^selfenroll_'])."\n".
'';
return $hidden_elements;
}
@@ -2516,6 +3058,10 @@ sub get_permission {
processcat => 'edit',
selfenroll => 'edit',
adhocrole => 'coord',
+ setltiauth => 'edit',
+ processltiauth => 'edit',
+ setexttool => 'edit',
+ processexttool => 'edit',
);
if ($passwdconf{'crsownerchg'}) {
$permission{passwdchg} = 'edit';
@@ -2531,6 +3077,8 @@ sub get_permission {
catsettings => 'view',
selfenroll => 'view',
adhocrole => 'custom',
+ setltiauth => 'view',
+ setexttool => 'view',
);
if ($passwdconf{'crsownerchg'}) {
$permission{passwdchg} = 'view';
@@ -2539,6 +3087,22 @@ sub get_permission {
return ($allowed,\%permission);
}
+sub devalidate_remote_instcats {
+ if ($modified_dom ne '') {
+ my %servers = &Apache::lonnet::internet_dom_servers($modified_dom);
+ my %thismachine;
+ map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
+ if (keys(%servers)) {
+ foreach my $server (keys(%servers)) {
+ next if ($thismachine{$server});
+ &Apache::lonnet::remote_devalidate_cache($server,['instcats:'.$modified_dom]);
+ }
+ }
+ $modified_dom = '';
+ }
+ return;
+}
+
sub handler {
my $r = shift;
if ($r->header_only) {
@@ -2547,6 +3111,9 @@ sub handler {
return OK;
}
+ $registered_cleanup=0;
+ $modified_dom = '';
+
my $dom = $env{'request.role.domain'};
my $domdesc = &Apache::lonnet::domain($dom,'description');
my ($allowed,$permission) = &get_permission($dom);
@@ -2715,6 +3282,30 @@ sub handler {
text=>"Result"});
&modify_selfenrollconfig($r,$type,$cdesc,$coursehash);
}
+ } elsif (($phase eq 'setltiauth') && ($permission->{'setltiauth'})) {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:changePage(document.$phase,'$phase')",
+ text=>"Requirement for re-authentication for LTI launch of deep-linked item"});
+ &print_set_ltiauth($r,$cdom,$cnum,$cdesc,$type,$readonly);
+ } elsif (($phase eq 'processltiauth') && ($permission->{'processltiauth'})) {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:changePage(document.$phase,'setltiauth')",
+ text=>"Requirement for re-authentication for LTI launch of deep-linked item"},
+ {href=>"javascript:changePage(document.$phase,'$phase')",
+ text=>"Result"});
+ &modify_ltiauth($r,$cdom,$cnum,$cdesc,$domdesc,$type);
+ } elsif (($phase eq 'setexttool') && ($permission->{'setexttool'})) {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:changePage(document.$phase,'$phase')",
+ text=>"External Tool permission"});
+ &print_set_exttool($r,$cdom,$cnum,$cdesc,$type,$readonly);
+ } elsif (($phase eq 'processexttool') && ($permission->{'processexttool'})) {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:changePage(document.$phase,'setexttool')",
+ text=>"External Tool permission"},
+ {href=>"javascript:changePage(document.$phase,'$phase')",
+ text=>"Result"});
+ &modify_exttool($r,$cdom,$cnum,$cdesc,$domdesc,$type);
}
}
} else {