[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm lonmsg.pm lonsyllabus.pm portfolio.pm /lonnet/perl lonnet.pm
raeburn
raeburn at source.lon-capa.org
Sun Sep 18 18:33:45 EDT 2022
raeburn Sun Sep 18 22:33:45 2022 EDT
Modified files:
/loncom/interface domainprefs.pm lonmsg.pm lonsyllabus.pm
portfolio.pm
/loncom/lonnet/perl lonnet.pm
Log:
- URLs in direct links to LON-CAPA messages in notification email, and to
publicly accessible syllabus or portfolio files can be set to use hostname
of portal server instead of user's homeserver as first part of URL.
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.413 loncom/interface/domainprefs.pm:1.414
--- loncom/interface/domainprefs.pm:1.413 Thu Sep 8 01:41:13 2022
+++ loncom/interface/domainprefs.pm Sun Sep 18 22:33:45 2022
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.413 2022/09/08 01:41:13 raeburn Exp $
+# $Id: domainprefs.pm,v 1.414 2022/09/18 22:33:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -10675,13 +10675,29 @@
} elsif ($item eq 'lang_def') {
my $includeempty = 1;
$datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
- } else {
- my $size;
- if ($item eq 'portal_def') {
- $size = ' size="25"';
- }
+ } elsif ($item eq 'portal_def') {
$datatable .= '<input type="text" name="'.$item.'" value="'.
- $defaults{$item}.'"'.$size.' />';
+ $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
+ my $portalsty = 'none';
+ if ($defaults{$item}) {
+ $portalsty = 'block';
+ }
+ foreach my $field ('email','web') {
+ my $checkedoff = ' checked="checked"';
+ my $checkedon;
+ if ($defaults{$item.'_'.$field}) {
+ $checkedon = $checkedoff;
+ $checkedoff = '';
+ }
+ $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
+ '<span class="LC_nobreak">'.$titles->{$field}.' '.
+ '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
+ (' 'x2).
+ '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
+ '</div>';
+ }
+ } else {
+ $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
}
$datatable .= '</td></tr>';
$rownum ++;
@@ -10777,6 +10793,8 @@
'timezone_def' => 'Default timezone',
'datelocale_def' => 'Default locale for dates',
'portal_def' => 'Portal/Default URL',
+ 'email' => 'Email links use portal URL',
+ 'web' => 'Public web links use portal URL',
'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
'intauth_check' => 'Check bcrypt cost if authenticated',
'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
@@ -11491,6 +11509,23 @@
sub defaults_javascript {
my ($settings) = @_;
return unless (ref($settings) eq 'HASH');
+ my $portal_js = <<"ENDPORTAL";
+
+function portalExtras(caller) {
+ var x = caller.value;
+ var y = new Array('email','web');
+ for (var i=0; i<y.length; i++) {
+ if (document.getElementById('portal_def_'+y[i]+'_div')) {
+ var z = document.getElementById('portal_def_'+y[i]+'_div');
+ if (x.length > 0) {
+ z.style.display = 'block';
+ } else {
+ z.style.display = 'none';
+ }
+ }
+ }
+}
+ENDPORTAL
if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
my $maxnum = scalar(@{$settings->{'inststatusorder'}});
if ($maxnum eq '') {
@@ -11544,6 +11579,17 @@
return;
}
+$portal_js
+
+// ]]>
+</script>
+
+ENDSCRIPT
+ } else {
+return <<"ENDSCRIPT";
+<script type="text/javascript">
+// <![CDATA[
+$portal_js
// ]]>
</script>
@@ -19993,16 +20039,58 @@
}
} elsif ($item eq 'portal_def') {
if ($newvalues{$item} ne '') {
- unless ($newvalues{$item} =~ /^https?\:\/\/(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\/?$/) {
+ if ($newvalues{$item} =~ /^https?\:\/\/(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\/?$/) {
+ foreach my $field ('email','web') {
+ if ($env{'form.'.$item.'_'.$field}) {
+ $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
+ }
+ }
+ } else {
push(@errors,$item);
}
}
}
if (grep(/^\Q$item\E$/, at errors)) {
$newvalues{$item} = $domdefaults{$item};
+ if ($item eq 'portal_def') {
+ if ($domdefaults{$item}) {
+ foreach my $field ('email','web') {
+ if (exists($domdefaults{$item.'_'.$field})) {
+ $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
+ }
+ }
+ }
+ }
} elsif ($domdefaults{$item} ne $newvalues{$item}) {
$changes{$item} = 1;
}
+ if ($item eq 'portal_def') {
+ unless (grep(/^\Q$item\E$/, at errors)) {
+ if ($newvalues{$item} eq '') {
+ foreach my $field ('email','web') {
+ if (exists($domdefaults{$item.'_'.$field})) {
+ delete($domdefaults{$item.'_'.$field});
+ }
+ }
+ } else {
+ unless ($changes{$item}) {
+ foreach my $field ('email','web') {
+ if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
+ $changes{$item} = 1;
+ last;
+ }
+ }
+ }
+ foreach my $field ('email','web') {
+ if ($newvalues{$item.'_'.$field}) {
+ $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
+ } elsif (exists($domdefaults{$item.'_'.$field})) {
+ delete($domdefaults{$item.'_'.$field});
+ }
+ }
+ }
+ }
+ }
$domdefaults{$item} = $newvalues{$item};
}
my %staticdefaults = (
@@ -20202,7 +20290,20 @@
$value = $authnames{$shortauth{$value}};
}
$resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
- $mailmsgtext .= "$title->{$item} set to $value\n";
+ $mailmsgtext .= "$title->{$item} set to $value\n";
+ if ($item eq 'portal_def') {
+ if ($env{'form.'.$item} ne '') {
+ foreach my $field ('email','web') {
+ $value = $env{'form.'.$item.'_'.$field};
+ if ($value) {
+ $value = &mt('Yes');
+ } else {
+ $value = &mt('No');
+ }
+ $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
+ }
+ }
+ }
}
}
$resulttext .= '</ul>';
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.248 loncom/interface/lonmsg.pm:1.249
--- loncom/interface/lonmsg.pm:1.248 Tue Jan 18 17:33:13 2022
+++ loncom/interface/lonmsg.pm Sun Sep 18 22:33:45 2022
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging
#
-# $Id: lonmsg.pm,v 1.248 2022/01/18 17:33:13 raeburn Exp $
+# $Id: lonmsg.pm,v 1.249 2022/09/18 22:33:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -510,12 +510,8 @@
$text=~s/\<\;/\</gs;
$text=~s/\>\;/\>/gs;
- my $homeserver = &Apache::lonnet::homeserver($touname,$toudom);
- my $hostname = &Apache::lonnet::hostname($homeserver);
- my $protocol = $Apache::lonnet::protocol{$homeserver};
- $protocol = 'http' if ($protocol ne 'https');
-#FIXME
- my $url = $protocol.'://'.$hostname.
+ my $touhome = &Apache::lonnet::homeserver($touname,$toudom);
+ my $url = &Apache::lonnet::url_prefix('',$toudom,$touhome,'email').
'/adm/email?username='.$touname.'&domain='.$toudom.
'&display='.&escape($msgid);
my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,
Index: loncom/interface/lonsyllabus.pm
diff -u loncom/interface/lonsyllabus.pm:1.150 loncom/interface/lonsyllabus.pm:1.151
--- loncom/interface/lonsyllabus.pm:1.150 Tue May 4 18:47:36 2021
+++ loncom/interface/lonsyllabus.pm Sun Sep 18 22:33:45 2022
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Syllabus
#
-# $Id: lonsyllabus.pm,v 1.150 2021/05/04 18:47:36 raeburn Exp $
+# $Id: lonsyllabus.pm,v 1.151 2022/09/18 22:33:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -314,12 +314,8 @@
if ($allowed) {
#---------------------------------- Print External URL Syllabus Info if editing
if ($target ne 'tex') {
- my $hostname = &Apache::lonnet::hostname($homeserver);
- my $protocol = $Apache::lonnet::protocol{$homeserver};
- $protocol = 'http' if ($protocol ne 'https');
- my $alias = &Apache::lonnet::use_proxy_alias($r,$homeserver);
- $hostname = $alias if ($alias ne '');
- my $link = $protocol.'://'.$hostname.$r->uri;
+ my $link = &Apache::lonnet::url_prefix($r,$cdom,$homeserver,'web').
+ $r->uri;
$r->print('<div class="LC_left_float">'
.'<span class="LC_help_open_topic LC_info">'
.'<span class="LC_info">'
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.265 loncom/interface/portfolio.pm:1.266
--- loncom/interface/portfolio.pm:1.265 Tue Nov 30 15:55:37 2021
+++ loncom/interface/portfolio.pm Sun Sep 18 22:33:45 2022
@@ -1,7 +1,7 @@
# The LearningOnline Network
# portfolio browser
#
-# $Id: portfolio.pm,v 1.265 2021/11/30 15:55:37 raeburn Exp $
+# $Id: portfolio.pm,v 1.266 2022/09/18 22:33:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -897,6 +897,8 @@
my $aclcount = keys(%access_controls);
my ($header,$info);
if ($action eq 'chgaccess') {
+ my $uhome = &Apache::lonnet::homeserver($uname,$udom);
+ my $prefix = &Apache::lonnet::url_prefix($r,$udom,$uhome,'web');
$header =
'<h2>'
.&mt('Allowing others to retrieve file: [_1]'
@@ -909,13 +911,13 @@
$info .= '</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.');
$info .= '</li><li>'.&explain_conditionals();
$info .= '</li></ul>'.
- &mt('A listing of files viewable without log-in is available at: ')."<a href=\"/adm/$udom/$uname/aboutme/portfolio\">".&Apache::lonnet::absolute_url()."/adm/$udom/$uname/aboutme/portfolio</a>.<br />";
+ &mt('A listing of files viewable without log-in is available at: ')."<a href=\"$prefix/adm/$udom/$uname/aboutme/portfolio\">$prefix/adm/$udom/$uname/aboutme/portfolio</a>.<br />";
if ($group eq '') {
$info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on your personal information page:");
} else {
$info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on the course information page:");
}
- $info .= "<br /><a href=\"/adm/$udom/$uname/aboutme\">".&Apache::lonnet::absolute_url()."/adm/$udom/$uname/aboutme</a><br />";
+ $info .= "<br /><a href=\"$prefix/adm/$udom/$uname/aboutme\">$prefix/adm/$udom/$uname/aboutme</a><br />";
if ($group ne '') {
$info .= &mt("Users with course editing rights may add a 'Group Portfolio' item using the Course Editor (Collaboration tab), to provide access to viewable group portfolio files.").'<br />';
}
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1491 loncom/lonnet/perl/lonnet.pm:1.1492
--- loncom/lonnet/perl/lonnet.pm:1.1491 Tue Sep 13 12:22:15 2022
+++ loncom/lonnet/perl/lonnet.pm Sun Sep 18 22:33:45 2022
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.1491 2022/09/13 12:22:15 raeburn Exp $
+# $Id: lonnet.pm,v 1.1492 2022/09/18 22:33:45 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2707,6 +2707,8 @@
$domdefaults{'timezone_def'} = $domconfig{'defaults'}{'timezone_def'};
$domdefaults{'datelocale_def'} = $domconfig{'defaults'}{'datelocale_def'};
$domdefaults{'portal_def'} = $domconfig{'defaults'}{'portal_def'};
+ $domdefaults{'portal_def_email'} = $domconfig{'defaults'}{'portal_def_email'};
+ $domdefaults{'portal_def_web'} = $domconfig{'defaults'}{'portal_def_web'};
$domdefaults{'intauth_cost'} = $domconfig{'defaults'}{'intauth_cost'};
$domdefaults{'intauth_switch'} = $domconfig{'defaults'}{'intauth_switch'};
$domdefaults{'intauth_check'} = $domconfig{'defaults'}{'intauth_check'};
@@ -2967,6 +2969,26 @@
return $firsturl;
}
+sub url_prefix {
+ my ($r,$dom,$home,$context) = @_;
+ my $prefix;
+ my %domdefs = &get_domain_defaults($dom);
+ if ($domdefs{'portal_def'} && $domdefs{'portal_def_'.$context}) {
+ if ($domdefs{'portal_def'} =~ m{^(https?://[^/]+)}) {
+ $prefix = $1;
+ }
+ }
+ if ($prefix eq '') {
+ my $hostname = &hostname($home);
+ my $protocol = $protocol{$home};
+ $protocol = 'http' if ($protocol{$home} ne 'https');
+ my $alias = &use_proxy_alias($r,$home);
+ $hostname = $alias if ($alias ne '');
+ $prefix = $protocol.'://'.$hostname;
+ }
+ return $prefix;
+}
+
# --------------------------------------------- Get domain config for passwords
sub get_passwdconf {
More information about the LON-CAPA-cvs
mailing list