[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm lonuserutils.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Mon May 6 15:28:25 EDT 2019


raeburn		Mon May  6 19:28:25 2019 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm lonuserutils.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Domain configuration which allows Course Owner to change a student's
    password (with conditions):
    - Restrict to specified institutional status types for (a) course owner
      and (b) student.
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.358 loncom/interface/domainprefs.pm:1.359
--- loncom/interface/domainprefs.pm:1.358	Mon May  6 01:30:14 2019
+++ loncom/interface/domainprefs.pm	Mon May  6 19:28:17 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.358 2019/05/06 01:30:14 raeburn Exp $
+# $Id: domainprefs.pm,v 1.359 2019/05/06 19:28:17 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6300,29 +6300,60 @@
                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                       '</span></td></tr>';
     } else {
-        my $checkedon;
-        my $checkedoff = ' checked="checked"';
+        my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
+        my %ownerchg = (
+                          by  => {},
+                          for => {},
+                       );
+        my %ownertitles = &Apache::lonlocal::texthash (
+                            by  => 'Course owner status(es) allowed',
+                            for => 'Student status(es) allowed',
+                          );
         if (ref($settings) eq 'HASH') {
-            if ($settings->{crsownerchg}) {
-                $checkedon = $checkedoff;
-                $checkedoff = '';
+            if (ref($settings->{crsownerchg}) eq 'HASH') {
+                if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
+                    map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
+                }
+                if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
+                    map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
+                }
             }
         }
         $css_class = $itemcount%2?' class="LC_odd_row"':'';
         $datatable .= '<tr '.$css_class.'>'.
                       '<td>'.
                       &mt('Requirements').'<ul>'.
-                      '<li>'.&mt("Course 'type' is not a Community").'</li>'.
+                      '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
                       '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
                       '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
+                      '<li>'.&mt('User, course, and student share same domain').'</li>'.
                       '</ul>'.
                       '</td>'.
-                      '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
-                      '<label><input type="radio" name="passwords_crsowner" value="1"'.$checkedon.' />'.&mt('Yes').'</label></span>   '.
-                      '<span class="LC_nobreak"><label><input type="radio" name="passwords_crsowner" value="0"'.$checkedoff.' />'.
-                      &mt('No').'</label></span>'.
-                      '</td></tr>';
-
+                      '<td class="LC_left_item">';
+        foreach my $item ('by','for') {
+            $datatable .= '<fieldset style="display: inline-block;">'.
+                          '<legend>'.$ownertitles{$item}.'</legend>';
+            if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
+                foreach my $type (@{$types}) {
+                    my $checked;
+                    if ($ownerchg{$item}{$type}) {
+                        $checked = ' checked="checked"';
+                    }
+                    $datatable .= '<span class="LC_nobreak"><label>'.
+                                  '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
+                                  $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
+                                  '<span>   ';
+                }
+            }
+            my $checked;
+            if ($ownerchg{$item}{'default'}) {
+                $checked = ' checked="checked"';
+            }
+            $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
+                          'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
+                          $othertitle.'</label></span></fieldset>';
+        }
+        $datatable .= '</td></tr>';
     }
     return $datatable;
 }
@@ -14588,7 +14619,7 @@
         my $ruleok;
         if ($rule eq 'expire') {
             if ($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) {
-                $ruleok = 1; 
+                $ruleok = 1;
             }
         } elsif ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
             $ruleok = 1;
@@ -14628,13 +14659,36 @@
             }
         }
     }
