[LON-CAPA-cvs] cvs: loncom /auth lonroles.pm /interface loncommon.pm londocs.pm lonnavdisplay.pm
raeburn
raeburn at source.lon-capa.org
Sun Mar 1 17:21:00 EST 2015
raeburn Sun Mar 1 22:21:00 2015 EDT
Modified files:
/loncom/interface lonnavdisplay.pm londocs.pm loncommon.pm
/loncom/auth lonroles.pm
Log:
- &check_release_required() moved from lonroles.pm to loncommon.pm to
facilitate reuse.
- Display of Contents page will check if it has been more than 10 minutes
since last check for content change in course.
- If it has been: loncommon::needs_coursereinit() will be called to check if
course was changes after the "Big Hash" was last tied for the user's session
in the course.
- The course will be re-initialized (or a Switch Server link displayed),
as needed.
-------------- next part --------------
Index: loncom/interface/lonnavdisplay.pm
diff -u loncom/interface/lonnavdisplay.pm:1.30 loncom/interface/lonnavdisplay.pm:1.31
--- loncom/interface/lonnavdisplay.pm:1.30 Sun Mar 1 20:47:54 2015
+++ loncom/interface/lonnavdisplay.pm Sun Mar 1 22:20:56 2015
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Display Handler
#
-# $Id: lonnavdisplay.pm,v 1.30 2015/03/01 20:47:54 raeburn Exp $
+# $Id: lonnavdisplay.pm,v 1.31 2015/03/01 22:20:56 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -61,6 +61,27 @@
return REDIRECT;
}
+ # Check if course needs to be re-initialized
+ my $loncaparev = $r->dir_config('lonVersion');
+ my ($result, at reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
+
+ if ($result eq 'switch') {
+ &Apache::loncommon::content_type($r,'text/html');
+ $r->send_http_header;
+ $r->print(&Apache::loncommon::check_release_result(@reinit));
+ return OK;
+ } elsif ($result eq 'update') {
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
+ if ($ferr) {
+ my $requrl = $r->uri;
+ $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
+ $env{'user.reinit'} = 1;
+ return HTTP_NOT_ACCEPTABLE;
+ }
+ }
+
# Create the nav map
my $navmap = Apache::lonnavmaps::navmap->new();
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.591 loncom/interface/londocs.pm:1.592
--- loncom/interface/londocs.pm:1.591 Sun Dec 21 16:26:31 2014
+++ loncom/interface/londocs.pm Sun Mar 1 22:20:56 2015
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.591 2014/12/21 16:26:31 raeburn Exp $
+# $Id: londocs.pm,v 1.592 2015/03/01 22:20:56 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2806,7 +2806,7 @@
# Rename, cut, copy or remove a single resource
if (&handle_edit_cmd()) {
my $contentchg;
- if ($env{'form.cmd'} =~ m{^(del|cut)_}) {
+ if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
$contentchg = 1;
}
($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1206 loncom/interface/loncommon.pm:1.1207
--- loncom/interface/loncommon.pm:1.1206 Wed Feb 25 19:22:24 2015
+++ loncom/interface/loncommon.pm Sun Mar 1 22:20:56 2015
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1206 2015/02/25 19:22:24 raeburn Exp $
+# $Id: loncommon.pm,v 1.1207 2015/03/01 22:20:56 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -11485,7 +11485,6 @@
for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
-
document.getElementById('camtasia_titles').style.display='block';
} else {
document.getElementById('camtasia_titles').style.display='none';
@@ -15628,8 +15627,206 @@
=back
+=head1 Routines for version requirements for current course.
+
+=over 4
+
+=item * &check_release_required()
+
+Compares required LON-CAPA version with version on server, and
+if required version is newer looks for a server with the required version.
+
+Looks first at servers in user's owen domain; if none suitable, looks at
+servers in course's domain are permitted to host sessions for user's domain.
+
+Inputs:
+
+$loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
+
+$courseid - Course ID of current course
+
+$rolecode - User's current role in course (for switchserver query string).
+
+$required - LON-CAPA version needed by course (format: Major.Minor).
+
+
+Returns:
+
+$switchserver - query string tp append to /adm/switchserver call (if
+ current server's LON-CAPA version is too old.
+
+$warning - Message is displayed if no suitable server could be found.
+
+=cut
+
+sub check_release_required {
+ my ($loncaparev,$courseid,$rolecode,$required) = @_;
+ my ($switchserver,$warning);
+ if ($required ne '') {
+ my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
+ my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
+ if ($reqdmajor ne '' && $reqdminor ne '') {
+ my $otherserver;
+ if (($major eq '' && $minor eq '') ||
+ (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
+ my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
+ my $switchlcrev =
+ &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
+ $userdomserver);
+ my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
+ if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
+ (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
+ my $cdom = $env{'course.'.$courseid.'.domain'};
+ if ($cdom ne $env{'user.domain'}) {
+ my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
+ my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
+ my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
+ my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
+ my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
+ my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
+ my $canhost =
+ &Apache::lonnet::can_host_session($env{'user.domain'},
+ $coursedomserver,
+ $remoterev,
+ $udomdefaults{'remotesessions'},
+ $defdomdefaults{'hostedsessions'});
+
+ if ($canhost) {
+ $otherserver = $coursedomserver;
+ } else {
+ $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
+ }
+ } else {
+ $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
+ }
+ } else {
+ $otherserver = $userdomserver;
+ }
+ }
+ if ($otherserver ne '') {
+ $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
+ }
+ }
+ }
+ return ($switchserver,$warning);
+}
+
+=pod
+
+=item * &check_release_result()
+
+Inputs:
+
+$switchwarning - Warning message if no suitable server found to host session.
+
+$switchserver - query string to append to /adm/switchserver containing lonHostID
+ and current role.
+
+Returns: HTML to display with information about requirement to switch server.
+ Either displaying warning with link to Roles/Courses screen or
+ display link to switchserver.
+
=cut
+sub check_release_result {
+ my ($switchwarning,$switchserver) = @_;
+ my $output = &start_page('Selected course unavailable on this server').
+ '<p class="LC_warning">';
+ if ($switchwarning) {
+ $output .= $switchwarning.'<br /><a href="/adm/roles">';
+ if (&show_course()) {
+ $output .= &mt('Display courses');
+ } else {
+ $output .= &mt('Display roles');
+ }
+ $output .= '</a>';
+ } elsif ($switchserver) {
+ $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
+ '<br />'.
+ '<a href="/adm/switchserver?'.$switchserver.'">'.
+ &mt('Switch Server').
+ '</a>';
+ }
+ $output .= '</p>'.&end_page();
+ return $output;
+}
+
+=pod
+
+=item * &needs_coursereinit()
+
+Determine if course contents stored for user's session needs to be
+refreshed, because content has changed since "Big Hash" last tied.
+
+Check for change is made if time last checked is more than 10 minutes ago
+(by default).
+
+Inputs:
+
+$loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
+
+$interval (optional) - Time which may elapse (in s) between last check for content
+ change in current course. (default: 600 s).
+
+Returns: an array; first element is:
+
+=over 4
+
+'switch' - if content updates mean user's session
+ needs to be switched to a server running a newer LON-CAPA version
+
+'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
+ on current server hosting user's session
+
+'' - if no action required.
+
+=back
+
+If first item element is 'switch':
+
+second item is $switchwarning - Warning message if no suitable server found to host session.
+
+third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
+ and current role.
+
+otherwise: no other elements returned.
+
+=back
+
+=cut
+
+sub needs_coursereinit {
+ my ($loncaparev,$interval) = @_;
+ return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $now = time;
+ if ($interval eq '') {
+ $interval = 600;
+ }
+ if (($now-$env{'request.course.timechecked'})>$interval) {
+ my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
+ &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
+ if ($lastchange > $env{'request.course.tied'}) {
+ my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
+ if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
+ my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
+ if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
+ &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
+ $curr_reqd_hash{'internal.releaserequired'}});
+ my ($switchserver,$switchwarning) =
+ &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
+ $curr_reqd_hash{'internal.releaserequired'});
+ if ($switchwarning ne '' || $switchserver ne '') {
+ return ('switch',$switchwarning,$switchserver);
+ }
+ }
+ }
+ return ('update');
+ }
+ }
+ return ();
+}
sub update_content_constraints {
my ($cdom,$cnum,$chome,$cid) = @_;
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.309 loncom/auth/lonroles.pm:1.310
--- loncom/auth/lonroles.pm:1.309 Sun Dec 14 21:47:48 2014
+++ loncom/auth/lonroles.pm Sun Mar 1 22:21:00 2015
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.309 2014/12/14 21:47:48 raeburn Exp $
+# $Id: lonroles.pm,v 1.310 2015/03/01 22:21:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -286,14 +286,15 @@
&Apache::lonnet::put('email_status',\%temp);
&Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
}
- &Apache::lonnet::appenv({"request.course.id" => '',
- "request.course.fn" => '',
- "request.course.uri" => '',
- "request.course.sec" => '',
- "request.course.tied" => '',
- "request.role" => 'cm',
- "request.role.adv" => $env{'user.adv'},
- "request.role.domain" => $env{'user.domain'}});
+ &Apache::lonnet::appenv({"request.course.id" => '',
+ "request.course.fn" => '',
+ "request.course.uri" => '',
+ "request.course.sec" => '',
+ "request.course.tied" => '',
+ "request.course.timechecked" => '',
+ "request.role" => 'cm',
+ "request.role.adv" => $env{'user.adv'},
+ "request.role.domain" => $env{'user.domain'}});
# Check if user is a DC trying to enter a course or author space and needs privs to be created
if ($numdc > 0) {
foreach my $envkey (keys(%env)) {
@@ -382,30 +383,13 @@
my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
my ($switchserver,$switchwarning) =
- &check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,$curr_reqd_hash{'internal.releaserequired'});
+ &Apache::loncommon::check_release_required($loncaparev,$cdom.'_'.$cnum,$trolecode,
+ $curr_reqd_hash{'internal.releaserequired'});
if ($switchwarning ne '' || $switchserver ne '') {
&Apache::loncommon::content_type($r,'text/html');
&Apache::loncommon::no_cache($r);
$r->send_http_header;
- my $end_page=&Apache::loncommon::end_page();
- $r->print(&Apache::loncommon::start_page('Selected course unavailable on this server').
- '<p class="LC_warning">');
- if ($switchwarning) {
- $r->print($switchwarning.'<br /><a href="/adm/roles">');
- if (&Apache::loncommon::show_course()) {
- $r->print(&mt('Display courses'));
- } else {
- $r->print(&mt('Display roles'));
- }
- $r->print('</a>');
- } elsif ($switchserver) {
- $r->print(&mt('This course requires a newer version of LON-CAPA than is installed on this server.').
- '<br />'.
- '<a href="/adm/switchserver?'.$switchserver.'">'.
- &mt('Switch Server').
- '</a>');
- }
- $r->print('</p>'.&Apache::loncommon::end_page());
+ $r->print(&Apache::loncommon::check_release_result($switchwarning,$switchserver));
return OK;
}
}
@@ -1211,7 +1195,7 @@
my $required = $env{'course.'.$tcourseid.'.internal.releaserequired'};
if ($required ne '') {
($switchserver,$switchwarning) =
- &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
+ &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
if ($switchserver || $switchwarning) {
$button = 0;
}
@@ -1234,7 +1218,7 @@
my $required = $newhash{'internal.releaserequired'};
if ($required ne '') {
($switchserver,$switchwarning) =
- &check_release_required($loncaparev,$tcourseid,$trolecode,$required);
+ &Apache::loncommon::check_release_required($loncaparev,$tcourseid,$trolecode,$required);
if ($switchserver || $switchwarning) {
$button = 0;
}
@@ -1759,58 +1743,6 @@
return $is_cc;
}
-sub check_release_required {
- my ($loncaparev,$tcourseid,$trolecode,$required) = @_;
- my ($switchserver,$warning);
- if ($required ne '') {
- my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
- my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
- if ($reqdmajor ne '' && $reqdminor ne '') {
- my $otherserver;
- if (($major eq '' && $minor eq '') ||
- (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
- my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
- my $switchlcrev =
- &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
- $userdomserver);
- my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
- if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
- (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
- my $cdom = $env{'course.'.$tcourseid.'.domain'};
- if ($cdom ne $env{'user.domain'}) {
- my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
- my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
- my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
- my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
- my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
- my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
- my $canhost =
- &Apache::lonnet::can_host_session($env{'user.domain'},
- $coursedomserver,
- $remoterev,
- $udomdefaults{'remotesessions'},
- $defdomdefaults{'hostedsessions'});
-
- if ($canhost) {
- $otherserver = $coursedomserver;
- } else {
- $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$tcourseid.'.internal.releaserequired'}).'<br />'. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
- }
- } else {
- $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$tcourseid.'.internal.releaserequired'}).'<br />'.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
- }
- } else {
- $otherserver = $userdomserver;
- }
- }
- if ($otherserver ne '') {
- $switchserver = 'otherserver='.$otherserver.'&role='.$trolecode;
- }
- }
- }
- return ($switchserver,$warning);
-}
-
sub courselink {
my ($dcdom,$rowtype) = @_;
my $courseform=&Apache::loncommon::selectcourse_link
More information about the LON-CAPA-cvs
mailing list