[LON-CAPA-cvs] cvs: loncom /interface loncoursegroups.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Thu, 18 May 2006 22:13:49 -0000


raeburn		Thu May 18 18:13:49 2006 EDT

  Modified files:              
    /loncom/interface	loncoursegroups.pm 
  Log:
  Replace _all with all (reserved word) for all sections in choose membership filter.  Members were being added back in after deletion/expiration etc.  Now compare old privs with new privs to prevent this.  
  
  
Index: loncom/interface/loncoursegroups.pm
diff -u loncom/interface/loncoursegroups.pm:1.19 loncom/interface/loncoursegroups.pm:1.20
--- loncom/interface/loncoursegroups.pm:1.19	Thu May 18 14:35:13 2006
+++ loncom/interface/loncoursegroups.pm	Thu May 18 18:13:48 2006
@@ -476,7 +476,7 @@
         }
         if (defined($env{'form.sectionpick'})) {
             @sections=&Apache::loncommon::get_env_multiple('form.sectionpick');
-            if (grep/^_all$/,@sections) {
+            if (grep/^all$/,@sections) {
                 @sections = sort {$a cmp $b} keys(%sectioncount);
             }
         }
@@ -561,7 +561,7 @@
 
     if (($state eq 'pick_privs') || ($state eq 'change_privs') ||
         (($specificity eq 'No') && 
-         (($state eq 'result') || ($state eq 'memresult')))) {
+         (($state eq 'addresult') || ($state eq 'memresult')))) {
         foreach my $tool (@tools) {
             my @values = &Apache::loncommon::get_env_multiple('form.user_'.$tool);
             foreach my $user (@values) {
@@ -2905,6 +2905,7 @@
     my $num_ok = 0;
     my $num_fail = 0;
     my %group_privs = ();
+    my %curr_privs = ();
     my %tooltype = ();
 
     foreach my $tool (@{$tools}) {
@@ -2943,6 +2944,7 @@
     my @expire = ();
     my @deletion = ();
     my @reenable = ();
+    my @unchanged = ();
     if ($state eq 'memresult') {
         if (ref($$memchg{'activate'}) eq 'ARRAY') {
             @activate = @{$$memchg{'activate'}};
@@ -2956,21 +2958,25 @@
         if (ref($$memchg{'reenable'}) eq 'ARRAY') {
             @reenable = @{$$memchg{'reenable'}};
         }
+        my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
+                                                                 $groupname);
+        foreach my $key (sort(keys(%membership))) {
+            if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
+                (undef,undef,$curr_privs{$1})=split(/:/,$membership{$key},3);
+            }
+        }
         if (@expire + @deletion > 0) {
-            my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
-                                                                   $groupname);
             foreach my $user (@expire) {
-                my ($currend,$currstart,@userprivs) = 
-                                  split(/:/,$membership{$groupname.':'.$user});
-                $group_privs{$user} = join(':',@userprivs); 
+                my ($currend,$currstart,$grp_privs) = 
+                              split(/:/,$membership{$groupname.':'.$user},3);
                 if ($currstart > $now) {
                     $currstart = $now;
                 }
                 $usersettings{$groupname.':'.$user} = $now.':'.$currstart.':'.
-                                                      $group_privs{$user};
+                                                      $grp_privs;
                 if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
                                                        $user,$now,$currstart,
-                                                       $group_privs{$user}) eq 'ok') {
+                                                       $grp_privs) eq 'ok') {
                     push(@{$added{'expired'}},$user);
                     $num_ok ++;
                 } else {
@@ -2994,10 +3000,17 @@
     }
 
     foreach my $user (sort(keys(%{$usertools}))) {
+        if ((grep(/^$user$/,@expire)) || (grep(/^$user$/,@deletion))) {
+            next;
+        }
         my $type;
         my $start = $startdate;
         my $end = $enddate;
         if ($state eq 'memresult') {
+            if ($curr_privs{$user} eq $group_privs{$user}) {
+               push(@unchanged,$user);
+               next;
+            }
             $type = 'modified';
             if (@activate > 0) {
                 if (grep/^$user$/,@activate) {
@@ -3030,7 +3043,7 @@
     if ($num_ok) {
         foreach my $type (sort(keys(%added))) { 
             $r->print(&mt('The following users were successfully [_1]',$type));
-            if (!($type eq 'deleted' ||  $type eq 'expired')) {   
+            if (!($type eq 'deleted' || $type eq 'expired')) {   
                 $r->print(&mt(' with the following privileges'));
             }
             $r->print(':<br />');
@@ -3051,6 +3064,7 @@
                 }
                 $r->print($$userdata{$user}[$$idx{fullname}].'&nbsp;-&nbsp;'.$user.$privlist.'<br />');
             }
+            $r->print('<br />');
         }
     }
     if ($num_fail) {
@@ -3060,6 +3074,14 @@
                 $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
             }
         }
+        $r->print('<br />');
+    }
+    if (@unchanged > 0) {
+        $r->print(&mt('No change occurred for the following users:<br />'));
+        foreach my $user (sort(@unchanged)) {
+            $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
+        }
+        $r->print('<br />');
     }
     if ($roster_result eq 'ok') {
         $r->print('<br />'.&mt('Group membership list updated.'));