[LON-CAPA-cvs] cvs: loncom(version_2_9_X) /lonnet/perl lonnet.pm

raeburn raeburn@source.lon-capa.org
Fri, 21 May 2010 22:09:49 -0000


raeburn		Fri May 21 22:09:49 2010 EDT

  Modified files:              (Branch: version_2_9_X)
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Backport 1.1063, 1.1064.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1056.2.2 loncom/lonnet/perl/lonnet.pm:1.1056.2.3
--- loncom/lonnet/perl/lonnet.pm:1.1056.2.2	Fri Mar 26 21:27:41 2010
+++ loncom/lonnet/perl/lonnet.pm	Fri May 21 22:09:48 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1056.2.2 2010/03/26 21:27:41 raeburn Exp $
+# $Id: lonnet.pm,v 1.1056.2.3 2010/05/21 22:09:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4028,23 +4028,36 @@
 }
 
 sub set_userprivs {
-    my ($userroles,$allroles,$allgroups) = @_; 
+    my ($userroles,$allroles,$allgroups,$groups_roles) = @_; 
     my $author=0;
     my $adv=0;
     my %grouproles = ();
     if (keys(%{$allgroups}) > 0) {
+        my @groupkeys;
         foreach my $role (keys(%{$allroles})) {
-            my ($trole,$area,$sec,$extendedarea);
-            if ($role =~ m-^(\w+|cr/$match_domain/$match_username/\w+)\.(/$match_domain/$match_courseid)(/?\w*)\.-) {
-                $trole = $1;
-                $area = $2;
-                $sec = $3;
-                $extendedarea = $area.$sec;
-                if (exists($$allgroups{$area})) {
-                    foreach my $group (keys(%{$$allgroups{$area}})) {
-                        my $spec = $trole.'.'.$extendedarea;
-                        $grouproles{$spec.'.'.$area.'/'.$group} = 
-                                                $$allgroups{$area}{$group};
+            push(@groupkeys,$role);
+        }
+        if (ref($groups_roles) eq 'HASH') {
+            foreach my $key (keys(%{$groups_roles})) {
+                unless (grep(/^\Q$key\E$/,@groupkeys)) {
+                    push(@groupkeys,$key);
+                }
+            }
+        }
+        if (@groupkeys > 0) {
+            foreach my $role (@groupkeys) {
+                my ($trole,$area,$sec,$extendedarea);
+                if ($role =~ m-^(\w+|cr/$match_domain/$match_username/\w+)\.(/$match_domain/$match_courseid)(/?\w*)\.-) {
+                    $trole = $1;
+                    $area = $2;
+                    $sec = $3;
+                    $extendedarea = $area.$sec;
+                    if (exists($$allgroups{$area})) {
+                        foreach my $group (keys(%{$$allgroups{$area}})) {
+                            my $spec = $trole.'.'.$extendedarea;
+                            $grouproles{$spec.'.'.$area.'/'.$group} = 
+                                                  $$allgroups{$area}{$group};
+                        }
                     }
                 }
             }
@@ -4091,26 +4104,58 @@
                 if ($$tstart<$now) {
                     if ($$tstart && $$tstart>$refresh) {
                         if (($$where ne '') && ($$role ne '')) {
-                            my (%allroles,%allgroups,$group_privs);
+                            my (%allroles,%allgroups,$group_privs,
+                                %groups_roles,@rolecodes);
                             my %userroles = (
                                 'user.role.'.$$role.'.'.$$where => $$tstart.'.'.$$tend
                             );
+                            @rolecodes = ('cm');
                             my $spec=$$role.'.'.$$where;
                             my ($tdummy,$tdomain,$trest)=split(/\//,$$where);
                             if ($$role =~ /^cr\//) {
                                 &custom_roleprivs(\%allroles,$$role,$tdomain,$trest,$spec,$$where);
+                                push(@rolecodes,'cr');
                             } elsif ($$role eq 'gr') {
+                                push(@rolecodes,$$role);
                                 my %rolehash = &get('roles',[$$where.'_'.$$role],$env{'user.domain'},
                                                     $env{'user.name'});
-                                my $trole = split('_',$rolehash{$$where.'_'.$$role},1);
+                                my ($trole) = split('_',$rolehash{$$where.'_'.$$role},2);
                                 (undef,my $group_privs) = split(/\//,$trole);
                                 $group_privs = &unescape($group_privs);
                                 &group_roleprivs(\%allgroups,$$where,$group_privs,$$tend,$$tstart);
+                                my %course_roles = &get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',['active'],['cc','co','in','ta','ep','ad','st','cr'],[$tdomain],1);
+                                if (keys(%course_roles) > 0) {
+                                    my ($tnum) = ($trest =~ /^($match_courseid)/);
+                                    if ($tdomain ne '' && $tnum ne '') {
+                                        foreach my $key (keys(%course_roles)) {
+                                            if ($key =~ /^\Q$tnum\E:\Q$tdomain\E:([^:]+):?([^:]*)/) {
+                                                my $crsrole = $1;
+                                                my $crssec = $2;
+                                                if ($crsrole =~ /^cr/) {
+                                                    unless (grep(/^cr$/,@rolecodes)) {
+                                                        push(@rolecodes,'cr');
+                                                    }
+                                                } else {
+                                                    unless(grep(/^\Q$crsrole\E$/,@rolecodes)) {
+                                                        push(@rolecodes,$crsrole);
+                                                    }
+                                                }
+                                                my $rolekey = $crsrole.'./'.$tdomain.'/'.$tnum;
+                                                if ($crssec ne '') {
+                                                    $rolekey .= '/'.$crssec;
+                                                }
+                                                $rolekey .= './';
+                                                $groups_roles{$rolekey} = \@rolecodes;
+                                            }
+                                        }
+                                    }
+                                }
                             } else {
+                                push(@rolecodes,$$role);
                                 &standard_roleprivs(\%allroles,$$role,$tdomain,$spec,$trest,$$where);
                             }
-                            my ($author,$adv)= &set_userprivs(\%userroles,\%allroles,\%allgroups);
-                            &appenv(\%userroles,[$$role,'cm']);
+                            my ($author,$adv)= &set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
+                            &appenv(\%userroles,\@rolecodes);
                             &log($env{'user.domain'},$env{'user.name'},$env{'user.home'},"Role ".$role);
                         }
                     }