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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Mon, 19 May 2008 17:55:40 -0000


raeburn		Mon May 19 13:55:40 2008 EDT

  Modified files:              
    /loncom/auth	lonroles.pm 
  Log:
  - Domain Coordinator selection of ad hoc co-author role.
    - "Select Author" link triggers pop-up window with display of authors in domain.
    - Selection of author from list causes roles page to auto-submit.
    - Eliminated distinction between "new" ad hoc CA role and previously selected one.
    - Added redirection to switchserver, if current session is not on homeserver of selected author (needs testing).  
  
  
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.192 loncom/auth/lonroles.pm:1.193
--- loncom/auth/lonroles.pm:1.192	Wed May 14 21:00:37 2008
+++ loncom/auth/lonroles.pm	Mon May 19 13:55:38 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.192 2008/05/15 01:00:37 raeburn Exp $
+# $Id: lonroles.pm,v 1.193 2008/05/19 17:55:38 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -154,42 +154,34 @@
                     }
                     last;
                 }
-# Is this a recent ad-hoc CA-role?
+# Is this an ad-hoc CA-role?
                 if (my ($domain,$user) =
 		    ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
-                   # See if still allowed
+                   # Check if author blocked ca-access
                     my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
                     if ($blocked{'domcoord.author'} eq 'blocked') {
                        delete($env{$envkey});
                        $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
                        last;
                     }
-                    if (($dcroles{$domain}) && (&is_author_homeserver($user,$domain))) {
-                        &check_privs($domain,$user,$then,$now,'ca');
+                    if ($dcroles{$domain}) {
+                        my ($server_status,$home) = &check_author_homeserver($user,$domain);
+                        if (($server_status eq 'ok') || ($server_status eq 'switchserver')) {
+                            &check_privs($domain,$user,$then,$now,'ca');
+                            if ($server_status eq 'switchserver') {
+                                my $trolecode = 'ca./'.$domain.'/'.$user; 
+                                my $switchserver = '/adm/switchserver?'
+                                                  .'otherserver='.$home.'&role='.$trolecode;
+                                $r->internal_redirect($switchserver);
+                            }
+                        } else {
+                            delete($env{$envkey});
+                        }
                     } else {
                         delete($env{$envkey});
                     }
                     last;
                 }
-# Is this a new ad-hoc CA-role?
-                if (my ($domain) =
-                    ($envkey =~ m-^form\.adhocca\./($match_domain)$-)) {
-                    my $user=$env{'form.adhoccauname.'.$domain};
-                    if (!$user) { $user=$env{'form.adhoccaunamerecent.'.$domain} };
-                   # See if that is even allowed
-                    my %blocked=&Apache::lonnet::get('environment',['domcoord.author'],$domain,$user);
-                    if ($blocked{'domcoord.author'} eq 'blocked') {
-                       $env{'user.error.msg'}=':::1:User '.$user.' in domain '.$domain.' blocked domain coordinator access';
-                       last;
-                    }
-                    if ($dcroles{$domain}) {
-                        if (($user) && ($user=~/$match_username/) && (&is_author_homeserver($user,$domain))) { 
-                           &check_privs($domain,$user,$then,$now,'ca');
-                           $env{'form.ca./'.$domain.'/'.$user}=1;
-		       }
-                    }
-                    last;
-                }
             }
         }
 
@@ -770,7 +762,8 @@
 
     if ($numdc > 0) {
         $r->print(&coursepick_jscript());
-        $r->print(&Apache::loncommon::coursebrowser_javascript());
+        $r->print(&Apache::loncommon::coursebrowser_javascript().
+                  &Apache::loncommon::authorbrowser_javascript());
     }
     &print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
     my $tremark='';
@@ -1025,18 +1018,21 @@
     return $roletext;
 }
 
-sub is_author_homeserver {
+sub check_author_homeserver {
     my ($uname,$udom)=@_;
+    if (($uname eq '') || ($udom eq '')) {
+        return ('fail','');
+    }
     my $home = &Apache::lonnet::homeserver($uname,$udom);
+    if (&Apache::lonnet::host_domain($home) ne $udom) {
+        return ('fail',$home);
+    }
     my @ids=&Apache::lonnet::current_machine_ids();
-    foreach my $id (@ids) { 
-       if ($id eq $home) { 
-          if (-e "/home/".$uname."/public_html") {
-             return 1;
-          }
-       }
+    if (grep(/^\Q$home\E$/,@ids)) {
+        return ('ok',$home);
+    } else {
+        return ('switchserver',$home);
     }
-    return 0;
 }
 
 sub check_privs {
@@ -1138,7 +1134,7 @@
 }
 
 sub courselink {
-    my ($dcdom,$rowtype,$selecttype) = @_;
+    my ($dcdom,$rowtype) = @_;
     my $courseform=&Apache::loncommon::selectcourse_link
                    ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
                     'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
@@ -1190,6 +1186,13 @@
     return $verify_script;
 }
 
+sub coauthorlink {
+    my ($dcdom,$rowtype) = @_;
+    my $coauthorform=&Apache::loncommon::selectauthor_link('rolechoice',$dcdom);
+    my $hiddenitems = '<input type="hidden" name="adhoccauname'.$rowtype.'_'.$dcdom.'" value="" />';
+    return $coauthorform.$hiddenitems;
+}
+
 sub display_cc_role {
     my $rolekey = shift;
     my $roletext;
@@ -1228,15 +1231,14 @@
                  ' <td colspan="5"><table><tr><td><span class="LC_rolesinfo">'
                  .&mt('[_1]Ad hoc[_2] roles in domain [_3] --',
                  '<span class="LC_cusr_emph">','</span>',$dcdom).'</span></td><td>';
-    my $selectlink = &courselink($dcdom,$rowtype);
+    my $selectcclink = &courselink($dcdom,$rowtype);
     my $ccrole = &Apache::lonnet::plaintext('cc');
     my $carole = &Apache::lonnet::plaintext('ca');
-    my $inputlink='<input type="text" size="10" name="adhoccauname'.$rowtype.'.'.$dcdom.'" />';
-    my $gobutton='<input type="submit" name="adhocca./'.$dcdom.'" value="'.&mt('Go').'" />';
+    my $selectcalink = &coauthorlink($dcdom,$rowtype);
     $output.= '<span class="LC_rolesinfo">'.
-            &mt('[_1]: [_2]',$ccrole,$selectlink).
+            &mt('[_1]: [_2]',$ccrole,$selectcclink).
             '</span><br /></td><td>&nbsp;&nbsp;</td><td><span class="LC_rolesinfo">'.
-            &mt('[_1]: [_2] [_3]',$carole,$inputlink,$gobutton).
+            &mt('[_1]: [_2]',$carole,$selectcalink).
             '</span><br /></td></tr></table></td></tr>'.
             '<tr><td colspan="5" height="3"></td></tr>'."\n";
     return $output;