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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Tue, 11 Dec 2007 01:17:18 -0000


This is a MIME encoded message

--raeburn1197335838
Content-Type: text/plain

raeburn		Mon Dec 10 20:17:18 2007 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm 
  Log:
  - default role for display of user lists in course context set to "student"
  - context type 'construction_space' renamed 'author', for consistency with domainprefs.
  - move generation of alert messages from namespacing checks for username and student/employeeID moved to &print_namespacing_alerts().
  - adding chgdates as an option for modification of selected users with both active and future roles.
  
  
--raeburn1197335838
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071210201718.txt"

Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.12 loncom/interface/lonuserutils.pm:1.13
--- loncom/interface/lonuserutils.pm:1.12	Wed Dec  5 23:03:36 2007
+++ loncom/interface/lonuserutils.pm	Mon Dec 10 20:17:16 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.12 2007/12/06 04:03:36 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.13 2007/12/11 01:17:16 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -96,7 +96,7 @@
         }
     } elsif ($context eq 'domain') {
         $scope = '/'.$env{'request.role.domain'}.'/';
-    } elsif ($context eq 'construction_space') {
+    } elsif ($context eq 'author') {
         $scope =  '/'.$env{'user.domain'}.'/'.$env{'user.name'};
     }
     if ($context eq 'domain') {
@@ -211,7 +211,7 @@
     # domain context   
     #
     # Role types
-    my @roletypes = ('domain','construction_space','course');
+    my @roletypes = ('domain','author','course');
     my %lt = &role_type_names();
     #
     # build up the menu information to be passed to
@@ -233,7 +233,7 @@
         my @roles;
         if ($roletype eq 'domain') {
             @roles = &domain_roles();
-        } elsif ($roletype eq 'construction_space') {
+        } elsif ($roletype eq 'author') {
             @roles = &construction_space_roles();
         } else {
             @roles = &course_roles('domain');
@@ -254,7 +254,7 @@
     }
     my $result = &Apache::loncommon::linked_select_forms
         ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
-         'roletype','showrole',\%select_menus,['domain','construction_space','course']);
+         'roletype','showrole',\%select_menus,['domain','author','course']);
     return $result;
 }
 
@@ -659,7 +659,7 @@
     my $formname;
     if ($context eq 'course') {
         $formname = 'document.studentform';
-    } elsif ($context eq 'construction_space') {
+    } elsif ($context eq 'author') {
         $formname = 'document.studentform';
     } elsif ($context eq 'domain') {
         $formname = 'document.studentform';
@@ -710,7 +710,7 @@
         $Str .= '<h3>'.&mt('Settings for assigning roles:').'</h3>'."\n".
                 &mt('Pick the action to take on roles for these users:').'<br /><span class="LC_nobreak"><label><input type="radio" name="roleaction" value="norole" checked="checked" />&nbsp;'.&mt('No role changes').'</label>&nbsp;&nbsp;&nbsp;<label><input type="radio" name="roleaction" value="domain" />&nbsp;'.&mt('Add a domain role').'</label>&nbsp;&nbsp;&nbsp;<label><input type="radio" name="roleaction" value="course" />&nbsp;'.&mt('Add a course role').'</label></span>';
     }
