[LON-CAPA-cvs] cvs: loncom /enrollment Autoenroll.pl /interface lonmenu.pm lonuserutils.pm /lonnet/perl lonnet.pm /misc refresh_courseids_db.pl

raeburn raeburn at source.lon-capa.org
Mon Oct 2 17:01:22 EDT 2023


raeburn		Mon Oct  2 21:01:22 2023 EDT

  Modified files:              
    /loncom/interface	lonmenu.pm lonuserutils.pm 
    /loncom/misc	refresh_courseids_db.pl 
    /loncom/enrollment	Autoenroll.pl 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Bug 6979.
    "View As" form in Functions menu includes domain dropdown list if users in
    course are from more than one domain. Use course's environment.db to store
    comma separated list of unique domains to which course users belong.  
  
  
-------------- next part --------------
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.538 loncom/interface/lonmenu.pm:1.539
--- loncom/interface/lonmenu.pm:1.538	Thu Sep 28 15:56:48 2023
+++ loncom/interface/lonmenu.pm	Mon Oct  2 21:01:21 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.538 2023/09/28 15:56:48 raeburn Exp $
+# $Id: lonmenu.pm,v 1.539 2023/10/02 21:01:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1081,11 +1081,30 @@
         if (($env{'request.symb'} ne '') &&
             ($env{'request.filename'}=~/$LONCAPA::assess_re/) &&
             (($perms{'mgr'}) || ($perms{'vgr'}))) {
-            my ($viewas,$text,$change,$visibility,$vuname,$vudom,$vid,$leftvis,$defdom,$righticon);
+            my ($viewas,$text,$change,$visibility,$vuname,$vudom,$vid,$leftvis,$defdom,
+                $domselector,$righticon);
             my %lt = &Apache::lonlocal::texthash(
                                                  view => 'View',
                                                  upda => 'Update',
             );
+            my $possdomstr = $env{'course.'.$env{'request.course.id'}.'.internal.userdomains'};
+            if ($possdomstr =~ /,/) {
+                my @possdoms = split(/,/,$possdomstr);
+                if ($env{'request.user_in_effect'} =~ /^$match_username:($match_domain)$/) {
+                    $defdom = $1;
+                } elsif (grep(/^\Q$cdom\E$/, at possdoms)) {
+                    $defdom = $cdom;
+                } elsif (&Apache::lonnet::domain($possdoms[0]) ne '') {
+                    $defdom = $possdoms[0];
+                }
+                $domselector = &Apache::loncommon::select_dom_form($defdom,'vudom','','','',\@possdoms);
+            } elsif (($possdomstr ne '') && (&Apache::lonnet::domain($possdomstr) ne '')) {
+                if ($env{'request.user_in_effect'} =~ /^$match_username:($match_domain)$/) {
+                    $defdom = $1;
+                } else {
+                    $defdom = $possdomstr;
+                }
+            }
             if ($env{'request.user_in_effect'} =~ /^($match_username):($match_domain)$/) {
                 ($vuname,$vudom) = ($1,$2);
                 unless (&Apache::lonnet::is_advanced_user($vudom,$vuname)) {
@@ -1103,19 +1122,29 @@
                 $change = 'on';
                 $visibility = 'none';
                 $leftvis = 'inline';
-                $defdom = $cdom;
+                if ($defdom eq '') {       
+                    $defdom = $cdom;
+                }
             }
             my $sellink = &Apache::loncommon::selectstudent_link('userview','vuname','vudom','','','vuidentifier');
             my $selscript=&Apache::loncommon::studentbrowser_javascript();
             my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}),'<>&"');
