[LON-CAPA-cvs] cvs: loncom / lond /enrollment localenroll.pm /interface lonpopulate.pm /lonnet/perl lonnet.pm /misc refresh_courseids_db.pl

raeburn raeburn at source.lon-capa.org
Tue Mar 30 22:19:59 EDT 2021


raeburn		Wed Mar 31 02:19:59 2021 EDT

  Modified files:              
    /loncom	lond 
    /loncom/enrollment	localenroll.pm 
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/misc	refresh_courseids_db.pl 
    /loncom/interface	lonpopulate.pm 
  Log:
  - Support institutional policies which allow a Course Coordinator affiliated 
    with a cross-listed course to be automatically listed as a co-owner in a 
    course.
  
  
-------------- next part --------------
Index: loncom/lond
diff -u loncom/lond:1.565 loncom/lond:1.566
--- loncom/lond:1.565	Mon Feb  8 14:50:53 2021
+++ loncom/lond	Wed Mar 31 02:19:58 2021
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.565 2021/02/08 14:50:53 raeburn Exp $
+# $Id: lond,v 1.566 2021/03/31 02:19:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -65,7 +65,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.565 $'; #' stupid emacs
+my $VERSION='$Revision: 1.566 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -213,6 +213,7 @@
                autovalidateclass_sec => {catalog => 1},
                autovalidatecourse => {remote => 1, enroll => 1},
                autovalidateinstcode => {domroles => 1, remote => 1, enroll => 1},
+               autovalidateinstcrosslist => {remote => 1, enroll => 1},
                changeuserauth => {remote => 1, domroles => 1},
                chatretr => {remote => 1, enroll => 1},
                chatsend => {remote => 1, enroll => 1},
@@ -5948,6 +5949,39 @@
 }
 &register_handler("autovalidateinstcode", \&validate_instcode_handler, 0, 1, 0);
 
+#
+#  Validate co-owner for cross-listed institutional code and
+#  institutional course code itself used for a LON-CAPA course.
+#
+# Formal Parameters:
+#   $cmd          - The command request that got us dispatched.
+#   $tail         - The tail of the command.  In this case,
+#                   this is a colon separated string containing:
+#      $dom            - Course's LON-CAPA domain
+#      $instcode       - Institutional course code for the course
+#      $inst_xlist     - Institutional course Id for the crosslisting
+#      $coowner        - Username of co-owner
+#      (values for all but $dom have been escaped). 
+#
+#   $client       - Socket open on the client.
+# Returns:
+#    1           - Indicating processing should continue.
+#
+sub validate_instcrosslist_handler  {
+    my ($cmd, $tail, $client) = @_;
+    my $userinput = "$cmd:$tail";
+    my ($dom,$instcode,$inst_xlist,$coowner) = split(/:/,$tail);
+    $instcode = &unescape($instcode);
+    $inst_xlist = &unescape($inst_xlist);
+    $coowner = &unescape($coowner);
+    my $outcome = &localenroll::validate_crosslist_access($dom,$instcode,
+                                                          $inst_xlist,$coowner);
+    &Reply($client, \$outcome, $userinput);
+
+    return 1;
+}
+&register_handler("autovalidateinstcrosslist", \&validate_instcrosslist_handler, 0, 1, 0);
+
 #   Get the official sections for which auto-enrollment is possible.
 #   Since the admin people won't know about 'unofficial sections' 
 #   we cannot auto-enroll on them.
Index: loncom/enrollment/localenroll.pm
diff -u loncom/enrollment/localenroll.pm:1.59 loncom/enrollment/localenroll.pm:1.60
--- loncom/enrollment/localenroll.pm:1.59	Thu Jun 14 04:11:49 2018
+++ loncom/enrollment/localenroll.pm	Wed Mar 31 02:19:58 2021
@@ -1,6 +1,6 @@
 # functions to glue school database system into Lon-CAPA for 
 # automated enrollment
-# $Id: localenroll.pm,v 1.59 2018/06/14 04:11:49 raeburn Exp $
+# $Id: localenroll.pm,v 1.60 2021/03/31 02:19:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -144,7 +144,7 @@
  Manager, or via the 'Upload a class list','Enroll a single student' or 
  'Modify student data' utilities in the Enrollment Manager, by checking the 
  'make these dates the default for future enrollment' checkbox. If no default 
- dates have been set, then the tudent role will be active immediately, and will 
+ dates have been set, then the student role will be active immediately, and will 
  remain active until the role is explicitly expired using ENRL -> Drop students. 
  If dates are to included in the XML file, they should be in the format
  YYYY:MM:DD:HH:MM:SS (: separators required).
