[LON-CAPA-cvs] cvs: loncom /auth lonroles.pm

www lon-capa-cvs-allow@mail.lon-capa.org
Wed, 30 Jan 2008 01:18:58 -0000


www		Tue Jan 29 20:18:58 2008 EDT

  Modified files:              
    /loncom/auth	lonroles.pm 
  Log:
  Don't go to non-exising authorspaces
  
  
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.182 loncom/auth/lonroles.pm:1.183
--- loncom/auth/lonroles.pm:1.182	Sat Jan 26 16:12:32 2008
+++ loncom/auth/lonroles.pm	Tue Jan 29 20:18:58 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.182 2008/01/26 21:12:32 www Exp $
+# $Id: lonroles.pm,v 1.183 2008/01/30 01:18:58 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -134,10 +134,12 @@
                     last;
                 }
 # Is this a recent ad-hoc CA-role?
-                if (my ($domain,$coursenum) =
-		    ($envkey =~ m-^form\.ca\./($match_domain)/($match_courseid)$-)) {
-                    if ($dcroles{$domain}) {
-                        &check_privs($domain,$coursenum,$then,$now,'ca');
+                if (my ($domain,$user) =
+		    ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
+                    if (($dcroles{$domain}) && (&is_author_homeserver($user,$domain))) {
+                        &check_privs($domain,$user,$then,$now,'ca');
+                    } else {
+                        delete($env{$envkey});
                     }
                     last;
                 }
@@ -147,7 +149,7 @@
                     if ($dcroles{$domain}) {
                         my $user=$env{'form.adhoccauname.'.$domain};
                         if (!$user) { $user=$env{'form.adhoccaunamerecent.'.$domain} };
-                        if (($user) && ($user=~/$match_username/)) { 
+                        if (($user) && ($user=~/$match_username/) && (&is_author_homeserver($user,$domain))) { 
                            &check_privs($domain,$user,$then,$now,'ca');
                            $env{'form.ca./'.$domain.'/'.$user}=1;
 		       }
@@ -905,6 +907,20 @@
     return $roletext;
 }
 
+sub is_author_homeserver {
+    my ($uname,$udom)=@_;
+    my $home = &Apache::lonnet::homeserver($uname,$udom);
+    my @ids=&Apache::lonnet::current_machine_ids();
+    foreach my $id (@ids) { 
+       if ($id eq $home) { 
+          if (-e "/home/".$uname."/public_html") {
+             return 1;
+          }
+       }
+    }
+    return 0;
+}
+
 sub check_privs {
     my ($cdom,$cnum,$then,$now,$checkrole) = @_;
     my $cckey = 'user.role.'.$checkrole.'./'.$cdom.'/'.$cnum;