--- loncom/auth/lonroles.pm 2012/08/16 17:02:46 1.274
+++ loncom/auth/lonroles.pm 2014/02/23 19:06:18 1.296
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.274 2012/08/16 17:02:46 raeburn Exp $
+# $Id: lonroles.pm,v 1.296 2014/02/23 19:06:18 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -138,10 +138,12 @@ use Apache::lonlocal;
use Apache::lonpageflip();
use Apache::lonnavdisplay();
use Apache::loncoursequeueadmin;
+use Apache::longroup;
+use Apache::lonrss;
use GDBM_File;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities;
-
+
sub redirect_user {
my ($r,$title,$url,$msg) = @_;
@@ -286,13 +288,15 @@ sub handler {
"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) {
+ foreach my $envkey (keys(%env)) {
# Is this an ad-hoc Coordinator role?
if (my ($ccrole,$domain,$coursenum) =
($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
if ($dcroles{$domain}) {
- &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
- $update,$refresh,$now,$ccrole);
+ if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
+ $update,$refresh,$now,$ccrole)) {
+ &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});
+ }
}
last;
}
@@ -307,6 +311,7 @@ sub handler {
my $trolecode = 'au./'.$domain.'/';
my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
$r->internal_redirect($switchserver);
+ return OK;
}
last;
}
@@ -318,6 +323,7 @@ sub handler {
my $trolecode = 'ca./'.$domain.'/'.$user;
my $switchserver = '/adm/switchserver?otherserver='.$home.'&role='.$trolecode;
$r->internal_redirect($switchserver);
+ return OK;
}
last;
}
@@ -339,6 +345,7 @@ sub handler {
my $switchserver = '/adm/switchserver?'
.'otherserver='.$home.'&role='.$trolecode;
$r->internal_redirect($switchserver);
+ return OK;
}
} else {
delete($env{$envkey});
@@ -351,7 +358,7 @@ sub handler {
}
}
- foreach $envkey (keys %env) {
+ foreach $envkey (keys(%env)) {
next if ($envkey!~/^user\.role\./);
my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
&Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
@@ -515,14 +522,37 @@ ENDENTERKEY
my $msg;
my ($furl,$ferr)=
&Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+ unless ($ferr) {
+ unless (($env{'form.switchrole'}) ||
+ ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) {
+ &Apache::lonnet::put('nohist_crslastlogin',
+ {$env{'user.name'}.':'.$env{'user.domain'}.
+ ':'.$csec.':'.$role => $now},$cdom,$cnum);
+ }
+ my ($feeds,$syllabus_time);
+ &Apache::lonrss::advertisefeeds($cnum,$cdom,undef,\$feeds);
+ &Apache::lonnet::appenv({'request.course.feeds' => $feeds});
+ &Apache::lonnet::get_numsuppfiles($cnum,$cdom,1);
+ unless ($env{'course.'.$cdom.'_'.$cnum.'.updatedsyllabus'}) {
+ unless (($env{'course.'.$cdom.'_'.$cnum.'.externalsyllabus'}) ||
+ ($env{'course.'.$cdom.'_'.$cnum.'.uploadedsyllabus'})) {
+ my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
+ $syllabus_time = $syllabus{'uploaded.lastmodified'};
+ if ($syllabus_time) {
+ &Apache::lonnet::appenv({'request.course.syllabustime' => $syllabus_time});
+ }
+ }
+ }
+ }
if (($env{'form.orgurl'}) &&
- ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
+ ($env{'form.orgurl'}!~/^\/adm\/flip/) &&
+ ($env{'form.orgurl'} ne '/adm/roles')) {
my $dest=$env{'form.orgurl'};
if ($env{'form.symb'}) {
if ($dest =~ /\?/) {
$dest .= '&';
} else {
- $dest .= '?'
+ $dest .= '?';
}
$dest .= 'symb='.$env{'form.symb'};
}
@@ -571,11 +601,52 @@ ENDENTERKEY
$furl = "/adm/helper/course.initialization.helper";
# Send the user to the course they selected
} elsif ($env{'request.course.id'}) {
- if ($env{'form.destinationurl'}) {
- my $dest = $env{'form.destinationurl'};
- if ($env{'form.destsymb'} ne '') {
- my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
- $dest .= '?symb='.$esc_symb;
+ my ($dest,$destsymb,$checkenc);
+ $dest = $env{'form.destinationurl'};
+ $destsymb = $env{'form.destsymb'};
+ if ($dest ne '') {
+ if ($env{'form.switchrole'}) {
+ if ($destsymb ne '') {
+ if ($destsymb !~ m{^/enc/}) {
+ unless ($env{'request.role.adv'}) {
+ $checkenc = 1;
+ }
+ }
+ }
+ if ($dest =~ m{^/enc/}) {
+ if ($env{'request.role.adv'}) {
+ $dest = &Apache::lonenc::unencrypted($dest);
+ if ($destsymb eq '') {
+ ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/);
+ $destsymb = &unescape($destsymb);
+ }
+ }
+ } else {
+ if ($destsymb eq '') {
+ ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]+)/);
+ $destsymb = &unescape($destsymb);
+ }
+ unless ($env{'request.role.adv'}) {
+ $checkenc = 1;
+ }
+ }
+ if (($checkenc) && ($destsymb ne '')) {
+ my ($encstate,$unencsymb,$res);
+ $unencsymb = &Apache::lonnet::symbclean($destsymb);
+ (undef,undef,$res) = &Apache::lonnet::decode_symb($unencsymb);
+ &Apache::lonnet::symbverify($unencsymb,$res,\$encstate);
+ if ($encstate) {
+ if (($dest ne '') && ($dest !~ m{^/enc/})) {
+ $dest=&Apache::lonenc::encrypted($dest);
+ }
+ }
+ }
+ }
+ unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) {
+ if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) {
+ my $esc_symb = &escape($destsymb);
+ $dest .= '?symb='.$esc_symb;
+ }
}
&redirect_user($r, &mt('Entering [_1]',
$env{'course.'.$courseid.'.description'}),
@@ -622,7 +693,7 @@ ENDENTERKEY
$redirect_url .= $where;
}
$redirect_url .= '/';
- &redirect_user($r,&mt('Entering Construction Space'),
+ &redirect_user($r,&mt('Entering Authoring Space'),
$redirect_url);
return OK;
}
@@ -654,11 +725,13 @@ ENDENTERKEY
my $crumbtext = 'User Roles';
my $pagetitle = 'My Roles';
my $recent = &mt('Recent Roles');
+ my $standby = &mt('Role selected. Please stand by.');
my $show_course=&Apache::loncommon::show_course();
if ($show_course) {
$crumbtext = 'Courses';
$pagetitle = 'My Courses';
$recent = &mt('Recent Courses');
+ $standby = &mt('Course selected. Please stand by.');
}
my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
@@ -668,7 +741,6 @@ ENDENTERKEY
my $swinfo=&Apache::lonmenu::rawconfig();
my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
my $funcs = &get_roles_functions($showcount);
- my $standby=&mt('Role selected. Please stand by.');
$standby=~s/\n/\\n/g;
my $noscript='
'.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'
'.&mt('As this is not the case, most functionality in the system will be unavailable.').'
';
@@ -817,11 +889,13 @@ ENDHEADER
my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&');
$r->print(
'
'
- .&mt('[_1]Visit the [_2]Course/Community Catalog[_3]'
- .' to view all [_4] LON-CAPA courses and communities.'
+ .&mt('[_1]Visit the [_2]Course/Community Catalog[_3][_4]'
+ .' to view all [_5] LON-CAPA courses and communities.'
,''
,''
- ,'',$domdesc)
+ ,''
+ ,''
+ ,'"'.$domdesc.'"')
.'
'
.&mt('If a course or community is [_1]not[_2] in your list of current courses and communities below,'
.' you may be able to enroll if self-enrollment is permitted.'
@@ -1086,7 +1160,7 @@ sub gather_roles {
}
#next if ($home eq 'no_host');
$home = &Apache::lonnet::hostname($home);
- $ttype='Construction Space';
+ $ttype='Authoring Space';
$twhere=&mt('User').': '.$trest.'
'.&mt('Domain').
': '.$tdom.'
'.
' '.&mt('Server').': '.$home;
@@ -1105,7 +1179,7 @@ sub gather_roles {
}
#next if ($home eq 'no_host');
$home = &Apache::lonnet::hostname($home);
- $ttype='Construction Space';
+ $ttype='Authoring Space';
$twhere=&mt('Domain').': '.$tdom.'
'.&mt('Server').
': '.$home;
$env{'course.'.$tdom.'_'.$trest.'.description'}='ca';
@@ -1278,7 +1352,7 @@ sub roletable_headers {
}
sub roletypes {
- my @types = ('Domain','Construction Space','Course','Community','Unavailable','System');
+ my @types = ('Domain','Authoring Space','Course','Community','Unavailable','System');
return @types;
}
@@ -1417,7 +1491,7 @@ sub privileges_info {
my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
if ($trest) {
if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
- $ttype='Construction Space';
+ $ttype='Authoring Space';
$twhere='User: '.$trest.', Domain: '.$tdom;
} else {
$ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
@@ -1607,6 +1681,11 @@ sub adhoc_course_role {
$setprivs = 1;
}
}
+ unless ($setprivs) {
+ if (!exists($env{'user.priv.'.$env{'form.switchrole'}.'./'})) {
+ $setprivs = 1;
+ }
+ }
if ($setprivs) {
if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
my $role = $1;
@@ -1634,7 +1713,11 @@ sub adhoc_course_role {
$spec .= '/'.$usec;
$area .= '/'.$usec;
}
- &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
+ if ($role =~ /^cr/) {
+ &Apache::lonnet::custom_roleprivs(\%newrole,$role,$cdom,$cnum,$spec,$area);
+ } else {
+ &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
+ }
&Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups);
my $adhocstart = $refresh-1;
$userroles{'user.role.'.$spec} = $adhocstart.'.';
@@ -2093,7 +2176,6 @@ sub update_session_roles {
my $status_in_db =
&curr_role_status($tstart,$tend,$refresh,$now);
my ($rdummy,$rest) = split(/\//,$role,2);
- my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
my %currpriv;
unless (exists($crprivs{$rest})) {
my ($rdomain,$rauthor,$rrole)=split(/\//,$rest);
@@ -2118,21 +2200,23 @@ sub update_session_roles {
}
}
}
- $currpriv{sys} = $env{"user.priv.$rolekey./"};
- $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
- $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
- if (keys(%crprivs)) {
- if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
- ($crprivs{$rest}{dom} ne $currpriv{dom})
+ my $status_in_env =
+ &curr_role_status($currstart,$currend,$refresh,$update);
+ if ($status_in_env eq 'active') {
+ $currpriv{sys} = $env{"user.priv.$rolekey./"};
+ $currpriv{dom} = $env{"user.priv.$rolekey./$udom/"};
+ $currpriv{crs} = $env{"user.priv.$rolekey.$where"};
+ if (keys(%crprivs)) {
+ if (($crprivs{$rest}{sys} ne $currpriv{sys}) ||
+ ($crprivs{$rest}{dom} ne $currpriv{dom})
||
- ($crprivs{$rest}{crs} ne $currpriv{crs})) {
- &gather_roleprivs(\%allroles,\%allgroups,\%userroles,$where,$role,$tstart,$tend,$status_in_db);
- unless (grep(/^\Q$role\E$/,@changed_roles)) {
- push(@changed_roles,$role);
- }
- my $status_in_env =
- &curr_role_status($currstart,$currend,$refresh,$update);
- if ($status_in_env eq 'active') {
+ ($crprivs{$rest}{crs} ne $currpriv{crs})) {
+ &gather_roleprivs(\%allroles,\%allgroups,
+ \%userroles,$where,$role,
+ $tstart,$tend,$status_in_db);
+ unless (grep(/^\Q$role\E$/,@changed_roles)) {
+ push(@changed_roles,$role);
+ }
$customprivchg{$rolekey} = $status_in_env;
}
}
@@ -2214,6 +2298,93 @@ sub update_session_roles {
}
$msg .= '
'.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'
'.&mt('Author role request').'
';
if ($status eq 'approval') {
- $output .= &mt('A request for authoring space submitted on [_1] is awaiting approval',
+ $output .= &mt('A request for Authoring Space submitted on [_1] is awaiting approval',
&Apache::lonlocal::locallocaltime($timestamp));
} elsif ($status eq 'approved') {
my %roleshash =