--- loncom/auth/lonroles.pm 2012/08/27 11:48:24 1.269.2.2
+++ loncom/auth/lonroles.pm 2013/01/01 03:45:50 1.269.2.6
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.269.2.2 2012/08/27 11:48:24 raeburn Exp $
+# $Id: lonroles.pm,v 1.269.2.6 2013/01/01 03:45:50 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -138,6 +138,7 @@ use Apache::lonlocal;
use Apache::lonpageflip();
use Apache::lonnavdisplay();
use Apache::loncoursequeueadmin;
+use Apache::longroup;
use GDBM_File;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities;
@@ -585,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);
+ my $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'}),
@@ -1621,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;
@@ -1648,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.'.';
@@ -2132,21 +2183,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;
}
}
@@ -2228,6 +2281,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.').'
';
}
+ &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);
+ }
if (!@changed_roles || !(keys(%changed_groups))) {
my ($rolesmsg,$groupsmsg);
if (!@changed_roles) {
@@ -2260,11 +2400,42 @@ sub update_session_roles {
if (@changed_roles > 0) {
if (keys(%newgroup) > 0) {
my $groupmsg;
+ my (%curr_groups,%groupdescs,$currcrs);
foreach my $item (sort(keys(%newgroup))) {
if (&is_active_course($item,$refresh,$update,\%roleshash)) {
- $groupmsg .= ''.
- &mt('[_1] with status: [_2].',
- $item,$newgroup{$item}).'';
+ if ($item =~ m{^gr\./($match_domain/$match_courseid)/(\w+)$}) {
+ my ($cdom,$cnum) = split(/\//,$1);
+ my $group = $2;
+ if ($currcrs ne $cdom.'_'.$cnum) {
+ if ($currcrs) {
+ $groupmsg .= '';
+ }
+ $groupmsg .= ''.
+ $env{'course.'.$cdom.'_'.$cnum.'.description'}.'';
+ }
+ my ($cdom,$cnum) = split(/\//,$1);
+ my $group = $2;
+ my $groupdesc;
+ unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') {
+ %{$curr_groups{$cdom.'_'.$cnum}} =
+ &Apache::longroup::coursegroups($cdom,$cnum);
+ }
+ unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') &&
+ ($groupdescs{$cdom.'_'.$cnum}{$group})) {
+
+ my %groupinfo =
+ &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group});
+ $groupdescs{$cdom.'_'.$cnum}{$group} =
+ &unescape($groupinfo{'description'});
+ }
+ $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group};
+ $groupmsg .= '- '.
+ &mt('[_1] with status: [_2].',
+ ''.$groupdesc.'',$newgroup{$item}).'
';
+ }
+ }
+ if ($groupmsg) {
+ $groupmsg .= '
';
}
}
if ($groupmsg) {
@@ -2277,9 +2448,10 @@ sub update_session_roles {
$changemsg .= ''.&mt('New roles').
'';
foreach my $item (sort(keys(%newrole))) {
+ my $desc = &role_desc($item,$update,$refresh,$now);
$changemsg .= '- '.
&mt('[_1] with status: [_2].',
- $item,$newrole{$item}).'
';
+ $desc,$newrole{$item}).'
';
}
$changemsg .= '';
}
@@ -2288,7 +2460,8 @@ sub update_session_roles {
&mt('Custom roles with privilege changes').
'';
foreach my $item (sort(keys(%customprivchg))) {
- $changemsg .= '- '.$item.'
';
+ my $desc = &role_desc($item,$update,$refresh,$now);
+ $changemsg .= '- '.$desc.'
';
}
$changemsg .= '
';
}
@@ -2297,8 +2470,9 @@ sub update_session_roles {
&mt('Existing roles with status changes').''.
'';
foreach my $item (sort(keys(%rolechange))) {
+ my $desc = &role_desc($item,$update,$refresh,$now);
$changemsg .= '- '.
- &mt('[_1] status now: [_2].',$item,
+ &mt('[_1] status now: [_2].',$desc,
$rolechange{$item}).'
';
}
$changemsg .= '
';
@@ -2308,7 +2482,8 @@ sub update_session_roles {
&mt('Existing roles now expired').''.
'';
foreach my $item (sort(keys(%deletedroles))) {
- $changemsg .= '- '.$item.'
';
+ my $desc = &role_desc($item,$update,$refresh,$now);
+ $changemsg .= '- '.$desc.'
';
}
$changemsg .= '
';
}
@@ -2340,10 +2515,22 @@ sub update_session_roles {
&mt('Existing course/community groups with status changes').''.
'';
foreach my $crs (sort(keys(%groupchange))) {
+ my $cid = $crs;
+ $cid=~s{^/}{};
+ $cid=~s{/}{_};
+ my $crsdesc = $env{'course.'.$cid.'.description'};
+ my $cdom = $env{'course.'.$cid.'.domain'};
+ my $cnum = $env{'course.'.$cid.'.num'};
+ my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
+ my %groupdesc;
if (ref($groupchange{$crs}) eq 'HASH') {
- $groupchgmsg .= '- '.&mt('Course/Community: [_1]',''.$crs.'
');
+ $groupchgmsg .= '- '.&mt('Course/Community: [_1]',''.$crsdesc.'
');
foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
- $groupchgmsg .= '- '.&mt('Group: [_1] status now: [_2].',''.$group.'',$groupchange{$crs}{$group}).'
';
+ unless ($groupdesc{$group}) {
+ my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$group});
+ $groupdesc{$group} = &unescape($groupinfo{'description'});
+ }
+ $groupchgmsg .= '- '.&mt('Group: [_1] status now: [_2].',''.$groupdesc{$group}.'',$groupchange{$crs}{$group}).'
';
}
$groupchgmsg .= '
';
}
@@ -2359,94 +2546,61 @@ sub update_session_roles {
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;
- }
- }
+ return $msg;
+}
+
+sub role_desc {
+ my ($item,$update,$refresh,$now) = @_;
+ my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$twhere,
+ $trole,$tremark);
+ &Apache::lonnet::role_status('user.role.'.$item,$update,$refresh, $now,\$role,\$where, \$trolecode,
+ \$tstatus,\$tstart,\$tend);
+ if ($role =~ /^cr\//) {
+ my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
+ $tremark = &mt('Customrole defined by [_1].',$rauthor.':'.$rdomain);
+ }
+ $trole=Apache::lonnet::plaintext($role);
+ my ($tdom,$trest,$tsection)=
+ split(/\//,Apache::lonnet::declutter($where));
+ if (($role eq 'ca') || ($role eq 'aa')) {
+ my $home = &Apache::lonnet::homeserver($trest,$tdom);
+ $home = &Apache::lonnet::hostname($home);
+ $twhere=&mt('User').': '.$trest.' '.&mt('Domain').
+ ': '.$tdom.' '.&mt('Server').': '.$home;
+ } elsif ($role eq 'au') {
+ my $home = &Apache::lonnet::homeserver
+ ($env{'user.name'},$env{'user.domain'});
+ $home = &Apache::lonnet::hostname($home);
+ $twhere=&mt('Domain').': '.$tdom.' '.&mt('Server').
+ ': '.$home;
+ } elsif ($trest) {
+ my $tcourseid=$tdom.'_'.$trest;
+ my $crstype = &Apache::loncommon::course_type($tcourseid);
+ $trole = &Apache::lonnet::plaintext($role,$crstype,$tcourseid);
+ if ($env{'course.'.$tcourseid.'.description'}) {
+ $twhere=$env{'course.'.$tcourseid.'.description'};
+ } else {
+ my %newhash=&Apache::lonnet::coursedescription($tcourseid);
+ if (%newhash) {
+ $twhere=$newhash{'description'};
+ } else {
+ $twhere=&mt('Currently not available');
}
}
- 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 ($tsection) {
+ $twhere.= ' '.&mt('Section').': '.$tsection;
}
- 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 ($role ne 'st') {
+ $twhere.= ' '.&mt('Domain').': '.$tdom;
}
+ } elsif ($tdom) {
+ $twhere = &mt('Domain').': '.$tdom;
}
- if (keys(%newenv)) {
- &Apache::lonnet::appenv(\%newenv);
+ my $output = "$trole -- $twhere";
+ if ($tremark) {
+ $output .= '
'.$tremark;
}
- return $msg;
+ return $output;
}
sub curr_role_status {
@@ -2511,19 +2665,15 @@ sub is_active_course {
sub get_roles_functions {
my ($rolescount) = @_;
my @links;
- if ($env{'user.adv'}) {
- if ($env{'form.display'} eq 'showall') {
- push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired roles')]);
- } else {
- push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired roles')]);
- }
- }
push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
if ($env{'environment.canrequest.author'}) {
unless (&Apache::loncoursequeueadmin::is_active_author()) {
push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
}
}
+ if (($rolescount > 3) || ($env{'environment.recentroles'})) {
+ push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
+ }
if (&Apache::lonmenu::check_for_rcrs()) {
push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
}
@@ -2532,10 +2682,13 @@ sub get_roles_functions {
} else {
push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
}
- if (($rolescount > 3) || ($env{'environment.recentroles'})) {
- push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
+ if ($env{'user.adv'}) {
+ if ($env{'form.display'} eq 'showall') {
+ push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired roles')]);
+ } else {
+ push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired roles')]);
+ }
}
-
my $funcs = &Apache::lonhtmlcommon::start_funclist();
foreach my $link (@links) {
$funcs .= &Apache::lonhtmlcommon::add_item_funclist(