[LON-CAPA-cvs] cvs: loncom /auth lonacc.pm lonroles.pm migrateuser.pm switchserver.pm /interface lonmenu.pm

raeburn raeburn@source.lon-capa.org
Tue, 14 Apr 2009 23:52:11 -0000


This is a MIME encoded message

--raeburn1239753131
Content-Type: text/plain

raeburn		Tue Apr 14 23:52:11 2009 EDT

  Modified files:              
    /loncom/auth	lonacc.pm switchserver.pm migrateuser.pm lonroles.pm 
    /loncom/interface	lonmenu.pm 
  Log:
  - HTML documents uploaded directly to a course can be edited by a Course Coordinator (mdc priv).
  - "Edit this resource" link displayed in inline menu.
  - Link will switch server to course's home server if session is currently hoosted elsewehere (unless a lock is in place).
  
  - Deep linking:
    - origurl and symb args can be included in query string for switchserver call, so switched session will go to the same resource on the new server.
   
  Work in progress.
  Logging needed: changes, and by whom.
  
  
--raeburn1239753131
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090414235211.txt"

Index: loncom/auth/lonacc.pm
diff -u loncom/auth/lonacc.pm:1.124 loncom/auth/lonacc.pm:1.125
--- loncom/auth/lonacc.pm:1.124	Wed Dec 31 20:22:12 2008
+++ loncom/auth/lonacc.pm	Tue Apr 14 23:52:07 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Cookie Based Access Handler
 #
-# $Id: lonacc.pm,v 1.124 2008/12/31 20:22:12 raeburn Exp $
+# $Id: lonacc.pm,v 1.125 2009/04/14 23:52:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -449,6 +449,7 @@
 	if ($env{'request.course.id'}) {
 	    &Apache::lonnet::countacc($requrl);
 	    $requrl=~/\.(\w+)$/;
+            my $query=$r->args;
 	    if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
 		($requrl=~/^\/adm\/.*\/(aboutme|navmaps|smppg|bulletinboard)(\?|$ )/x) ||
 		($requrl=~/^\/adm\/wrapper\//) ||
@@ -456,7 +457,6 @@
 		($requrl=~m|\.problem/smpedit$|) ||
 		($requrl=~/^\/public\/.*\/syllabus$/)) {
 # ------------------------------------- This is serious stuff, get symb and log
-		my $query=$r->args;
 		my $symb;
 		if ($query) {
 		    &Apache::loncommon::get_unprocessed_cgi($query,['symb']);
@@ -503,6 +503,18 @@
 # ------------------------------------------------------- This is other content
 		&Apache::lonnet::courseacclog($requrl);    
 	    }
+            my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};;
+            my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};;
+            if ($requrl =~ m{^/+uploaded/\Q$cdom\E/\Q$cnum\E/docs/.+\.html?$}) {
+                if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
+                    if ($query) {
+                        &Apache::loncommon::get_unprocessed_cgi($query,['forceedit']);
+                        if ($env{'form.forceedit'}) {
+                            $env{'request.state'} = 'edit';
+                        }
+                    }
+                }
+            }
 	}
 	return OK;
     }
Index: loncom/auth/switchserver.pm
diff -u loncom/auth/switchserver.pm:1.21 loncom/auth/switchserver.pm:1.22
--- loncom/auth/switchserver.pm:1.21	Thu Nov 15 01:17:16 2007
+++ loncom/auth/switchserver.pm	Tue Apr 14 23:52:07 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Switch Servers Handler
 #
-# $Id: switchserver.pm,v 1.21 2007/11/15 01:17:16 albertel Exp $
+# $Id: switchserver.pm,v 1.22 2009/04/14 23:52:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -73,7 +73,7 @@
     if (!defined($handle)) { return FORBIDDEN; }
 
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-					    ['otherserver','role']);
+				['otherserver','role','origurl','symb']);
 
     my $switch_to=&Apache::lonnet::hostname($env{'form.otherserver'});
     if (! $env{'form.otherserver'}) {
@@ -132,6 +132,12 @@
 	      'username' => $env{'user.name'},
 	      'role'     => $env{'form.role'},
 	      'server'   => $r->dir_config('lonHostID'));
+    if ($env{'form.origurl'}) {
+        $info{'origurl'} = $env{'form.origurl'};
+    }
+    if ($env{'form.symb'}) {
+        $info{'symb'} = $env{'form.symb'};
+    }
     if ($env{'request.sso.login'}) {
 	$info{'sso.login'} = $env{'request.sso.login'};
     }
Index: loncom/auth/migrateuser.pm
diff -u loncom/auth/migrateuser.pm:1.14 loncom/auth/migrateuser.pm:1.15
--- loncom/auth/migrateuser.pm:1.14	Mon Sep 15 19:08:44 2008
+++ loncom/auth/migrateuser.pm	Tue Apr 14 23:52:07 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Starts a user off based of an existing token.
 #
-# $Id: migrateuser.pm,v 1.14 2008/09/15 19:08:44 raeburn Exp $
+# $Id: migrateuser.pm,v 1.15 2009/04/14 23:52:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -115,7 +115,12 @@
     }
 
     my $next_url='/adm/roles?selectrole=1&'.&escape($data{'role'}).'=1';