-            my $input = &mt('[_1]Username:[_2] or [_3]ID:[_4] | ',
-                            '<label><input type="radio" name="vuidentifier" value="uname" checked="checked" onclick="javascript:toggleIdentifier(this.form);" />',
-                            '</label><input name="vuname" type="text" size="6" value="'.$vuname.'" id="LC_vuname" />',
-                            '<label><input type="radio" name="vuidentifier" value="uid" onclick="javascript:toggleIdentifier(this.form);" />',
-                            '</label><input name="vid" type="hidden" size="6" value="'.$vid.'" id="LC_vid" />').
-                        '<input name="vudom" type="hidden" value="'.$defdom.'" />'.
-                        '<input name="LC_viewas" type="hidden" value="'.$viewas.'" />',
-                        '<input name="symb" type="hidden" value="'.$shownsymb.'" />';
+            my $input;
+            my @items = (
+                         '<label><input type="radio" name="vuidentifier" value="uname" checked="checked" onclick="javascript:toggleIdentifier(this.form);" />',
+                         '</label><input name="vuname" type="text" size="6" value="'.$vuname.'" id="LC_vuname" />',
+                         '<label><input type="radio" name="vuidentifier" value="uid" onclick="javascript:toggleIdentifier(this.form);" />',
+                         '</label><input name="vid" type="hidden" size="6" value="'.$vid.'" id="LC_vid" />'
+                        );
+            if ($domselector) {
+                push(@items,$domselector);
+                $input = &mt('[_1]User:[_2] or [_3]ID:[_4] at [_5] | ', at items);
+            } else {
+                $input = &mt('[_1]Username:[_2] or [_3]ID:[_4] | ', at items).
+                         '<input name="vudom" type="hidden" value="'.$defdom.'" />';
+            }
+            $input .= '<input name="LC_viewas" type="hidden" value="'.$viewas.'" />',
+                      '<input name="symb" type="hidden" value="'.$shownsymb.'" />';
             my $chooser = <<END;
 $selscript
 <a href="javascript:toggleViewAsUser('$change');" class="LC_menubuttons_link">
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.216 loncom/interface/lonuserutils.pm:1.217
--- loncom/interface/lonuserutils.pm:1.216	Tue Aug  1 15:56:32 2023
+++ loncom/interface/lonuserutils.pm	Mon Oct  2 21:01:21 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.216 2023/08/01 15:56:32 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.217 2023/10/02 21:01:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4723,7 +4723,7 @@
         $fieldstype{$field.'_choice'} = 'scalar';
     }
     &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
-    my ($cid,$crstype,$setting,$crsdom,$crsnum);
+    my ($cid,$crstype,$setting,$crsdom,$crsnum,$oldcrsuserdoms);
     if ($context eq 'domain') {
         $setting = $env{'form.roleaction'};
     }
@@ -4738,6 +4738,11 @@
             $crstype = &Apache::loncommon::course_type($cid);
             $crsdom = $env{'form.dcdomain'};
             $crsnum = $env{'form.dccourse'};
+            if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
+                $oldcrsuserdoms = 1;
+            }
+            my %coursedesc = &Apache::lonnet::coursedescription($cid,{ one_time => 1 });
+            $env{'course.'.$cid.'.internal.userdomains'} = $coursedesc{'internal.userdomains'};
         }
     }
     my ($startdate,$enddate) = &get_dates_from_form();
@@ -5564,6 +5569,13 @@
             } # end of loop
             $r->print('</ul>');
             &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+            if (($context eq 'domain') && ($setting eq 'course')) {
+                unless ($oldcrsuserdoms) {
+                    if (exists($env{'course.'.$cid.'.internal.userdomains'})) {
+                        delete($env{'course.'.$cid.'.internal.userdomains'});
+                    }
+                }
+            }
         }
         # Flush the course logs so reverse user roles immediately updated
         $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
Index: loncom/misc/refresh_courseids_db.pl
diff -u loncom/misc/refresh_courseids_db.pl:1.23 loncom/misc/refresh_courseids_db.pl:1.24
--- loncom/misc/refresh_courseids_db.pl:1.23	Wed Mar 31 02:19:59 2021
+++ loncom/misc/refresh_courseids_db.pl	Mon Oct  2 21:01:21 2023
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 # The LearningOnline Network
 #
-# $Id: refresh_courseids_db.pl,v 1.23 2021/03/31 02:19:59 raeburn Exp $
+# $Id: refresh_courseids_db.pl,v 1.24 2023/10/02 21:01:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -351,6 +351,11 @@
                             }
                         }
                     }
