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

raeburn raeburn@source.lon-capa.org
Wed, 05 Jan 2011 18:42:53 -0000


raeburn		Wed Jan  5 18:42:53 2011 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm lonuserutils.pm 
  Log:
  - Additional args for lonuserutils::check_usertype() -  refs to hashes for
    curr_rules and got_rules.
    - only use rules currently in force when determining usertype (official or unofficial)
      based on format of sername. Domain config sets rules in force.
  
  
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.352 loncom/interface/loncreateuser.pm:1.353
--- loncom/interface/loncreateuser.pm:1.352	Mon Oct 11 14:36:04 2010
+++ loncom/interface/loncreateuser.pm	Wed Jan  5 18:42:53 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.352 2010/10/11 14:36:04 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.353 2011/01/05 18:42:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -638,7 +638,6 @@
 
 sub entry_form {
     my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype) = @_;
-    my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
     my ($usertype,$inexact);
     if (ref($srch) eq 'HASH') {
         if (($srch->{'srchin'} eq 'dom') &&
@@ -646,9 +645,10 @@
             ($srch->{'srchtype'} eq 'exact') &&
             ($srch->{'srchdomain'} ne '') &&
             ($srch->{'srchterm'} ne '')) {
+            my (%curr_rules,%got_rules);
             my ($rules,$ruleorder) =
                 &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
-            $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
+            $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
         } else {
             $inexact = 1;
         }
@@ -942,7 +942,8 @@
         my ($rules,$ruleorder) =
             &Apache::lonnet::inst_userrules($ccdomain,'username');
             $usertype =
-                &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules);
+                &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
+                                                       \%curr_rules,\%got_rules);
         my $cancreate =
             &Apache::lonuserutils::can_create_user($ccdomain,$context,
                                                    $usertype);
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.133 loncom/interface/lonuserutils.pm:1.134
--- loncom/interface/lonuserutils.pm:1.133	Mon Nov 15 18:06:15 2010
+++ loncom/interface/lonuserutils.pm	Wed Jan  5 18:42:53 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.133 2010/11/15 18:06:15 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.134 2011/01/05 18:42:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5271,18 +5271,40 @@
 }
 
 sub check_usertype {
-    my ($dom,$uname,$rules) = @_;
+    my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
     my $usertype;
-    if (ref($rules) eq 'HASH') {
-        my @user_rules = keys(%{$rules});
-        if (@user_rules > 0) {
-            my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
-            if (keys(%rule_check) > 0) {
-                $usertype = 'unofficial';
-                foreach my $item (keys(%rule_check)) {
-                    if ($rule_check{$item}) {
-                        $usertype = 'official';
-                        last;
+    if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
+        if (!$got_rules->{$dom}) {
+            my %domconfig = &Apache::lonnet::get_dom('configuration',
+                                              ['usercreation'],$dom);
+            if (ref($domconfig{'usercreation'}) eq 'HASH') {
+                foreach my $item ('username','id') {
+                    if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
+                        $curr_rules->{$dom}{$item} =
+                                $domconfig{'usercreation'}{$item.'_rule'};
+                    }
+                }
+            }
+            $got_rules->{$dom} = 1;
+        }
+        if (ref($rules) eq 'HASH') {
+            my @user_rules;
+            if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
+                foreach my $rule (keys(%{$rules})) {
+                    if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
+                        push(@user_rules,$rule);
+                    }
+                } 
+            }
+            if (@user_rules > 0) {
+                my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
+                if (keys(%rule_check) > 0) {
+                    $usertype = 'unofficial';
+                    foreach my $item (keys(%rule_check)) {
+                        if ($rule_check{$item}) {
+                            $usertype = 'official';
+                            last;
+                        }
                     }
                 }
             }