@@ -207,7 +207,7 @@
  ("001","601","602") would be returned
 
  If the array returned contains at least one element, then 
- the interface offerred to the course coordinator, lists
+ the interface offered to the course coordinator, lists
  official sections and provides a checkbox to use to
  select enrollment in the LON-CAPA course from each official section.  
 
@@ -342,6 +342,32 @@
 
 =pod
 
+=item validate_crosslist_access()
+
+This is called for an official course to check whether a course
+with the institutional code can have access to enrollment data
+from a cross-listed institutional section code, given a co-owner.
+
+validate_crosslist_access() takes four arguments -
+(a) the course's LON-CAPA domain 
+(b) the institional course code assigned to the course
+(c) the institutional course section code for the crosslisting
+(d) the co-owner to check for affiliation with the crosslisting 
+    (username:domain).
+
+A combination of (a), (b), (c) and (d) with access to enrollment 
+data, as per institutional policies, is confirmed by returning 'valid'.
+
+=cut
+
+sub validate_crosslist_access {
+    my ($dom,$instcode,$inst_xlist,$coowner) = @_;
+    my $outcome = '';
+    return $outcome;
+}
+
+=pod
+
 =item validate_crsreq()
 
 This is used to check whether a course request should be processed
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1443 loncom/lonnet/perl/lonnet.pm:1.1444
--- loncom/lonnet/perl/lonnet.pm:1.1443	Thu Feb 11 19:54:52 2021
+++ loncom/lonnet/perl/lonnet.pm	Wed Mar 31 02:19:59 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1443 2021/02/11 19:54:52 raeburn Exp $
+# $Id: lonnet.pm,v 1.1444 2021/03/31 02:19:59 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -9427,6 +9427,25 @@
     return ($outcome,$description,$defaultcredits);
 }
 