+                    my $curruserdoms = $courseinfo{'internal.userdomains'};
+                    my $updateduserdoms = &get_unique_domains($cdom,$cnum);
+                    if ($curruserdoms ne $updateduserdoms) {
+                        $changes{'internal.userdomains'} = $updateduserdoms;
+                    }
                     if (keys(%changes)) {
                         if (&Apache::lonnet::put('environment',\%changes,$cdom,$cnum) eq 'ok') {
                             print $fh "Course's environment.db for ".$cdom."_".$cnum." successfully updated with following entries: ";
@@ -387,3 +392,28 @@
     return $lastupdate;
 }
 
+sub get_unique_domains {
+    my ($cdom,$cnum) = @_;
+    my %classlist = &Apache::lonnet::dump('classlist',$cdom,$cnum);
+    my (%uniquedom,$udomstr);
+    foreach my $key (keys(%classlist)) {
+        my $udom = (split(/:/,$key))[1];
+        $uniquedom{$udom} = 1;
+    }
+    my %dumphash =
+        &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
+    foreach my $entry (keys(%dumphash)) {
+        my $udom = (split(/\:/,$entry))[2];
+        $uniquedom{$udom} = 1;
+    }
+    foreach my $udom (keys(%uniquedom)) {
+        if (&Apache::lonnet::domain($udom) eq '') {
+            delete($uniquedom{$udom});
+        }
+    }
+    if (keys(%uniquedom) > 0) {
+        $udomstr = join(',',sort(keys(%uniquedom)));
+    }
+    return $udomstr;
+}
+
Index: loncom/enrollment/Autoenroll.pl
diff -u loncom/enrollment/Autoenroll.pl:1.37 loncom/enrollment/Autoenroll.pl:1.38
--- loncom/enrollment/Autoenroll.pl:1.37	Thu Jan 13 03:50:32 2022
+++ loncom/enrollment/Autoenroll.pl	Mon Oct  2 21:01:22 2023
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 #
 #Automated Enrollment script
-# $Id: Autoenroll.pl,v 1.37 2022/01/13 03:50:32 raeburn Exp $
+# $Id: Autoenroll.pl,v 1.38 2023/10/02 21:01:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -198,9 +198,14 @@
                         print $fh "$logmsg\n";
                         print $fh &mt('Messages end for [_1]',$crs)."\n";
                         if ($changecount > 0) {
-# Set $env{'user.name'}, $env{'user.domain'}, $env{'user.home'}
-# and $env{'request.course.id'} for use by logging in lonmsg
+# Set $env{'user.name'}, $env{'user.domain'}, $env{'user.home'},
+# $env{'request.course.id'} for use by logging in lonmsg,
+# and $env{'course.'.$env{'request.course.id'}.'.internal.userdomains'}
+# for use in courserolelog
                             $env{'request.course.id'} = $dom.'_'.$crs;
+                            if (exists($enrollvar{$crs}{'userdomains'})) {
+                                $env{'course.'.$dom.'_'.$crs.'.internal.userdomains'} = $enrollvar{$crs}{'userdomains'};
+                            }
                             my ($ownername,$ownerdom);
                             if ($enrollvar{$crs}{'courseowner'} ne '') {
                                 if ($enrollvar{$crs}{'courseowner'} =~ /:/) {
@@ -273,6 +278,9 @@
                             }
                             delete($env{'user.name'});
                             delete($env{'user.home'});
+                            if (exists($enrollvar{$crs}{'userdomains'})) {
+                                delete($env{'course.'.$dom.'_'.$crs.'.internal.userdomains'});
+                            }
                             delete($env{'request.course.id'});
                             $env{'user.domain'} = $dom;
                         }
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1514 loncom/lonnet/perl/lonnet.pm:1.1515
--- loncom/lonnet/perl/lonnet.pm:1.1514	Sat Jul 29 20:33:26 2023
+++ loncom/lonnet/perl/lonnet.pm	Mon Oct  2 21:01:22 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1514 2023/07/29 20:33:26 raeburn Exp $
+# $Id: lonnet.pm,v 1.1515 2023/10/02 21:01:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5471,6 +5471,36 @@
             $storehash{'group'} = $sec;
         } else {
             $storehash{'section'} = $sec;
+            my ($curruserdomstr,$newuserdomstr); 
+            if (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.userdomains'})) {
+                $curruserdomstr = $env{'course.'.$env{'request.course.id'}.'.internal.userdomains'};
+            } else {    
+                my %courseinfo = &coursedescription($cdom.'/'.$cnum);
+                $curruserdomstr = $courseinfo{'internal.userdomains'};
+            }
+            if ($currusedomstr ne '') {
+                my @udoms = split(/,/,$courseinfo{'internal.userdomains'});
+                unless (grep(/^\Q$domain\E/, at udoms)) {
+                    push(@udoms,$domain);
+                    $newuserdomstr = join(',',sort(@udoms));
+                }
+            } else {
+                $newuserdomstr = $domain;
+            }
+            if ($newuserdomstr ne '') {
+                my $putresult = &put('environment',{ 'internal.userdomains' => $newuserdomstr },
+                                     $cdom,$cnum);
+                if ($putresult eq 'ok') {
+                    unless (($selfenroll) || ($context eq 'selfenroll')) { 
+                        if (($context eq 'createcourse') || ($context eq 'requestcourses') ||
+                            ($context eq 'automated') || ($context eq 'domain')) {
+                            $env{'course.'.$cdom.'_'.$cnum.'.internal.userdomains'} = $newuserdomstr;
+                        } elsif ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
+                            &appenv({'course.'.$cdom.'_'.$cnum.'.internal.userdomains' => $newuserdomstr});
+                        }
+                    }
+                }
+            }
         }
         &write_log('course',$namespace,\%storehash,$delflag,$username,
                    $domain,$cnum,$cdom);


More information about the LON-CAPA-cvs mailing list