-    if ($env{'form.passwords_crsowner'}) {
-        $newvalues{'crsownerchg'} = 1;
-        unless ($current{'crsownerchg'}) {
-            $changes{'crsownerchg'} = 1;
+    my %crsownerchg = (
+                        by => [],
+                        for => [],
+                      );
+    foreach my $item ('by','for') {
+        my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
+        foreach my $type (sort(@posstypes)) {
+            if (grep(/^\Q$type\E$/, at oktypes)) {
+                push(@{$crsownerchg{$item}},$type);
+            }
+        }
+    }
+    $newvalues{'crsownerchg'} = \%crsownerchg;
+    if (ref($current{'crsownerchg'}) eq 'HASH') {
+        foreach my $item ('by','for') {
+            if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
+                my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
+                if (@diffs > 0) {
+                    $changes{'crsownerchg'} = 1;
+                    last;
+                }
+            }
+        }
+    } elsif (!exists($domconfig{passwords})) {
+        foreach my $item ('by','for') {
+            if (@{$crsownerchg{$item}} > 0) {
+                $changes{'crsownerchg'} = 1;
+                last;
+            }
         }
-    } elsif ($current{'crsownerchg'}) {
-        $changes{'crsownerchg'} = 1;
     }
 
     my %confighash = (
@@ -14786,10 +14840,29 @@
                             }
                         }
                     } elsif ($key eq 'crsownerchg') {
-                        if ($confighash{'passwords'}{'crsownerchg'}) {
-                            $resulttext .= '<li>'.&mt('Course owner may change student passwords.').'</li>';
+                        if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
+                            if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
+                                (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
+                                $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
+                            } else {
+                                my %crsownerstr;
+                                foreach my $item ('by','for') {
+                                    if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
+                                        foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
+                                            if ($type eq 'default') {
+                                                $crsownerstr{$item} .= $othertitle.', ';
+                                            } elsif ($usertypes->{$type} ne '') {
+                                                $crsownerstr{$item} .= $usertypes->{$type}.', ';
+                                            }
+                                        }
+                                        $crsownerstr{$item} =~ s/\Q, \E$//;
+                                    }
+                                }
+                                $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
+                                           $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
+                            }
                         } else {
-                            $resulttext .= '<li>'.&mt('Course owner may not change student passwords.');
+                            $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                         }
                     }
                     $resulttext .= '</ul></li>';
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.198 loncom/interface/lonuserutils.pm:1.199
--- loncom/interface/lonuserutils.pm:1.198	Mon May  6 18:25:58 2019
+++ loncom/interface/lonuserutils.pm	Mon May  6 19:28:17 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.198 2019/05/06 18:25:58 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.199 2019/05/06 19:28:17 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -6014,7 +6014,26 @@
         unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
             my ($cnum,$cdom) = &get_course_identity();
             if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
-                my $noupdate;
+                my @userstatuses = ('default');
+                my %userenv = &Apache::lonnet::userenvironment($udom,$uname,'inststatus');
+                if ($userenv{'inststatus'} ne '') {
+                    @userstatuses =  split(/:/,$userenv{'inststatus'});
+                }
+                my $noupdate = 1;
+                my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
+                if (ref($passwdconf{'crsownerchg'}) eq 'HASH') {
+                    if (ref($passwdconf{'crsownerchg'}{'for'}) eq 'ARRAY') {
+                        foreach my $status (@userstatuses) {
+                            if (grep(/^\Q$status\E$/,@{$passwdconf{'crsownerchg'}{'for'}})) {
+                                undef($noupdate);
+                                last;
+                            }
+                        }
+                    }
+                }
+                if ($noupdate) {
+                    return;
+                }
                 my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
                                                           $env{'user.name'}.':'.$env{'user.domain'},
                                                           undef,undef,undef,'.');
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1409 loncom/lonnet/perl/lonnet.pm:1.1410
--- loncom/lonnet/perl/lonnet.pm:1.1409	Mon Apr 29 22:19:45 2019
+++ loncom/lonnet/perl/lonnet.pm	Mon May  6 19:28:24 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1409 2019/04/29 22:19:45 raeburn Exp $
+# $Id: lonnet.pm,v 1.1410 2019/05/06 19:28:24 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -8089,9 +8089,21 @@
                 ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq $env{'user.name'}.':'.$env{'user.domain'})) {
                 my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                 if ($cdom ne '') {
-                    my %passwdconf = &Apache::lonnet::get_passwdconf($cdom);
-                    if ($passwdconf{'crsownerchg'}) {
-                        $thisallowed.=$rem;
+                    my %passwdconf = &get_passwdconf($cdom);
+                    if (ref($passwdconf{'crsownerchg'}) eq 'HASH') {
+                        if (ref($passwdconf{'crsownerchg'}{'by'}) eq 'ARRAY') {
+                            if (@{$passwdconf{'crsownerchg'}{'by'}}) {
+                                my @inststatuses = split(':',$env{'environment.inststatus'});
+                                unless (@inststatuses) {
+                                    @inststatuses = ('default');
+                                }
+                                foreach my $status (@inststatuses) {
+                                    if (grep(/^\Q$status\E$/,@{$passwdconf{'crsownerchg'}{'by'}})) {
+                                        $thisallowed.=$rem;
+                                    }
+                                }
+                            }
+                        }
                     }
                 }
             }


More information about the LON-CAPA-cvs mailing list