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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Fri, 21 Dec 2007 17:27:57 -0000


This is a MIME encoded message

--raeburn1198258077
Content-Type: text/plain

raeburn		Fri Dec 21 12:27:57 2007 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm lonuserutils.pm 
  Log:
  loncreateuser.pm
  - &lonuserutils::can_modify_userinfo() used to determine if personal info field can be modified.
  - Replace $home with $uhome as name of homeserver variable for newly created user.
  
  lonuserutils.pm
  can_modify_userinfo() returns a hash with information about which personal data fields are modifiable, as determined by context (author, course or domain) and roles of user being modified.  DC sets the domain configuration for user modification.
  
  
--raeburn1198258077
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071221122757.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.218 loncom/interface/loncreateuser.pm:1.219
--- loncom/interface/loncreateuser.pm:1.218	Fri Dec 21 11:23:54 2007
+++ loncom/interface/loncreateuser.pm	Fri Dec 21 12:27:57 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.218 2007/12/21 16:23:54 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.219 2007/12/21 17:27:57 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1397,15 +1397,17 @@
 
 sub personal_data_display {
     my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_;
-    my ($output,$showforceid,%userenv,%domconfig);
+    my ($output,$showforceid,%userenv,%canmodify);
+    my @userinfo = ('firstname','middlename','lastname','generation',
+                    'permanentemail','id');
     if (!$newuser) {
         # Get the users information
         %userenv = &Apache::lonnet::get('environment',
                    ['firstname','middlename','lastname','generation',
                     'permanentemail','id'],$ccdomain,$ccuname);
-        %domconfig =
-            &Apache::lonnet::get_dom('configuration',['usermodification'],
-                                     $ccdomain);
+        %canmodify =
+            &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
+                                                       \@userinfo);
     }
     my %lt=&Apache::lonlocal::texthash(
                 'pd'             => "Personal Data",
@@ -1417,8 +1419,6 @@
                 'id'             => "ID/Student Number",
                 'lg'             => "Login Data"
     );
-    my @userinfo = ('firstname','middlename','lastname','generation',
-                    'permanentemail','id');
     my %textboxsize = (
                        firstname      => '15',
                        middlename     => '15',
@@ -1447,33 +1447,14 @@
                 $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
             }
         } else {
-            my $canmodify = 0;
-            if (&Apache::lonnet::allowed('mau',$ccdomain)) {
-                $canmodify = 1;
-            } else {
-                if (ref($domconfig{'usermodification'}) eq 'HASH') {
-                    if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
-                        foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
-                            if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
-                                if ($domconfig{'usermodification'}{$context}{$key}{$item}) { 
-                                    $canmodify = 1;
-                                    last;
-                                }
-                            }
-                        }
-                    }
-                } elsif ($context eq 'course') {
-                    $canmodify = 1;
-                }
-            }
-            if ($canmodify) {
+            if ($canmodify{$item}) {
                 $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
             } else {
                 $output .= $userenv{$item};
             }
             if ($item eq 'id') {
-                $showforceid = $canmodify; 
-            } 
+                $showforceid = $canmodify{$item};
+            }
         }
         $output .= &Apache::lonhtmlcommon::row_closure(1);
     }
@@ -1495,7 +1476,9 @@
     my $end       = '</span><br /><br />';
     my $rtnlink   = '<a href="javascript:backPage(document.userupdate,'.
                     "'$env{'form.prevphase'}','modify')".'" />'.
-                    &mt('Return to previous page').'</a>'.&Apache::loncommon::end_page();
+                    &mt('Return to previous page').'</a>'.
+                    &Apache::loncommon::end_page();
+    my $now = time;
     my $title;
     if (exists($env{'form.makeuser'})) {
 	$title='Set Privileges for New User';
@@ -1520,13 +1503,12 @@
     }
     &Apache::lonhtmlcommon::add_breadcrumb
        ({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
-         text=>"Set user role",
+         text=>$breadcrumb_text{'modify'},
          faq=>282,bug=>'Instructor Interface',},
         {href=>"/adm/createuser",
          text=>"Result",
          faq=>282,bug=>'Instructor Interface',});
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
-
     my %disallowed;
     $r->print(&update_result_form($uhome));
     # Check Inputs
@@ -1552,6 +1534,9 @@
 		  $end.$rtnlink);
 	return;
     }
