[LON-CAPA-cvs] cvs: loncom / lond /enrollment localenroll.pm /interface coursecatalog.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Wed Jan 31 23:51:15 EST 2018


raeburn		Thu Feb  1 04:51:15 2018 EDT

  Modified files:              
    /loncom	lond 
    /loncom/interface	coursecatalog.pm 
    /loncom/enrollment	localenroll.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Checking if enrollment data can be accessed for a course uses a single 
    call to localenroll::check_instclasses(), mediated via lonnet/lond.
  
  
-------------- next part --------------
Index: loncom/lond
diff -u loncom/lond:1.541 loncom/lond:1.542
--- loncom/lond:1.541	Sat Aug 26 03:57:01 2017
+++ loncom/lond	Thu Feb  1 04:50:41 2018
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.541 2017/08/26 03:57:01 raeburn Exp $
+# $Id: lond,v 1.542 2018/02/01 04:50:41 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -65,7 +65,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.541 $'; #' stupid emacs
+my $VERSION='$Revision: 1.542 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -5746,9 +5746,10 @@
 # Formal Parameters:
 #    $cmd     - The command request that got us dispatched.
 #    $tail    - The tail of the command.   In this case this is a colon separated
-#               set of words that will be split into:
+#               set of values that will be split into:
 #               $inst_class  - Institutional code for the specific class section   
-#               $courseowner - The escaped username:domain of the course owner 
+#               $ownerlist   - An escaped comma-separated list of username:domain 
+#                              of the course owner, and co-owner(s).
 #               $cdom        - The domain of the course from the institution's
 #                              point of view.
 #    $client  - The socket open on the client.
@@ -5773,6 +5774,56 @@
 &register_handler("autovalidateclass_sec", \&validate_class_access_handler, 0, 1, 0);
 
 #
+#   Validate course owner or co-owners(s) access to enrollment data for all sections
+#   and crosslistings for a particular 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
+#               set of values that will be split into:
+#               $ownerlist   - An escaped comma-separated list of username:domain
+#                              of the course owner, and co-owner(s).
+#               $cdom        - The domain of the course from the institution's
+#                              point of view.
+#               $classes     - Frozen hash of institutional course sections and
+#                              crosslistings.
+#    $client  - The socket open on the client.
+# Returns:
+#    1 - continue processing.
+#
+
+sub validate_classes_handler {
+    my ($cmd, $tail, $client) = @_;
+    my $userinput = "$cmd:$tail";
+    my ($ownerlist,$cdom,$classes) = split(/:/, $tail);
+    my $classesref = &Apache::lonnet::thaw_unescape($classes);
+    my $owners = &unescape($ownerlist);
+    my $result;
+    eval {
+        local($SIG{__DIE__})='DEFAULT';
+        my %validations;
+        my $response = &localenroll::check_instclasses($owners,$cdom,$classesref,
+                                                       \%validations);
+        if ($response eq 'ok') {
+            foreach my $key (keys(%validations)) {
+                $result .= &escape($key).'='.&Apache::lonnet::freeze_escape($validations{$key}).'&';
+            }
+            $result =~ s/\&$//;
+        } else {
+            $result = 'error';
+        }
+    };
+    if (!$@) {
+        &Reply($client, \$result, $userinput);
+    } else {
+        &Failure($client,"unknown_cmd\n",$userinput);
+    }
+    return 1;
+}
+&register_handler("autovalidateinstclasses", \&validate_classes_handler, 0, 1, 0);
+
+#
 #   Create a password for a new LON-CAPA user added by auto-enrollment.
 #   Only used for case where authentication method for new user is localauth
 #
Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.94 loncom/interface/coursecatalog.pm:1.95
--- loncom/interface/coursecatalog.pm:1.94	Tue Aug  8 15:32:30 2017
+++ loncom/interface/coursecatalog.pm	Thu Feb  1 04:51:02 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for displaying the course catalog interface
 #
