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

raeburn raeburn@source.lon-capa.org
Mon, 15 Mar 2010 19:10:59 -0000


raeburn		Mon Mar 15 19:10:59 2010 EDT

  Modified files:              
    /loncom/interface	lonmodifycourse.pm 
  Log:
  - When auto-assignment of co-owners is enabled for official courses:
   - Use lonnet:: auto_validate_instcode() to check active CC is official
     course personnel before assigning co-owner role when
     (a) modifying institutional code, or (b) changing course owner.
  
  
Index: loncom/interface/lonmodifycourse.pm
diff -u loncom/interface/lonmodifycourse.pm:1.50 loncom/interface/lonmodifycourse.pm:1.51
--- loncom/interface/lonmodifycourse.pm:1.50	Mon Mar  8 22:31:27 2010
+++ loncom/interface/lonmodifycourse.pm	Mon Mar 15 19:10:59 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # handler for DC-only modifiable course settings
 #
-# $Id: lonmodifycourse.pm,v 1.50 2010/03/08 22:31:27 raeburn Exp $
+# $Id: lonmodifycourse.pm,v 1.51 2010/03/15 19:10:59 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -877,20 +877,26 @@
     }
     if ($settings->{'internal.courseowner'} ne $newattr->{'courseowner'}) {
         my $oldowner_to_coowner;
+        my @types = ('co-owners');
         if (($newattr->{'coursecode'}) && ($autocoowners)) {
             my $oldowner = $settings->{'internal.courseowner'};
             if ($cchash{$oldowner.':cc'}) {
-                if ($settings->{'internal.co-owner'}) {
-                    my @current = split(',',$settings->{'internal.co-owners'});
-                    unless (grep(/^\Q$oldowner\E$/,@current)) {
+                my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$oldowner);
+                if ($result eq 'valid') {
+                    if ($settings->{'internal.co-owner'}) {
+                        my @current = split(',',$settings->{'internal.co-owners'});
+                        unless (grep(/^\Q$oldowner\E$/,@current)) {
+                            $oldowner_to_coowner = 1;
+                        }
+                    } else {
                         $oldowner_to_coowner = 1;
                     }
-                } else {
-                    $oldowner_to_coowner = 1;
                 }
             }
+        } else {
+            push(@types,'pendingco-owners');
         }
-        foreach my $type ('co-owners','pendingco-owners') {
+        foreach my $type (@types) {
             if ($settings->{'internal.'.$type}) {
                 my @current = split(',',$settings->{'internal.'.$type});
                 my $newowner = $newattr->{'courseowner'};
@@ -960,15 +966,19 @@
                     my @currcoown = split(',',$settings->{'internal.coowners'});
                     my ($updatecoowners,$delcoowners);
                     foreach my $person (@currcoown) {
-                        my ($result,$desc) = &Apache::lonnet::valid_instcode();
+                        my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$person);
                         if ($result eq 'valid') {
                             push(@newcoowners,$person);
                         }
                     }
                     foreach my $item (sort(keys(%cchash))) {
                         my ($uname,$udom,$urole) = split(':',$item);
+                        next if ($uname.':'.$udom eq $newattr->{'courseowner'});
                         unless (grep(/^\Q$uname\E:\Q$udom\E$/,@newcoowners)) {
-                            push(@newcoowners,$uname.':'.$udom);
+                            my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$uname.':'.$udom);
+                            if ($result eq 'valid') {
+                                push(@newcoowners,$uname.':'.$udom);
+                            }
                         }
                     }
                     if (@newcoowners) {