--- loncom/auth/lonroles.pm 2013/01/04 04:08:34 1.269.2.7 +++ loncom/auth/lonroles.pm 2012/09/04 20:47:46 1.276 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.269.2.7 2013/01/04 04:08:34 raeburn Exp $ +# $Id: lonroles.pm,v 1.276 2012/09/04 20:47:46 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -138,11 +138,10 @@ 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; - + sub redirect_user { my ($r,$title,$url,$msg) = @_; @@ -150,7 +149,6 @@ sub redirect_user { &Apache::loncommon::content_type($r,'text/html'); &Apache::loncommon::no_cache($r); $r->send_http_header; - my $swinfo=&Apache::lonmenu::rawconfig(); # Breadcrumbs my $brcrum = [{'href' => $url, @@ -165,11 +163,6 @@ sub redirect_user { $url=~s/ /\%20/g; $r->print(< -// -

$msg

$end_page ENDREDIR @@ -220,7 +213,7 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); -# -------------------------------------------------- Check if setting hot list +# -------------------------------------------------- Check if setting hot list my $hotlist; if ($env{'form.action'} eq 'verify_and_change_rolespref') { $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r); @@ -602,13 +595,13 @@ ENDENTERKEY if ($env{'request.role.adv'}) { $dest = &Apache::lonenc::unencrypted($dest); if ($destsymb eq '') { - ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/); + ($destsymb) = ($dest =~ /\?symb=([^\&]*)/); $destsymb = &unescape($destsymb); } } } else { if ($destsymb eq '') { - ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]+)/); + ($destsymb) = ($dest =~ /\?symb=([^\&]+)/); $destsymb = &unescape($destsymb); } unless ($env{'request.role.adv'}) { @@ -617,7 +610,7 @@ ENDENTERKEY } if (($checkenc) && ($destsymb ne '')) { my ($encstate,$unencsymb,$res); - $unencsymb = &Apache::lonnet::symbclean($destsymb); + my $unencsymb = &Apache::lonnet::symbclean($destsymb); (undef,undef,$res) = &Apache::lonnet::decode_symb($unencsymb); &Apache::lonnet::symbverify($unencsymb,$res,\$encstate); if ($encstate) { @@ -627,7 +620,7 @@ ENDENTERKEY } } } - unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) { + unless (($dest =~ m{^/enc/}) || ($dest =~ /\?symb=.+___\d+___.+/)) { if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) { my $esc_symb = &escape($destsymb); $dest .= '?symb='.$esc_symb; @@ -758,7 +751,7 @@ function rolesView (caller) { document.rolechoice.display.value = caller; } else { if ((caller == 'doupdate') || (caller == 'requestauthor') || - (caller == 'queued')) { + (caller == 'queued')) { document.rolechoice.state.value = caller; } } @@ -842,7 +835,7 @@ ENDHEADER } if ($hotlist) { $showresult .= $hotlist; - } + } $showresult .= ''; $r->print($showresult); } elsif ($env{'form.state'} eq 'queued') { @@ -867,7 +860,7 @@ ENDHEADER \%sortrole,\%roleclass,\%futureroles,\%timezones,$loncaparev); $refresh = $now; &Apache::lonnet::appenv({'user.refresh.time' => $refresh}); - unless ($env{'user.adv'}) { + unless ($env{'user.adv'}) { if ($countactive > 0) { my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description'); my $esc_dom = &HTML::Entities::encode($env{'user.domain'},'"<>&'); @@ -1663,11 +1656,6 @@ 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; @@ -1695,11 +1683,7 @@ sub adhoc_course_role { $spec .= '/'.$usec; $area .= '/'.$usec; } - 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::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area); &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups); my $adhocstart = $refresh-1; $userroles{'user.role.'.$spec} = $adhocstart.'.'; @@ -2158,6 +2142,7 @@ 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); @@ -2182,23 +2167,21 @@ sub update_session_roles { } } } - 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}) + $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); - } + ($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') { $customprivchg{$rolekey} = $status_in_env; } } @@ -2280,93 +2263,6 @@ 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) { @@ -2399,41 +2295,11 @@ 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)) { - 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'}.'
  • '; + $groupmsg .= '
  • '. + &mt('[_1] with status: [_2].', + $item,$newgroup{$item}).'
  • '; } } if ($groupmsg) { @@ -2446,10 +2312,9 @@ sub update_session_roles { $changemsg .= '
  • '.&mt('New roles'). '
  • '; } @@ -2458,8 +2323,7 @@ sub update_session_roles { &mt('Custom roles with privilege changes'). ''; } @@ -2468,9 +2332,8 @@ sub update_session_roles { &mt('Existing roles with status changes').''. ''; @@ -2480,8 +2343,7 @@ sub update_session_roles { &mt('Existing roles now expired').''. ''; } @@ -2513,22 +2375,10 @@ sub update_session_roles { &mt('Existing course/community groups with status changes').''. '