-    if ($context eq 'construction_space') {
+    if ($context eq 'author') {
         $Str .= '<h3>'.&mt('Default role')."</h3>\n".
                 &mt('Choose the role to assign to users without one specified in the uploaded file');
     } elsif ($context eq 'course') {
@@ -724,7 +724,7 @@
     my ($options,$cb_script,$coursepick) = &default_role_selector($context,'defaultrole',1);
     if ($context eq 'domain') {
         $Str .= '<span class="LC_role_level">'.&mt('Domain Level').'</span><br />'.$options.'<br /><br /><span class="LC_role_level">'.&mt('Course Level').'</span><br />'.$cb_script.$coursepick;
-    } elsif ($context eq 'construction_space') {
+    } elsif ($context eq 'author') {
         $Str .= $options;
     } else {
         $Str .= '<table><tr><td><span class="LC_nobreak"<b>'.&mt('role').':&nbsp;</b>'.
@@ -763,7 +763,7 @@
     if ($context eq 'domain') {
         $output .= '<label><input type="checkbox" name="recurseid"'.
                    ' value="yes">'. 
-  &mt('Update ID/Student Number in courses in which user is an Active or Future student, (if forcing change).').
+  &mt('Update ID/Student Number in courses in which user is Active/Future student,<br />(if forcing change).').
                    '</label></p>'."\n";
     }
     return $output;
@@ -924,7 +924,7 @@
     my $dateDefault;
     if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
         $dateDefault = '&nbsp;';
-    } elsif ($mode ne 'construction_space' && $mode ne 'domain') {
+    } elsif ($mode ne 'author' && $mode ne 'domain') {
         if (($bulkaction eq 'reenable') || 
             ($bulkaction eq 'activate') || 
             ($bulkaction eq 'chgdates')) { 
@@ -986,7 +986,7 @@
     my ($context,$checkpriv) = @_;
     my %customroles;
     my ($options,$coursepick,$cb_jscript);
-    if ($context ne 'construction_space') {
+    if ($context ne 'author') {
         %customroles = &my_custom_roles();
     }
 
@@ -1000,7 +1000,7 @@
                ' <option value="">'.&mt('Please select').'</option>'."\n"; 
     if ($context eq 'course') {
         $options .= &default_course_roles($context,$checkpriv,%customroles);
-    } elsif ($context eq 'construction_space') {
+    } elsif ($context eq 'author') {
         my @roles = &construction_space_roles($checkpriv);
         foreach my $role (@roles) {
            my $plrole=&Apache::lonnet::plaintext($role);
@@ -1129,7 +1129,7 @@
 sub curr_role_permissions {
     my ($context,$setting,$checkpriv) = @_; 
     my @roles;
-    if ($context eq 'construction_space') {
+    if ($context eq 'author') {
         @roles = &construction_space_roles($checkpriv);
     } elsif ($context eq 'domain') {
         if ($setting eq 'course') {
@@ -1170,7 +1170,11 @@
         ($env{'form.Status'});
 
     if ($env{'form.showrole'} eq '') {
-        $env{'form.showrole'} = 'Any';
+        if ($context eq 'course') {
+            $env{'form.showrole'} = 'st';
+        } else {
+            $env{'form.showrole'} = 'Any';            
+        }
     }
     if (! defined($env{'form.output'}) ||
         $env{'form.output'} !~ /^(csv|excel|html)$/ ) {
@@ -1297,7 +1301,7 @@
                          \%advrolehash,$permission);
     } else {
         my (%cstr_roles,%dom_roles);
-        if ($context eq 'construction_space') {
+        if ($context eq 'author') {
             # List co-authors and assistant co-authors
             my @possroles = ('ca','aa');
             %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
@@ -1313,7 +1317,7 @@
                                          \%userinfo,$dom_roles{$key},$permission);
                     }
                 }
-            } elsif ($env{'form.roletype'} eq 'construction_space') {
+            } elsif ($env{'form.roletype'} eq 'author') {
                 my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
                 my %coauthors;
                 foreach my $key (keys(%dom_roles)) {
@@ -1392,12 +1396,12 @@
         }
     }
     if (keys(%userlist) == 0) {
-        if ($context eq 'construction_space') {
+        if ($context eq 'author') {
             $r->print(&mt('There are no co-authors to display.')."\n");
         } elsif ($context eq 'domain') {
             if ($env{'form.roletype'} eq 'domain') {
                 $r->print(&mt('There are no users with domain roles to display.')."\n");
-            } elsif ($env{'form.roletype'} eq 'construction_space') {
+            } elsif ($env{'form.roletype'} eq 'author') {
                 $r->print(&mt('There are no authors or co-authors to display.')."\n");
             } elsif ($env{'form.roletype'} eq 'course') {
                 $r->print(&mt('There are no course users to display')."\n"); 
@@ -1433,7 +1437,7 @@
     foreach my $item (keys(%{$rolehash})) {
         @{$userlist->{$item}} = ();
         my %userdata;
-        if ($context eq 'construction_space' || $context eq 'course') { 
+        if ($context eq 'author' || $context eq 'course') { 
             ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
                 split(/:/,$item);
             ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
@@ -1444,7 +1448,7 @@
                     split(/:/,$item);
                 ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
                 &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
-            } elsif ($env{'form.roletype'} eq 'construction_space') {
+            } elsif ($env{'form.roletype'} eq 'author') {
                 if (ref($rolehash->{$item}) eq 'HASH') {
                     $userdata{'extent'} = $item;
                     foreach my $key (keys(%{$rolehash->{$item}})) {
@@ -1883,7 +1887,7 @@
                       );
     if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
         $lt{'extent'} = &mt('Course(s): description, section(s), status');
-    } elsif ($context eq 'construction_space') {
+    } elsif ($context eq 'author') {
         $lt{'extent'} = &mt('Author'); 
     }
     my @cols = ('username','domain','id','fullname');
@@ -1896,7 +1900,7 @@
     if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
         push(@cols,'role');
     }
-    if ($context eq 'domain' && ($env{'form.roletype'} eq 'construction_space' ||
+    if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
                                 $env{'form.roletype'} eq 'course')) {
         push (@cols,'extent');
     }
@@ -2073,7 +2077,7 @@
                     delete($userlist->{$user});
                     next;
                 }
-            } elsif ($env{'form.roletype'} eq 'construction_space') {
+            } elsif ($env{'form.roletype'} eq 'author') {
                 ($uname,$udom,$role) = split(/:/,$user,-1);
             } elsif ($env{'form.roletype'} eq 'course') {
                 ($uname,$udom,$role) = split(/:/,$user);
@@ -2268,9 +2272,9 @@
 
 sub role_type_names {
     my %lt = &Apache::lonlocal::texthash (
-                         'domain'             => 'Domain Roles',
-                         'construction_space' => 'Co-Author Roles',
-                         'course'             => 'Course Roles',
+                         'domain' => 'Domain Roles',
+                         'author' => 'Co-Author Roles',
+                         'course' => 'Course Roles',
              );
     return %lt;
 }
@@ -2291,10 +2295,6 @@
 <option value="chgdates">'.$lt{'chgdates'}.'</option>';
         $choices{'dates'} = 1;
     } else {
-        if ($statusmode eq 'Active' || $statusmode eq 'Future') {
-            $options .= '
-<option value="revoke">'.$lt{'revoke'}.'</option>';
-        }
         if ($statusmode eq 'Future') {
             $options .= '
 <option value="activate">'.$lt{'activate'}.'</option>';
@@ -2304,6 +2304,12 @@
 <option value="reenable">'.$lt{'reenable'}.'</option>';
             $choices{'dates'} = 1;
         }
+        if ($statusmode eq 'Active' || $statusmode eq 'Future') {
+            $options .= '
+<option value="chgdates">'.$lt{'chgdates'}.'</option>
+<option value="revoke">'.$lt{'revoke'}.'</option>';
+            $choices{'dates'} = 1;
+        }
     }
     if ($context eq 'domain') {
         $options .= '
@@ -2544,7 +2550,7 @@
                 $description .= &mt('All users in course with [_1] roles',$rolefilter);
             }
         }
-    } elsif ($context eq 'construction_space') {
+    } elsif ($context eq 'author') {
         $description = &mt('Author space for [_1].').' ';
         if ($statusmode eq 'Expired') {
             $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
@@ -2576,7 +2582,7 @@
                     $description .= &mt('All users in domain with [_1] roles',$rolefilter);
                 }
             }
-        } elsif ($env{'form.roletype'} eq 'construction_space') {
+        } elsif ($env{'form.roletype'} eq 'author') {
             if ($statusmode eq 'Expired') {
                 $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
             } elsif ($statusmode eq 'Future') {
@@ -2902,7 +2908,7 @@
         } elsif ($setting eq 'course') {
             $defaultrole = $env{'form.courserole'};
         }  
-    } elsif ($context eq 'construction_space') {
+    } elsif ($context eq 'author') {
         $defaultrole = $env{'form.defaultrole'};
     }
     if ($context eq 'domain' && $setting eq 'course') { 
@@ -2925,7 +2931,7 @@
         #######################################
         if ($context eq 'course') {
             $r->print('<h3>'.&mt('Enrolling Users')."</h3>\n<p>\n");
-        } elsif ($context eq 'construction_space') {
+        } elsif ($context eq 'author') {
             $r->print('<h3>'.&mt('Updating Co-authors')."</h3>\n<p>\n");
         } else {
             $r->print('<h3>'.&mt('Adding/Modifying Users')."</h3>\n<p>\n");
@@ -3065,6 +3071,8 @@
                                 next if ($alerts{'username'}{$domain}{$username});
                             }
                         }
+                    } else {
+# FIXME check if user info can be updated.   
                     }
                     if ($id ne '') {
                         if (!$newuser) {
@@ -3117,7 +3125,7 @@
                             $r->print('<br />'. 
       &mt('<b>[_1]</b>: Unable to enroll.  No password specified.',$username)
                                      );
-                        } elsif ($context eq 'construction_space') {
+                        } elsif ($context eq 'author') {
                             $r->print('<br />'.
       &mt('<b>[_1]</b>: Unable to add co-author.  No password specified.',$username)
                                      );
@@ -3143,39 +3151,7 @@
                       &mt('Authentication changed for [_1] existing users.',
                           $counts{'auth'})."</p>\n");
         }
-        if (keys(%alerts) > 0) {
-            if (ref($alerts{'username'}) eq 'HASH') {
-                foreach my $dom (sort(keys(%{$alerts{'username'}}))) {
-                    my $count;
-                    if (ref($alerts{'username'}{$dom}) eq 'HASH') {
-                        $count = keys(%{$alerts{'username'}{$dom}});
-                    } 
-                    my $domdesc = &Apache::lonnet::domain($domain,'description');
-                    if (ref($curr_rules{$dom}) eq 'HASH') {
-                        $r->print(&Apache::loncommon::instrule_disallow_msg(
-                                 'username',$domdesc,$count,'upload'));
-                    }
-                    $r->print(&Apache::loncommon::user_rule_formats($dom,
-                              $domdesc,$curr_rules{$dom}{'username'},
-                             'username'));
-                }
-            }
-            if (ref($alerts{'id'}) eq 'HASH') {
-                foreach my $dom (sort(keys(%{$alerts{'id'}}))) {
-                    my $count;
-                    if (ref($alerts{'id'}{$dom}) eq 'HASH') {
-                        $count = keys(%{$alerts{'id'}{$dom}});
-                    }
-                    my $domdesc = &Apache::lonnet::domain($domain,'description');
-                    if (ref($curr_rules{$dom}) eq 'HASH') {
-                        $r->print(&Apache::loncommon::instrule_disallow_msg(
-                                 'id',$domdesc,$count,'upload'));
-                    }
-                    $r->print(&Apache::loncommon::user_rule_formats($dom,
-                              $domdesc,$curr_rules{$dom}{'id'},'id'));
-                }
-            }
-        }
+        $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
         $r->print('<form name="uploadresult" action="/adm/createuser">');
         $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','prevphase','currstate']));
         $r->print('</form>');
@@ -3206,6 +3182,46 @@
     } # end of unless
 }
 
+sub print_namespacing_alerts {
+    my ($domain,$alerts,$curr_rules) = @_;
+    my $output;
+    if (ref($alerts) eq 'HASH') {
+        if (keys(%{$alerts}) > 0) {
+            if (ref($alerts->{'username'}) eq 'HASH') {
+                foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
+                    my $count;
+                    if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
+                        $count = keys(%{$alerts->{'username'}{$dom}});
+                    }
+                    my $domdesc = &Apache::lonnet::domain($domain,'description');
+                    if (ref($curr_rules->{$dom}) eq 'HASH') {
+                        $output .= &Apache::loncommon::instrule_disallow_msg(
+                                        'username',$domdesc,$count,'upload');
+                    }
+                    $output .= &Apache::loncommon::user_rule_formats($dom,
+                                   $domdesc,$curr_rules->{$dom}{'username'},
+                                   'username');
+                }
+            }
+            if (ref($alerts->{'id'}) eq 'HASH') {
+                foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
+                    my $count;
+                    if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
+                        $count = keys(%{$alerts->{'id'}{$dom}});
+                    }
+                    my $domdesc = &Apache::lonnet::domain($domain,'description');
+                    if (ref($curr_rules->{$dom}) eq 'HASH') {
+                        $output .= &Apache::loncommon::instrule_disallow_msg(
+                                              'id',$domdesc,$count,'upload');
+                    }
+                    $output .= &Apache::loncommon::user_rule_formats($dom,
+                                    $domdesc,$curr_rules->{$dom}{'id'},'id');
+                }
+            }
+        }
+    }
+}
+
 sub user_change_result {
     my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username,
         $userchg) = @_;
@@ -3308,14 +3324,14 @@
             } else {
                 $scope = $scopestem.'/'.$sec;
             }
-        } elsif ($context eq 'construction_space') {
+        } elsif ($context eq 'author') {
             ($uname,$udom,$role) = split(/\:/,$item,-1);
             $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
         } elsif ($context eq 'domain') {
             if ($setting eq 'domain') {
                 ($role,$uname,$udom) = split(/\:/,$item,-1);
                 $scope = '/'.$env{'request.role.domain'}.'/';
-            } elsif ($setting eq 'construction_space') { 
+            } elsif ($setting eq 'author') { 
                 ($uname,$udom,$role,$scope) = split(/\:/,$item);
             } elsif ($setting eq 'course') {
                 ($uname,$udom,$role,$cid,$sec,$type,$locktype) = 

--raeburn1197335838--