+    if ($uhome eq 'no_host') {
+        $newuser = 1;
+    }
     if (! exists($env{'form.makeuser'})) {
         # Modifying an existing user, so check the validity of the name
         if ($uhome eq 'no_host') {
@@ -1589,7 +1574,6 @@
 	    return;
     }
 
-
     $r->print('<h3>'.&mt('User [_1] in domain [_2]',
 			 $env{'form.ccuname'}, $env{'form.ccdomain'}).'</h3>');
     my (%alerts,%rulematch,%inst_results,%curr_rules);
@@ -1616,7 +1600,7 @@
         my %checkhash;
         my %checks = ('id' => 1);
         %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
-            'newuser' => 1, 
+            'newuser' => $newuser, 
             'id' => $env{'form.cid'},
         );
         if ($env{'form.cid'} ne '') {
@@ -1650,10 +1634,10 @@
              $env{'form.cgeneration'},undef,$desiredhost,
              $env{'form.cpermanentemail'});
 	$r->print(&mt('Generating user').': '.$result);
-        my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
+        $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
                                                $env{'form.ccdomain'});
-        $r->print('<br />'.&mt('Home server').': '.$home.' '.
-                  &Apache::lonnet::hostname($home));
+        $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
+                  &Apache::lonnet::hostname($uhome));
     } elsif (($env{'form.login'} ne 'nochange') &&
              ($env{'form.login'} ne ''        )) {
 	# Modify user privileges
@@ -1764,33 +1748,12 @@
                 push(@longroles,&Apache::lonnet::plaintext($role)); 
             }
         }
-        foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') {
-            my $canmodify = 0;
-            if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
-                $canmodify = 1;
-            } else {
-                if ($context eq 'course' || $context eq 'author') {
-                    if (ref($domconfig{'usermodification'}) eq 'HASH') {
-                        if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
-                            foreach my $role (@userroles) {
-                                if (ref($domconfig{'usermodification'}{$context}{$role}) eq 'HASH') {
-                                    if ($domconfig{'usermodification'}{$context}{$role}{$item}) {
-                                        $canmodify = 1;
-                                        last;
-                                    }
-                                }
-                            }
-                        }
-                    }
-                } elsif ($context eq 'course') {
-                    if (grep(/^st$/,@userroles)) {
-                        $canmodify = 1;
-                    }
-                }
-            }
+        my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
+        my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
+        foreach my $item (@userinfo) {
             # Strip leading and trailing whitespace
             $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
-            if (!$canmodify) {
+            if (!$canmodify{$item}) {
                 if (defined($env{'form.c'.$item})) {
                     if ($env{'form.c'.$item} ne $userenv{$item}) {
                         push(@mod_disallowed,$item);
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.19 loncom/interface/lonuserutils.pm:1.20
--- loncom/interface/lonuserutils.pm:1.19	Fri Dec 21 10:22:01 2007
+++ loncom/interface/lonuserutils.pm	Fri Dec 21 12:27:57 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.19 2007/12/21 15:22:01 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.20 2007/12/21 17:27:57 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3810,6 +3810,61 @@
     return $cancreate;
 }
 
+sub can_modify_userinfo {
+    my ($context,$dom,$fields,$userroles) = @_;
+    my %domconfig =
+       &Apache::lonnet::get_dom('configuration',['usermodification'],
+                                $dom);
+    my %canmodify;
+    if (ref($fields) eq 'ARRAY') {
+        foreach my $field (@{$fields}) {
+            $canmodify{$field}  = 0;
+            if (&Apache::lonnet::allowed('mau',$dom)) {
+                $canmodify{$field} = 1;
+            } else {
+                if (ref($domconfig{'usermodification'}) eq 'HASH') {
+                    if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
+                        if (ref($userroles) eq 'ARRAY') {
+                            foreach my $role (@{$userroles}) {
+                                my $testrole;
+                                if ($role =~ /^cr\//) {
+                                    $testrole = 'cr';
+                                } else {
+                                    $testrole = $role;
+                                }
+                                if (ref($domconfig{'usermodification'}{$context}{$testrole}) eq 'HASH') {
+                                    if ($domconfig{'usermodification'}{$context}{$testrole}{$field}) {
+                                        $canmodify{$field} = 1;
+                                        last;
+                                    }
+                                }
+                            }
+                        } else {
+                            foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
+                                if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
+                                    if ($domconfig{'usermodification'}{$context}{$key}{$field}) {
+                                        $canmodify{$field} = 1;
+                                        last;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                } elsif ($context eq 'course') {
+                    if (ref($userroles) eq 'ARRAY') {
+                        if (grep(/^st$/,@{$userroles})) {
+                            $canmodify{$field} = 1;
+                        }
+                    } else {
+                        $canmodify{$field} = 1;
+                    }
+                }
+            }
+        }
+    }
+    return %canmodify;
+}
+
 sub check_usertype {
     my ($dom,$uname,$rules) = @_;
     my $usertype;

--raeburn1198258077--