+sub auto_validate_inst_crosslist {
+    my ($cnum,$cdom,$instcode,$inst_xlist,$coowner) = @_;
+    my ($homeserver,$response);
+    if (($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/)) {
+        $homeserver = &homeserver($cnum,$cdom);
+    }
+    if (!defined($homeserver)) {
+        if ($cdom =~ /^$match_domain$/) {
+            $homeserver = &domain($cdom,'primary');
+        }
+    }
+    unless (($homeserver eq '') || ($homeserver eq 'no_host')) {
+        $response=&reply('autovalidateinstcrosslist:'.$cdom.':'.
+                         &escape($instcode).':'.&escape($inst_xlist).':'.
+                         &escape($coowner),$homeserver)));
+    }
+    return $response;
+}
+
 sub auto_create_password {
     my ($cnum,$cdom,$authparam,$udom) = @_;
     my ($homeserver,$response);
@@ -10248,11 +10267,24 @@
         if ($domdesign{$cdom.'.autoassign.co-owners'}) {
             my %coursehash = &coursedescription($cdom.'_'.$cnum);
             my $instcode = $coursehash{'internal.coursecode'};
+            my $xlists = $coursehash{'internal.crosslistings'};
             if ($instcode ne '') {
                 if (($start && $start <= $now) && ($end == 0) || ($end > $now)) {
                     unless ($coursehash{'internal.courseowner'} eq $uname.':'.$udom) {
                         my ($delcoowners, at newcoowners,$putresult,$delresult,$coowners);
                         my ($result,$desc) = &auto_validate_instcode($cnum,$cdom,$instcode,$uname.':'.$udom);
+                        unless ($result eq 'valid') {
+                            if ($xlists ne '') {
+                                foreach my $xlist (split(',',$xlists)) {
+                                    my ($inst_crosslist,$lcsec) = split(':',$xlist);
+                                    $result =
+                                        &Apache::lonnet::auto_validate_inst_crosslist($cnum,$cdom,$instcode,
+                                                                                      $inst_crosslist,$uname.':'.$udom);
+                                        last if ($result eq 'valid');
+                                    }
+                                }
+                            }
+                        }
                         if ($result eq 'valid') {
                             if ($coursehash{'internal.co-owners'}) {
                                 foreach my $coowner (split(',',$coursehash{'internal.co-owners'})) {
@@ -10265,18 +10297,16 @@
                             } else {
                                 push(@newcoowners,$uname.':'.$udom);
                             }
-                        } else {
-                            if ($coursehash{'internal.co-owners'}) {
-                                foreach my $coowner (split(',',$coursehash{'internal.co-owners'})) {
-                                    unless ($coowner eq $uname.':'.$udom) {
-                                        push(@newcoowners,$coowner);
-                                    }
-                                }
-                                unless (@newcoowners > 0) {
-                                    $delcoowners = 1;
-                                    $coowners = '';
+                        } elsif ($coursehash{'internal.co-owners'}) {
+                            foreach my $coowner (split(',',$coursehash{'internal.co-owners'})) {
+                                unless ($coowner eq $uname.':'.$udom) {
+                                    push(@newcoowners,$coowner);
                                 }
                             }
+                            unless (@newcoowners > 0) {
+                                $delcoowners = 1;
+                                $coowners = '';
+                            }
                         }
                         if (@newcoowners || $delcoowners) {
                             &store_coowners($cdom,$cnum,$coursehash{'home'},
Index: loncom/misc/refresh_courseids_db.pl
diff -u loncom/misc/refresh_courseids_db.pl:1.22 loncom/misc/refresh_courseids_db.pl:1.23
--- loncom/misc/refresh_courseids_db.pl:1.22	Wed Apr 22 16:43:56 2020
+++ loncom/misc/refresh_courseids_db.pl	Wed Mar 31 02:19:59 2021
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 # The LearningOnline Network
 #
-# $Id: refresh_courseids_db.pl,v 1.22 2020/04/22 16:43:56 raeburn Exp $
+# $Id: refresh_courseids_db.pl,v 1.23 2021/03/31 02:19:59 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -183,6 +183,7 @@
                 my $creator = $courseinfo{'internal.creator'};
                 my $creationcontext = $courseinfo{'internal.creationcontext'};
                 my $inst_code = $courseinfo{'internal.coursecode'};
+                my $xlists = $courseinfo{'internal.crosslistings'};
                 my $releaserequired = $courseinfo{'internal.releaserequired'};
                 my $uniquecode = $courseinfo{'internal.uniquecode'};
                 $inst_code = '' if (!defined($inst_code));
@@ -281,9 +282,20 @@
                                 my $cc = $1;
                                 unless ($cc eq $owner) {
                                     my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$inst_code,$cc);
+                                    unless ($result eq 'valid') {
+                                        if ($xlists ne '') {
+                                            foreach my $xlist (split(',',$xlists)) {
+                                                my ($inst_crosslist,$lcsec) = split(':',$xlist);
+                                                $result =
+                                                    &Apache::lonnet::auto_validate_inst_crosslist($cnum,$cdom,$inst_code,
+                                                                                                  $inst_crosslist,$cc);
+                                                last if ($result eq 'valid');
+                                            }
+                                        }
+                                    }
                                     if ($result eq 'valid') {
                                         if (@newcoowners > 0) {
-                                            unless (grep(/^\Q$cc\E$/, at newcoowners)) { 
+                                            unless (grep(/^\Q$cc\E$/, at newcoowners)) {
                                                 push(@newcoowners,$cc);
                                             }
                                         } else {
Index: loncom/interface/lonpopulate.pm
diff -u loncom/interface/lonpopulate.pm:1.85 loncom/interface/lonpopulate.pm:1.86
--- loncom/interface/lonpopulate.pm:1.85	Wed Nov  9 00:48:52 2016
+++ loncom/interface/lonpopulate.pm	Wed Mar 31 02:19:59 2021
@@ -1,5 +1,5 @@
 # automated enrollment configuration handler
-# $Id: lonpopulate.pm,v 1.85 2016/11/09 00:48:52 raeburn Exp $
+# $Id: lonpopulate.pm,v 1.86 2021/03/31 02:19:59 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2149,14 +2149,27 @@
                         next;
                     }
                 }
-		my $coursecheck = 
+		my $coursecheck =
                     &Apache::lonnet::auto_validate_courseID($crs,$dom,$env{"form.$xl"});
 		if ($coursecheck eq 'ok') {
 		    my $addcheck = '';
 		    $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$env{"form.$xl"},$owner,$coowners);
-		    if ($addcheck eq 'ok') {
-			push(@xlists,$env{"form.$xl"}.":".$env{"form.$lc_sec"});
-		    } else {
+		    unless ($addcheck eq 'ok') {
+                        if ($coowners) {
+                            foreach my $user (split(/,/,$coowners)) {
+                                if ($user =~ /^($match_username):($match_domain)$/) {
+                                    if (&Apache::lonnet::auto_validate_inst_crosslist($crs,$dom,$coursecode,
+                                                                                      $env{"form.$xl"},$user) eq 'valid') {
+                                        $addcheck = 'ok';
+                                        last;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    if ($addcheck eq 'ok') {
+                        push(@xlists,$env{"form.$xl"}.":".$env{"form.$lc_sec"});
+                    } else { 
 			push(@badowner,$env{"form.$xl"}.":".$env{"form.$lc_sec"});
 		    }
 		} else {


More information about the LON-CAPA-cvs mailing list