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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Wed, 12 Dec 2007 19:44:53 -0000


This is a MIME encoded message

--raeburn1197488693
Content-Type: text/plain

raeburn		Wed Dec 12 14:44:53 2007 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
  Log:
  - Domain Configuration for control of user creation in author or course context
  - Types of user creation permitted can be: any, none, institutional (i.e., username formats corresponding to 'official' username formats at your institution, or non-institutional (i.e., username formats which are not a match to any defined institutional formats).
  
  
--raeburn1197488693
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071212144453.txt"

Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.33 loncom/interface/domainprefs.pm:1.34
--- loncom/interface/domainprefs.pm:1.33	Mon Dec 10 19:44:23 2007
+++ loncom/interface/domainprefs.pm	Wed Dec 12 14:44:53 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.33 2007/12/11 00:44:23 raeburn Exp $
+# $Id: domainprefs.pm,v 1.34 2007/12/12 19:44:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -127,8 +127,10 @@
         'usercreation' => 
                   { text => 'User creation',
                     help => 'Domain_User_Creation',
-                    header => [{col1 => 'Setting',
-                                col2 => 'Value',},
+                    header => [{col1 => 'Format Rule Type',
+                                col2 => 'Format Rules in force'},
+                               {col1 => 'User account creation',
+                                col2 => 'Usernames which may be created',},
                                {col1 => 'Context',
                                 col2 => 'Assignable Authentication Types'}],
                   },
@@ -372,7 +374,18 @@
         if ($action eq 'autoupdate') {
             $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'usercreation') {
-            $output .= &print_usercreation('bottom',$dom,$settings,\$rowtotal);
+            $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
+           </table>
+          </td>
+         </tr>
+         <tr>
+           <td>
+            <table class="LC_nested">
+             <tr class="LC_info_row">
+              <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
+              <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>             </tr>'.
+            &print_usercreation('bottom',$dom,$settings,\$rowtotal);
+            $rowtotal ++;
         } elsif ($action eq 'usermodification') {
             $output .= &print_usermodification('bottom',$dom,$settings,\$rowtotal);
         } else {
@@ -1297,33 +1310,10 @@
     my ($position,$dom,$settings,$rowtotal) = @_;
     my $numinrow = 4;
     my $datatable;
-    my %lt = &Apache::lonlocal::texthash (
-                        nondc => 'User creation other than by Domain Coordinator: ',
-                        author => 'When adding a co-author/assistant author',
-                        course => 'When adding users to a course',
-    );
     if ($position eq 'top') {
-        my %checked;
-        if (ref($settings) eq 'HASH') {
-            if (ref($settings->{'cancreate'}) eq 'ARRAY') {
-                foreach my $item (@{$settings->{'cancreate'}}) {
-                    $checked{$item} = ' checked="checked" ';
-                }
-            }
-        }
-        $datatable = '<tr class="LC_odd_row">'.
-                     '<td><span class="LC_nobreak">'.$lt{'nondc'}.
-                     '</span></td><td class="LC_left_item"><table>';
-        foreach my $item ('author','course') {
-            $datatable .= '<tr><td><span class="LC_nobreak"><label>'.
-                          '<input type="checkbox" name="can_createuser" '.
-                          $checked{$item}.' value="'.$item.'" />'.
-                          $lt{$item}.'</label><span></td></tr>';
-        }
-        $datatable .= '</table></td></tr>';
         $$rowtotal ++;
-        my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
         my $rowcount = 0;
+        my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
         if (ref($rules) eq 'HASH') {
             if (keys(%{$rules}) > 0) {
                 $datatable .= &user_formats_row('username',$settings,$rules,
@@ -1341,6 +1331,50 @@
                 $rowcount ++;
             }
         }
+    } elsif ($position eq 'middle') {
+        my @creators = ('author','course');
+        my %lt = &usercreation_types();
+        my %checked;
+        if (ref($settings) eq 'HASH') {
+            if (ref($settings->{'cancreate'}) eq 'HASH') {
+                foreach my $item (@creators) {
+                    $checked{$item} = $settings->{'cancreate'}{$item};
+                }
+            } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
+                foreach my $item (@creators) {
+                    if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
+                        $checked{$item} = 'none';
+                    }
+                }
+            }
+        }
+        my $rownum = 0;
+        foreach my $item (@creators) {
+            $rownum ++;
+            if ($checked{$item} eq '') {
+                $checked{$item} = 'any';
+            }
+            my $css_class;
+            if ($rownum%2) {
+                $css_class = '';
+            } else {
+                $css_class = ' class="LC_odd_row" ';
+            }
+            $datatable .= '<tr'.$css_class.'>'.
+                         '<td><span class="LC_nobreak">'.$lt{$item}.
+                         '</span></td><td align="right">';
+            foreach my $option ('any','official','unofficial','none') {
+                my $check = ' ';
+                if ($checked{$item} eq $option) {
+                    $check = ' checked="checked" ';
+                } 
+                $datatable .= '<span class="LC_nobreak"><label>'.
+                              '<input type="radio" name="can_createuser_'.
+                              $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
+                              $lt{$option}.'</label>&nbsp;&nbsp;</span>';
+            }
+            $datatable .= '</td></tr>';
+        }
     } else {
         my @contexts = ('author','course','domain');
         my @authtypes = ('int','krb4','krb5','loc');
@@ -1437,6 +1471,18 @@
     return $output;
 }
 
+sub usercreation_types {
+    my %lt = &Apache::lonlocal::texthash (
+                    author     => 'When adding a co-author',
+                    course     => 'When adding a user to a course',
+                    any        => 'Any',
+                    official   => 'Institutional only ',
+                    unofficial => 'Non-institutional only',
+                    none       => 'None',
+    );
+    return %lt;
+} 
+
 sub authtype_names {
     my %lt = &Apache::lonlocal::texthash(
                       int    => 'Internal',
@@ -2820,7 +2866,7 @@
             }
             $resulttext .= '</ul>';
         } else {
-            $resulttext = &mt('No changes made to contact information.');
+            $resulttext = &mt('No changes made to contact information');
         }
     } else {
         $resulttext = '<span class="LC_error">'.
@@ -2831,7 +2877,7 @@
 
 sub modify_usercreation {
     my ($dom,%domconfig) = @_;
-    my ($resulttext,%curr_usercreation,%changes,%authallowed);
+    my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
     if (ref($domconfig{'usercreation'}) eq 'HASH') {
         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
@@ -2843,21 +2889,34 @@
                 );
     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
-    my @cancreate = &Apache::loncommon::get_env_multiple('form.can_createuser');
-    if (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
-        foreach my $type (@{$curr_usercreation{'cancreate'}}) {
-            if (!grep(/^\Q$type\E$/,@cancreate)) {
-                push(@{$changes{'cancreate'}},$type);
-            }
+    my @contexts = ('author','course');
+    foreach my $item(@contexts) {
+        $cancreate{$item} = $env{'form.can_createuser_'.$item};
+    }
+    if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
+        foreach my $item (@contexts) {
+            if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
+                push(@{$changes{'cancreate'}},$item);
+            } 
         }
-        foreach my $type (@cancreate) {
-            if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'cancreate'}})) {
-                push(@{$changes{'cancreate'}},$type);
+    } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
+        foreach my $item (@contexts) {
+            if (grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
+                if ($cancreate{$item} ne 'any') {
+                    push(@{$changes{'cancreate'}},$item);
+                }
+            } else {
+                if ($cancreate{$item} ne 'none') {
+                    push(@{$changes{'cancreate'}},$item);
+                }
             }
         }
     } else {
-        push(@{$changes{'cancreate'}},@cancreate);
+        foreach my $item ('author','course') {
+            push(@{$changes{'cancreate'}},$item);
+        }
     }