-
+    if ($data{'origurl'} ne '') {
+        $next_url .= '&orgurl='.&escape($data{'origurl'});
+    }
+    if ($data{'symb'} ne '') {
+        $next_url .= '&symb='.&escape($data{'symb'});
+    }
     
     &Apache::lonauth::success($r,$data{'username'},$data{'domain'},$home,
 			      $next_url,$extra_env);
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.218 loncom/auth/lonroles.pm:1.219
--- loncom/auth/lonroles.pm:1.218	Sat Apr 11 21:42:58 2009
+++ loncom/auth/lonroles.pm	Tue Apr 14 23:52:07 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.218 2009/04/11 21:42:58 raeburn Exp $
+# $Id: lonroles.pm,v 1.219 2009/04/14 23:52:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -423,6 +423,14 @@
 			if (($env{'form.orgurl'}) && 
 			    ($env{'form.orgurl'}!~/^\/adm\/flip/)) {
 			    my $dest=$env{'form.orgurl'};
+                            if ($env{'form.symb'}) {
+                                if ($dest =~ /\?/) {
+                                    $dest .= '&';
+                                } else {
+                                    $dest .= '?'
+                                }
+                                $dest .= 'symb='.$env{'form.symb'};
+                            }
 			    if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
 			    &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
                             if (($ferr) && ($tadv)) {
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.257 loncom/interface/lonmenu.pm:1.258
--- loncom/interface/lonmenu.pm:1.257	Wed Apr  1 14:43:06 2009
+++ loncom/interface/lonmenu.pm	Tue Apr 14 23:52:11 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.257 2009/04/01 14:43:06 hauer Exp $
+# $Id: lonmenu.pm,v 1.258 2009/04/14 23:52:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -523,6 +523,12 @@
         ### resource
         ###
         my $editbutton = '';
+        my $noeditbutton = 1;
+        my ($cnum,$cdom);
+        if ($env{'request.course.id'}) {
+            $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+            $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+        }
         if ($env{'user.author'}) {
             if ($env{'request.role'}=~/^(aa|ca|au)/) {
                 # Set defaults for authors
@@ -550,6 +556,7 @@
 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 		if (!$allowed) {
 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
+                    $noeditbutton = 0;
                 }
             }
             ##
@@ -558,30 +565,53 @@
             my $cfile='';
             my $cfuname='';
             my $cfudom='';
+            my $uploaded;
             if ($env{'request.filename'}) {
                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
-                $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
-                # Check that the user has permission to edit this resource
-                ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
-                if (defined($cfudom)) {
-		    my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
-		    my $allowed=0;
-		    my @ids=&Apache::lonnet::current_machine_ids();
-		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
-		    if ($allowed) {
-                        $cfile=$file;
+                if (defined($cnum) && defined($cdom)) {
+                    $uploaded = &is_course_upload($file,$cnum,$cdom);
+                }
+                if (!$uploaded) {
+                    $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
+                    # Check that the user has permission to edit this resource
+                    ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
+                    if (defined($cfudom)) {
+		        my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
+		        my $allowed=0;
+		        my @ids=&Apache::lonnet::current_machine_ids();
+		        foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
+		        if ($allowed) {
+                            $cfile=$file;
+                        }
                     }
                 }
-            }        
+            }
             # Finally, turn the button on or off
             if ($cfile && !$const_space) {
                 $editbutton=&switch
                     ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
                      "go('".$cfile."');","Edit this resource");
+                $noeditbutton = 0;
             } elsif ($editbutton eq '') {
                 $editbutton=&clear(6,1);
             }
         }
+        if (($noeditbutton) && ($env{'request.filename'})) { 
+            if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
+                my $file=&Apache::lonnet::declutter($env{'request.filename'});
+                if (defined($cnum) && defined($cdom)) {
+                    if (&is_course_upload($file,$cnum,$cdom)) {
+                        my $cfile = &edit_course_upload($file,$cnum,$cdom);
+                        if ($cfile) {
+                            $editbutton=&switch
+                                        ('','',6,1,'pcstr.gif','edit[_1]',
+                                         'resource[_2]',"go('".$cfile."');",
+                                         'Edit this resource');
+                        }
+                    }
+                }
+            }
+        }
         ###
         ###
 # Prepare the rest of the buttons
@@ -816,6 +846,42 @@
     return $result;
 }
 
+sub is_course_upload {
+    my ($file,$cnum,$cdom) = @_;
+    my $uploadpath = &LONCAPA::propath($cdom,$cnum);
+    $uploadpath =~ s{^\/}{};
+    if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
+        ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
+        return 1;
+    }
+    return;
+}
+
+sub edit_course_upload {
+    my ($file,$cnum,$cdom) = @_;
+    my $cfile;
+    if ($file =~/\.(htm|html|css|js|txt)$/) {
+        my $ext = $1;
+        my $url = &Apache::lonnet::hreflocation('',$file);
+        my $home = &Apache::lonnet::homeserver($cnum,$cdom);
+        my @ids=&Apache::lonnet::current_machine_ids();
+        my $dest;
+        if ($home && grep(/^\Q$home\E$/,@ids)) {
+            $dest = $url.'?forceedit=1';
+        } else {
+            unless (&Apache::lonnet::get_locks()) {
+                $dest = '/adm/switchserver?otherserver='.
+                        $home.'&role='.$env{'request.role'}.
+                        '&url='.$url.'&forceedit=1';
+            }
+        }
+        if ($dest) {
+            $cfile = &HTML::Entities::encode($dest,'"<>&');
+        }
+    }
+    return $cfile;
+}
+
 sub loadevents() {
     if ($env{'request.state'} eq 'construct' ||
 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }

--raeburn1239753131--