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

raeburn raeburn@source.lon-capa.org
Tue, 18 Jan 2011 23:37:48 -0000


raeburn		Tue Jan 18 23:37:48 2011 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm 
  Log:
  - Bug 6415.
  
  
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.134 loncom/interface/lonuserutils.pm:1.135
--- loncom/interface/lonuserutils.pm:1.134	Wed Jan  5 18:42:53 2011
+++ loncom/interface/lonuserutils.pm	Tue Jan 18 23:37:47 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.134 2011/01/05 18:42:53 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.135 2011/01/18 23:37:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4000,7 +4000,8 @@
                             official   => 'Institutional',
                             unofficial => 'Non-institutional',
                         );
-        map { $cancreate{$_} = &can_create_user($domain,$context,$_); } keys(%longtypes);
+        my $newuserdom = $env{'request.role.domain'};
+        map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
         # Get new users list
         foreach my $line (@userdata) {
             my @secs;
@@ -4155,25 +4156,33 @@
                     my (%rulematch,%inst_results,%idinst_results);
                     my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
                     if ($uhome eq 'no_host') {
-                        if ($userdomain ne $domain) {
-                            $r->print('<br />'.
-                                &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
-                                    '<b>'.$username.'</b>',$userdomain).'<br />'.
-                                &mt('The user does not already exist, and you may not create a new user in a different domain.'));
+                        if ($userdomain ne $newuserdom) {
+                            if ($context eq 'course') {
+                                $r->print('<br />'.
+                                          &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
+                                          '<b>'.$username.'</b>',$userdomain).'<br />');
+                            } elsif ($context eq 'author') {
+                                $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of the author.',
+                                        '<b>'.$username.'</b>',$userdomain).'<br />'); 
+                            } else {
+                                $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
+                                        '<b>'.$username.'</b>',$userdomain).'<br />');
+                            }
+                            $r->print(&mt('The user does not already exist, and you may not create a new user in a different domain.'));
                             next;
                         }
                         $checkid = 1;
                         $newuser = 1;
-                        my $user = $username.':'.$domain;
+                        my $user = $username.':'.$newuserdom;
                         my $checkhash;
                         my $checks = { 'username' => 1 };
-                        $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
+                        $checkhash->{$username.':'.$newuserdom} = { 'newuser' => 1, };
                         &Apache::loncommon::user_rule_check($checkhash,$checks,
                             \%alerts,\%rulematch,\%inst_results,\%curr_rules,
                             \%got_rules);
                         if (ref($alerts{'username'}) eq 'HASH') {
-                            if (ref($alerts{'username'}{$domain}) eq 'HASH') {
-                                if ($alerts{'username'}{$domain}{$username}) {
+                            if (ref($alerts{'username'}{$newuserdom}) eq 'HASH') {
+                                if ($alerts{'username'}{$newuserdom}{$username}) {
                                     $r->print('<br />'.
                                               &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
                                               &mt('Consequently, the user was not created.'));