--- loncom/auth/lonroles.pm 2012/02/08 00:22:15 1.256.2.6.2.1
+++ loncom/auth/lonroles.pm 2014/05/05 11:37:41 1.256.2.8
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.256.2.6.2.1 2012/02/08 00:22:15 raeburn Exp $
+# $Id: lonroles.pm,v 1.256.2.8 2014/05/05 11:37:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -57,7 +57,8 @@ course they should act on, etc. Both in
handler determines via C's C<&allowed> function that a certain
action is not allowed, C is used as error handler. This
allows the user to select another role which may have permission to do
-what they were trying to do.
+what they were trying to do. C can also be accessed via the
+B button in the Remote Control.
=begin latex
@@ -217,33 +218,12 @@ sub handler {
my $now=time;
my $then=$env{'user.login.time'};
my $refresh=$env{'user.refresh.time'};
- my $update=$env{'user.update.time'};
if (!$refresh) {
$refresh = $then;
}
- if (!$update) {
- $update = $then;
- }
-
-# -------------------------------------------------------- Check for new roles
- my $updateresult;
- if ($env{'form.doupdate'}) {
- my $show_course=&Apache::loncommon::show_course();
- my $checkingtxt;
- if ($show_course) {
- $checkingtxt = &mt('Checking for new courses ...');
- } else {
- $checkingtxt = &mt('Checking for new roles ...');
- }
- $updateresult = ''.$checkingtxt.'';
- $updateresult .= &update_session_roles();
- &Apache::lonnet::appenv({'user.update.time' => $now});
- $update = $now;
- }
-
my $envkey;
my %dcroles = ();
- my $numdc = &check_fordc(\%dcroles,$update,$then);
+ my $numdc = &check_fordc(\%dcroles,$then);
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
@@ -263,13 +243,13 @@ sub handler {
if (defined($env{'user.role.'.$env{'form.switchrole'}})) {
my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.switchrole'}});
if (!$end || $end > $now) {
- if (!$start || $start < $update) {
+ if (!$start || $start < $refresh) {
$switch_is_active = 1;
}
}
}
unless ($switch_is_active) {
- &adhoc_course_role($refresh,$update,$then);
+ &adhoc_course_role($refresh,$then);
}
}
my %temp=('logout_'.$env{'request.course.id'} => time);
@@ -291,7 +271,7 @@ sub handler {
($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
if ($dcroles{$domain}) {
&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
- $update,$refresh,$now,$ccrole);
+ $then,$refresh,$now,$ccrole);
}
last;
}
@@ -331,7 +311,7 @@ sub handler {
if ($dcroles{$domain}) {
my ($server_status,$home) = &check_author_homeserver($user,$domain);
if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
- &Apache::lonnet::check_adhoc_privs($domain,$user,$update,
+ &Apache::lonnet::check_adhoc_privs($domain,$user,$then,
$refresh,$now,'ca');
if ($server_status eq 'switchserver') {
my $trolecode = 'ca./'.$domain.'/'.$user;
@@ -353,7 +333,7 @@ sub handler {
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,
+ &Apache::lonnet::role_status($envkey,$then,$refresh,$now,\$role,\$where,
\$trolecode,\$tstatus,\$tstart,\$tend);
if ($env{'form.'.$trolecode}) {
if ($tstatus eq 'is') {
@@ -695,13 +675,6 @@ function enterrole (thisform,rolecode,bu
alert('$standby');
}
}
-
-function setToUpdate(thisform) {
- thisform.doupdate.value='1';
- thisform.selectrole.value='';
- thisform.submit();
-}
-
// ]]>
ENDHEADER
@@ -764,14 +737,13 @@ ENDHEADER
}
# -------------------------------------------------------- Choice or no choice?
if ($nochoose) {
- $r->print("".&mt('Sorry ...')."
\n".
- &mt('This action is currently not authorized.').''.
- &Apache::loncommon::end_page());
- return OK;
+ $r->print("".&mt('Sorry ...')."
\n".
+ &mt('This action is currently not authorized.').''.
+ &Apache::loncommon::end_page());
+ return OK;
} else {
- $r->print($updateresult);
if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
- $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
+ $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
}
$r->print('
';
- }
- } elsif ($currrole_expired) {
- $msg .= '';
- if (&Apache::loncommon::show_course()) {
- $msg .= &mt('Your role in the current course has expired.');
- } else {
- $msg .= &mt('Your current role has expired.');
- }
- $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.').'
';
- }
- if (!@changed_roles || !(keys(%changed_groups))) {
- my ($rolesmsg,$groupsmsg);
- if (!@changed_roles) {
- if (&Apache::loncommon::show_course()) {
- $rolesmsg = &mt('No new courses or communities');
- } else {
- $rolesmsg = &mt('No role changes');
- }
- }
- if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
- $groupsmsg = &mt('No changes in course/community groups');
- }
- if (!@changed_roles && !(keys(%changed_groups))) {
- if (($msg ne '') || ($groupsmsg ne '')) {
- $msg .= '';
- if ($rolesmsg) {
- $msg .= '- '.$rolesmsg.'
';
- }
- if ($groupsmsg) {
- $msg .= '- '.$groupsmsg.'
';
- }
- $msg .= '
';
- } else {
- $msg = ' '.$rolesmsg.'
';
- }
- return $msg;
- }
- }
- my $changemsg;
- if (@changed_roles > 0) {
- if (keys(%newgroup) > 0) {
- my $groupmsg;
- foreach my $item (sort(keys(%newgroup))) {
- if (&is_active_course($item,$refresh,$update,\%roleshash)) {
- $groupmsg .= ''.
- &mt('[_1] with status: [_2].',
- $item,$newgroup{$item}).'';
- }
- }
- if ($groupmsg) {
- $changemsg .= ''.
- &mt('Courses with new groups').''.
- '';
- }
- }
- if (keys(%newrole) > 0) {
- $changemsg .= ''.&mt('New roles').
- '';
- foreach my $item (sort(keys(%newrole))) {
- $changemsg .= '- '.
- &mt('[_1] with status: [_2].',
- $item,$newrole{$item}).'
';
- }
- $changemsg .= '
';
- }
- if (keys(%customprivchg) > 0) {
- $changemsg .= ''.
- &mt('Custom roles with privilege changes').
- '';
- foreach my $item (sort(keys(%customprivchg))) {
- $changemsg .= '- '.$item.'
';
- }
- $changemsg .= '
';
- }
- if (keys(%rolechange) > 0) {
- $changemsg .= ''.
- &mt('Existing roles with status changes').''.
- '';
- foreach my $item (sort(keys(%rolechange))) {
- $changemsg .= '- '.
- &mt('[_1] status now: [_2].',$item,
- $rolechange{$item}).'
';
- }
- $changemsg .= '
';
- }
- if (keys(%deletedroles) > 0) {
- $changemsg .= ''.
- &mt('Existing roles deleted').''.
- '';
- foreach my $item (sort(keys(%deletedroles))) {
- $changemsg .= '- '.$item.'
';
- }
- $changemsg .= '
';
- }
- }
- if ((keys(%changed_groups) > 0) || (keys(%groupchange) > 0)) {
- my $groupchgmsg;
- foreach my $key (sort(keys(%changed_groups))) {
- my $crs = 'gr/'.$key;
- $crs =~ s/_/\//;
- if (&is_active_course($crs,$refresh,$update,\%roleshash)) {
- if (ref($changed_groups{$key}) eq 'HASH') {
- my @showgroups;
- foreach my $group (sort(keys(%{$changed_groups{$key}}))) {
- if ($changed_groups{$key}{$group} eq 'active') {
- push(@showgroups,$group);
- }
- }
- if (@showgroups > 0) {
- $groupchgmsg .= ''.
- &mt('Course: [_1], groups: [_2].',$key,
- join(', ',@showgroups)).
- '';
- }
- }
- }
- }
- if (keys(%groupchange) > 0) {
- $groupchgmsg .= ''.
- &mt('Existing course/community groups with status changes').''.
- '';
- foreach my $crs (sort(keys(%groupchange))) {
- if (ref($groupchange{$crs}) eq 'HASH') {
- $groupchgmsg .= '- '.&mt('Course/Community: [_1]',''.$crs.'
');
- foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
- $groupchgmsg .= '- '.&mt('Group: [_1] status now: [_2].',''.$group.'',$groupchange{$crs}{$group}).'
';
- }
- $groupchgmsg .= '
';
- }
- }
- $groupchgmsg .= '
';
- }
- if ($groupchgmsg) {
- $changemsg .= ''.
- &mt('Courses with changes in groups').''.
- '';
- }
- }
- if ($changemsg) {
- $msg .= '';
- }
- &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
- my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
- $curr_author = $env{'user.author'};
- if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
- ($env{'request.role'} =~/^aa/)) {
- $curr_role_author=1;
- }
- $curr_is_adv = $env{'user.adv'};
- $curr_role_adv = $env{'request.role.adv'};
- if (keys(%userroles) > 0) {
- foreach my $role (@changed_roles) {
- unless(grep(/^\Q$role\E$/,@rolecodes)) {
- push(@rolecodes,$role);
- }
- }
- unless(grep(/^\Qcm\E$/,@rolecodes)) {
- push(@rolecodes,'cm');
- }
- &Apache::lonnet::appenv(\%userroles,\@rolecodes);
- }
- my %newenv;
- if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
- unless ($curr_is_adv) {
- $newenv{'user.adv'} = 1;
- }
- } elsif ($curr_is_adv && !$curr_role_adv) {
- &Apache::lonnet::delenv('user.adv');
- }
- my %authorroleshash =
- &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
- if (keys(%authorroleshash)) {
- unless ($curr_author) {
- $newenv{'user.author'} = 1;
- }
- } elsif ($curr_author && !$curr_role_author) {
- &Apache::lonnet::delenv('user.author');
- }
- if ($env{'request.course.id'}) {
- my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- my (@activecrsgroups,$crsgroupschanged);
- if ($env{'request.course.groups'}) {
- @activecrsgroups = split(/:/,$env{'request.course.groups'});
- foreach my $item (keys(%deletedroles)) {
- if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
- if (grep(/^\Q$1\E$/,@activecrsgroups)) {
- $crsgroupschanged = 1;
- last;
- }
- }
- }
- }
- unless ($crsgroupschanged) {
- foreach my $item (keys(%newgroup)) {
- if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
- if ($newgroup{$item} eq 'active') {
- $crsgroupschanged = 1;
- last;
- }
- }
- }
- }
- if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
- (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
- ($crsgroupschanged)) {
- my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
- ['active'],['gr'],[$cdom],1);
- my @activegroups;
- foreach my $item (keys(%grouproles)) {
- next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
- my $group;
- my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
- if ($remainder =~ /:/) {
- (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
- } else {
- $group = $remainder;
- }
- if ($group ne '') {
- push(@activegroups,$group);
- }
- }
- $newenv{'request.course.groups'} = join(':',@activegroups);
- }
- }
- if (keys(%newenv)) {
- &Apache::lonnet::appenv(\%newenv);
- }
- return $msg;
-}
-
-sub curr_role_status {
- my ($start,$end,$refresh,$update) = @_;
- if (($start) && ($start<0)) { return 'deleted' };
- my $status = 'active';
- if (($end) && ($end<=$update)) {
- $status = 'previous';
- }
- if (($start) && ($refresh<$start)) {
- $status = 'future';
- }
- return $status;
-}
-
-sub gather_roleprivs {
- my ($allroles,$allgroups,$userroles,$area,$role,$tstart,$tend,$status) = @_;
- return unless ((ref($allroles) eq 'HASH') && (ref($allgroups) eq 'HASH') && (ref($userroles) eq 'HASH'));
- if (($area ne '') && ($role ne '')) {
- &Apache::lonnet::userrolelog($role,$env{'user.name'},$env{'user.domain'},
- $area,$tstart,$tend);
- my $spec=$role.'.'.$area;
- $userroles->{'user.role.'.$spec} = $tstart.'.'.$tend;
- my ($tdummy,$tdomain,$trest)=split(/\//,$area);
- if ($status eq 'active') {
- if ($role =~ /^cr\//) {
- &Apache::lonnet::custom_roleprivs($allroles,$role,$tdomain,$trest,$spec,$area);
- } elsif ($role eq 'gr') {
- my %rolehash = &Apache::lonnet::get('roles',[$area.'_'.$role],
- $env{'user.domain'},
- $env{'user.name'});
- my ($trole) = split(/_/,$rolehash{$area.'_'.$role},2);
- (undef,my $group_privs) = split(/\//,$trole);
- $group_privs = &unescape($group_privs);
- &Apache::lonnet::group_roleprivs($allgroups,$area,$group_privs,$tend,$tstart);
- } else {
- &Apache::lonnet::standard_roleprivs($allroles,$role,$tdomain,$spec,$trest,$area);
- }
- }
- }
- return;
-}
-
-sub is_active_course {
- my ($rolekey,$refresh,$update,$roleshashref) = @_;
- return unless(ref($roleshashref) eq 'HASH');
- my ($role,$cdom,$cnum) = split(/\//,$rolekey);
- my $is_active;
- foreach my $key (keys(%{$roleshashref})) {
- if ($key =~ /^\Q$cnum\E:\Q$cdom\E:/) {
- my ($tstart,$tend) = split(/:/,$roleshashref->{$key});
- my $status = &curr_role_status($tstart,$tend,$refresh,$update);
- if ($status eq 'active') {
- $is_active = 1;
- last;
- }
- }
- }
- return $is_active;
-}
-
1;
__END__
@@ -2545,7 +1849,8 @@ course they should act on, etc. Both in
handler determines via C's C<&allowed> function that a certain
action is not allowed, C is used as error handler. This
allows the user to select another role which may have permission to do
-what they were trying to do.
+what they were trying to do. C can also be accessed via the
+B button in the Remote Control.
=begin latex