--- loncom/auth/lonroles.pm 2012/08/19 03:11:43 1.275
+++ loncom/auth/lonroles.pm 2013/05/06 16:16:03 1.283
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.275 2012/08/19 03:11:43 raeburn Exp $
+# $Id: lonroles.pm,v 1.283 2013/05/06 16:16:03 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) = @_;
@@ -522,6 +524,11 @@ ENDENTERKEY
&Apache::lonnet::put('nohist_crslastlogin',
{$env{'user.name'}.':'.$env{'user.domain'}.
':'.$csec.':'.$role => $now},$cdom,$cnum);
+ my $feeds;
+ &Apache::lonrss::advertisefeeds($cnum,$cdom,undef,\$feeds);
+ &Apache::lonnet::appenv(
+ {'course.'.$cdom.'_'.$cnum.'.feeds' => $feeds}
+ );
}
if (($env{'form.orgurl'}) &&
($env{'form.orgurl'}!~/^\/adm\/flip/)) {
@@ -579,11 +586,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'}),
@@ -1615,6 +1663,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;
@@ -1642,7 +1695,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.'.';
@@ -2101,7 +2158,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);
@@ -2126,21 +2182,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;
}
}
@@ -2222,6 +2280,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.').'