-# $Id: coursecatalog.pm,v 1.94 2017/08/08 15:32:30 raeburn Exp $
+# $Id: coursecatalog.pm,v 1.95 2018/02/01 04:51:02 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1669,27 +1669,33 @@
 sub get_valid_classes {
     my ($seclist,$xlist_items,$crscode,$owners,$cdom,$cnum) = @_;
     my $response;
-    my %validations;
+    my (@sections, at xlists,%possclasses,%okclasses,%validations);
     @{$validations{'sections'}} = ();
     @{$validations{'xlists'}} = ();
     my $totalitems = 0;
     if ($seclist) {
-        foreach my $sec (split(/, /,$seclist)) {
+        @sections = split(/,\s+/,$seclist);
+        map { $possclasses{$crscode.$_} = 1; } @sections;
+    }
+    if ($xlist_items) {
+        @xlists = split(/,\s+/,$xlist_items);
+        map { $possclasses{$_} = 1; } @xlists;
+    }
+    my %okclasses = &Apache::lonnet::auto_validate_instclasses($cdom,$cnum,$owners,
+                                                               \%possclasses);
+    if (keys(%okclasses)) {
+        foreach my $sec (@sections) {
             my $class = $crscode.$sec;
-            if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
-							 $class) eq 'ok') {
+            if ($okclasses{$crscode.$sec}) {
                 if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
                     push(@{$validations{'sections'}},$sec);
                     $totalitems ++;
                 }
             }
         }
-    }
-    if ($xlist_items) {
-        foreach my $item (split(/, /,$xlist_items)) {
-            if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
-							 $item) eq 'ok') {
-                if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
+        foreach my $item (@xlists) {
+            if ($okclasses{$item}) {
+                if (!grep(/^\Q$item\E$/,@{$validations{'xlists'}})) {
                     push(@{$validations{'xlists'}},$item);
                     $totalitems ++;
                 }
Index: loncom/enrollment/localenroll.pm
diff -u loncom/enrollment/localenroll.pm:1.57 loncom/enrollment/localenroll.pm:1.58
--- loncom/enrollment/localenroll.pm:1.57	Fri Oct 13 20:37:40 2017
+++ loncom/enrollment/localenroll.pm	Thu Feb  1 04:51:08 2018
@@ -1,6 +1,6 @@
 # functions to glue school database system into Lon-CAPA for 
 # automated enrollment
-# $Id: localenroll.pm,v 1.57 2017/10/13 20:37:40 raeburn Exp $
+# $Id: localenroll.pm,v 1.58 2018/02/01 04:51:08 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -39,8 +39,6 @@
 
 =head1 NOTABLE SUBROUTINES
 
-=over
-
 =cut
 
 package localenroll;
@@ -48,6 +46,8 @@
 use strict;
 
 =pod
+
+=over
  
 =item run()
  set this to return 1 if you want the auto enrollment to run
@@ -258,9 +258,11 @@
  username:domain
  (c) the LON-CAPA domain that contains the course
 
- new_course also takes a fourth (optional) argument -
+ new_course also takes optional fourth and fifth arguments -
  (d) the course co-owners, as a comma-separated list of username:domain for
- any co-owners. 
+ any co-owners.
+ (e) database handle (might be set when new_course() is called by check_section
+ routine within localenroll.pm).
 
 =cut
 
@@ -590,6 +592,46 @@
 
 =pod
 
+=item check_instclasses()
+
+ This is used to supply information about which instituional course sections
+ and cross-listings are available to supply enrollment data, given the current
+ list of owner and co-owners. The data are used to populate the column titled:
+ "Auto-enrollment of registered students" when showing full detailed for a course
+ in the course catalog.
+
+ This subroutine takes four arguments -
+
+ (a) $owners - comma-separated list of username:domain for course owner 
+     and co-owners.
+ (b) $dom - domain of course.
+ (c) $classes - reference to hash of institutional course sections and
+     crosslistings for which access to enrollment data is being checked.
+ (d) $validated - reference to hash which will be populated with all
+     keys from incoming $classes hashref, for which one or more of the
+     owner/co-owners has rights to access enrollment data. For each
+     key included in $validated hashref, corresponding value will be set to 1.
+  
+ The subroutine returns 'ok' if there is no processing error.
+
+=cut
+
+
+sub check_instclasses {
+    my ($owners,$dom,$classes,$validated) = @_;
+    if ((ref($classes) eq 'HASH') && (ref($validated) eq 'HASH')) {
+        foreach my $class (keys(%{$classes})){
+            if (&check_section($class,$owners,$cdom) eq 'ok') {
+                $validated->{$class} = 1;
+            }
+        }
+    }
+    return 'ok';
+}
+
+
+=pod
+
 =item create_password()
 
  This is called when the authentication method set for the automated 
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1366 loncom/lonnet/perl/lonnet.pm:1.1367
--- loncom/lonnet/perl/lonnet.pm:1.1366	Wed Jan  3 04:21:02 2018
+++ loncom/lonnet/perl/lonnet.pm	Thu Feb  1 04:51:13 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1366 2018/01/03 04:21:02 raeburn Exp $
+# $Id: lonnet.pm,v 1.1367 2018/02/01 04:51:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -8892,6 +8892,33 @@
     return $response;
 }
 
+sub auto_validate_instclasses {
+    my ($cdom,$cnum,$owners,$classesref) = @_;
+    my ($homeserver,%validations);
+    $homeserver = &homeserver($cnum,$cdom);
+    unless ($homeserver eq 'no_host') {
+        my $ownerlist;
+        if (ref($owners) eq 'ARRAY') {
+            $ownerlist = join(',',@{$owners});
+        } else {
+            $ownerlist = $owners;
+        }
+        if (ref($classesref) eq 'HASH') {
+            my $classes = &freeze_escape($classesref);
+            my $response=&reply('autovalidateinstclasses:'.&escape($ownerlist).
+                                ':'.$cdom.':'.$classes,$homeserver);
+            unless ($response =~ /(con_lost|error|no_such_host|refused)/) {
+                my @items = split(/&/,$response);
+                foreach my $item (@items) {
+                    my ($key,$value) = split('=',$item);
+                    $validations{&unescape($key)} = &thaw_unescape($value);
+                }
+            }
+        }
+    }
+    return %validations;
+}
+
 sub auto_crsreq_update {
     my ($cdom,$cnum,$crstype,$action,$ownername,$ownerdomain,$fullname,$title,
         $code,$accessstart,$accessend,$inbound) = @_;


More information about the LON-CAPA-cvs mailing list