+
     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
             if (!grep(/^\Q$type\E$/,@username_rule)) {
@@ -2920,7 +2979,7 @@
 
     my %usercreation_hash =  (
             usercreation => {
-                              cancreate     => \@cancreate,
+                              cancreate     => \%cancreate,
                               username_rule => \@username_rule,
                               id_rule       => \@id_rule,
                               authtypes     => \%authhash,
@@ -2933,15 +2992,19 @@
         if (keys(%changes) > 0) {
             $resulttext = &mt('Changes made:').'<ul>';
             if (ref($changes{'cancreate'}) eq 'ARRAY') {
-                my $chgtext = '<ul>';
-                foreach my $type (@cancreate) {
-                    $chgtext .= '<li>'.$title{$type}.'</li>';
-                }
-                $chgtext .= '</ul>';
-                if (@cancreate > 0) {
-                    $resulttext .= '<li>'.&mt('Creation of new users is permitted by a Domain Coordinator, and also by other users when: ').$chgtext.'</li>';
-                } else {
-                    $resulttext .= '<li>'.&mt("Creation of new users is now only allowed when the user's role is Domain Coordinator.").'</li>';
+                my %lt = &usercreation_types();
+                foreach my $type (@{$changes{'cancreate'}}) {
+                    my $chgtext; 
+                    if ($cancreate{$type} eq 'none') {
+                        $chgtext = $lt{$type}.' '.&mt('creation of new users is not permitted, except by a Domain Coordinator.');
+                    } elsif ($cancreate{$type} eq 'any') {
+                        $chgtext = $lt{$type}.' '.&mt('creation of new users is permitted for both institutional and non-institutional usernames.'); 
+                    } elsif ($cancreate{$type} eq 'official') {
+                        $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for institutional usernames.',$lt{$type});
+                    } elsif ($cancreate{$type} eq 'unofficial') {
+                        $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for non-institutional usernames.',$lt{$type});
+                    }
+                    $resulttext .= '<li>'.$chgtext.'</li>';
                 }
             }
             if (ref($changes{'username_rule'}) eq 'ARRAY') {

--raeburn1197488693--