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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Wed, 16 Apr 2008 23:11:07 -0000


This is a MIME encoded message

--raeburn1208387467
Content-Type: text/plain

raeburn		Wed Apr 16 19:11:07 2008 EDT

  Modified files:              
    /loncom/interface	portfolio.pm 
  Log:
  - &get_name_dom() can now take $group as an (optional) argument.
  - arguments in calls to lonnet::dirlist() and lonnet::diskusage() modified to use new versions of these subs and to eliminate the need to call &propath() on session server side.
  
  
--raeburn1208387467
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080416191107.txt"

Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.190 loncom/interface/portfolio.pm:1.191
--- loncom/interface/portfolio.pm:1.190	Tue Feb  5 00:54:59 2008
+++ loncom/interface/portfolio.pm	Wed Apr 16 19:11:06 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # portfolio browser
 #
-# $Id: portfolio.pm,v 1.190 2008/02/05 05:54:59 raeburn Exp $
+# $Id: portfolio.pm,v 1.191 2008/04/16 23:11:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -183,7 +183,7 @@
         $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" /></td>');
         $r->print('<td>'.$version_flag.'</td>');
     } else { # this is a graded or handed back file
-        my ($user,$domain) = &get_name_dom();
+        my ($user,$domain) = &get_name_dom($env{'form.group'});
         my $permissions_hash = &Apache::lonnet::get_portfile_permissions($domain,$user);
         if (defined($$permissions_hash{$fullpath})) {
             foreach my $array_item (@{$$permissions_hash{$fullpath}}) {
@@ -231,7 +231,7 @@
     my $select_mode;
     my $checked_files;
     my $port_path = &get_port_path();
-    my ($uname,$udom) = &get_name_dom();
+    my ($uname,$udom) = &get_name_dom($group);
     my $access_admin_text = &mt('View Status');
     if ($can_setacl) {
         $access_admin_text = &mt('View/Change Status');
@@ -531,12 +531,12 @@
 }
 
 sub delete {
-    my ($r,$url)=@_;
+    my ($r,$url,$group)=@_;
     my @check;
     my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
     $file_name = &prepend_group($file_name);
     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
-    my ($uname,$udom) = &get_name_dom();
+    my ($uname,$udom) = &get_name_dom($group);
     if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
         $r->print(&mt('The file is locked and cannot be deleted.').'<br />');
         $r->print(&done('Back',$url));
@@ -556,7 +556,7 @@
     my ($r,$url,$group)=@_;
     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
     my $result;
-    my ($uname,$udom) = &get_name_dom();
+    my ($uname,$udom) = &get_name_dom($group);
     my $port_path = &get_port_path();
     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
                                                                         $uname);
@@ -615,10 +615,10 @@
 } 
 
 sub delete_dir_confirmed {
-    my ($r,$url)=@_;
+    my ($r,$url,$group)=@_;
     my $directory_name = $env{'form.currentpath'};
     $directory_name =~ s|/$||; # remove any trailing slash
-    my ($uname,$udom) = &get_name_dom();
+    my ($uname,$udom) = &get_name_dom($group);
     my $namespace = &get_namespace();
     my $port_path = &get_port_path();
     my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
@@ -643,9 +643,9 @@
 }
 
 sub rename {
-    my ($r,$url)=@_;
+    my ($r,$url,$group)=@_;
     my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
-    my ($uname,$udom) = &get_name_dom();
+    my ($uname,$udom) = &get_name_dom($group);
     $file_name = &prepend_group($file_name);
     if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
         $r->print("The file is locked and cannot be renamed.<br />");
@@ -661,7 +661,7 @@
 sub rename_confirmed {
     my ($r,$url,$group)=@_;
     my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
-    my ($uname,$udom) = &get_name_dom();
+    my ($uname,$udom) = &get_name_dom($group);
     my $port_path = &get_port_path();
     if ($filenewname eq '') {
 	$r->print('<span class="LC_error">'.
@@ -745,7 +745,7 @@
 
 sub display_access {
     my ($r,$url,$group,$can_setacl,$port_path,$action) = @_;
-    my ($uname,$udom) = &get_name_dom();
+    my ($uname,$udom) = &get_name_dom($group);
     my $file_name = $env{'form.currentpath'}.$env{'form.access'};
     $file_name = &prepend_group($file_name);
     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
@@ -959,7 +959,7 @@
     $r->print('<h3>'.&mt('Allowing others to retrieve file: [_1]',
               $port_path.$file_name).'</h3>'."\n");
     $file_name = &prepend_group($file_name);
-    my ($uname,$udom) = &get_name_dom();
+    my ($uname,$udom) = &get_name_dom($group);
     my ($errors,$outcome,$deloutcome,$new_values,$translation);
     if ($totalprocessed) {
         ($outcome,$deloutcome,$new_values,$translation) =
@@ -1754,12 +1754,11 @@
     my ($path,$fname,$group,$element) = @_;
     my $disk_quota = &get_quota($group);
     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
-
     my $portfolio_root = &get_portfolio_root();
     my $port_path = &get_port_path();
-    my ($uname,$udom) = &get_name_dom();
+    my ($uname,$udom) = &get_name_dom($group);
     # Fixme --- Move the checking for existing file to LOND error return
-    my @dir_list=&get_dir_list($portfolio_root,$path);
+    my @dir_list=&get_dir_list($portfolio_root,$path,$group);
     my $found_file = 0;
     my $locked_file = 0;
     foreach my $line (@dir_list) {
@@ -1773,7 +1772,8 @@
             } 
         }
     }
-    my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
+    my $getpropath = 1;
+    my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
 
     if (($current_disk_usage + $filesize) > $disk_quota){
         my $msg = '<span class="LC_error">'.
@@ -1897,7 +1897,7 @@
 
 sub lock_info {
     my ($r,$url,$group) = @_;
-    my ($uname,$udom) = &get_name_dom();
+    my ($uname,$udom) = &get_name_dom($group);
     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
                                                                        $uname);
     my $file_name = $env{'form.lockinfo'};
@@ -1939,7 +1939,7 @@
 }
 
 sub createdir {
-    my ($r,$url)=@_;
+    my ($r,$url,$group)=@_;
     my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
     if ($newdir eq '') {
     	$r->print('<span class="LC_error">'.
@@ -1949,7 +1949,7 @@
 	    return;
     }
     my $portfolio_root = &get_portfolio_root(); 
-    my @dir_list=&get_dir_list($portfolio_root);
+    my @dir_list=&get_dir_list($portfolio_root,undef,$group);
     my $found_file = 0;
     foreach my $line (@dir_list) {
         my ($filename)=split(/\&/,$line,2);
@@ -1962,7 +1962,7 @@
                       .&mt('Unable to create a directory named [_1].','<strong>'.$newdir.'</strong>')
                       .' '.&mt('A file or directory by that name already exists.').'</span><br />');
     } else {
-        my ($uname,$udom) = &get_name_dom();
+        my ($uname,$udom) = &get_name_dom($group);
         my $port_path = &get_port_path();
         my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
 	         $port_path.$env{'form.currentpath'}.$newdir);
@@ -1983,7 +1983,7 @@
 sub get_portfolio_root {
     my ($udom,$uname,$group) = @_;
     if (!(defined($udom)) || !(defined($uname))) {
-        ($uname,$udom) = &get_name_dom();
+        ($uname,$udom) = &get_name_dom($group);
     }
     my $path = '/userfiles/portfolio';
     if (!defined($group)) { 
@@ -1994,7 +1994,7 @@
     if (defined($group)) {
         $path = '/userfiles/groups/'.$group.'/portfolio';
     } 
-    return (&Apache::loncommon::propath($udom,$uname).$path);
+    return $path;
 }
 
 sub get_group_quota {
@@ -2009,21 +2009,23 @@
         $group_quota = $group_info{'quota'}; #expressed in Mb
         if ($group_quota) {
             $group_quota = 1000 * $group_quota; #expressed in k
-        } 
+        }
     }
     return $group_quota;
-} 
+}
 
 sub get_dir_list {
-    my ($portfolio_root,$path) = @_;
+    my ($portfolio_root,$path,$group) = @_;
     $path ||= $env{'form.currentpath'};
-    my ($uname,$udom) = &get_name_dom();
-    return &Apache::lonnet::dirlist($path,$udom,$uname,$portfolio_root);
+    my ($uname,$udom) = &get_name_dom($group);
+    my $getpropath = 1;
+    return &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
 }
 
 sub get_name_dom {
+    my ($group) = @_;
     my ($uname,$udom);
-    if (defined($env{'form.group'})) {
+    if (defined($group)) {
         $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
         $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
     } else {
@@ -2044,7 +2046,7 @@
 sub get_namespace {
     my $namespace = 'portfolio';
     if (defined($env{'form.group'})) {
-        my ($uname,$udom) = &get_name_dom();
+        my ($uname,$udom) = &get_name_dom($env{'form.group'});
         $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
     }
     return $namespace;
@@ -2158,8 +2160,8 @@
            &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
         $env{'form.group'} =~ s/\W//g;
 	$group = $env{'form.group'};
-        if ($group) {
-            ($uname,$udom) = &get_name_dom();
+        if ($group ne '') {
+            ($uname,$udom) = &get_name_dom($group);
             my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
 							       $group); 
             if (%curr_groups) {
@@ -2268,13 +2270,13 @@
         }
     } elsif ($env{'form.action'} eq 'delete') {
         if ($can_delete) {
-	    &delete($r,$url);
+	    &delete($r,$url,$group);
         } else {
             &missing_priv($r,$url,'delete');
         }
     } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
         if ($can_delete) {
-	    &delete_dir_confirmed($r,$url);
+	    &delete_dir_confirmed($r,$url,$group);
         } else {
             &missing_priv($r,$url,'delete');
         }
@@ -2294,7 +2296,7 @@
         $env{'form.selectfile'} = $env{'form.rename'};
         $env{'form.action'} = 'rename';
         if ($can_modify) {
-	    &rename($r,$url);
+	    &rename($r,$url,$group);
         } else {
             &missing_priv($r,$url,'rename');
         }
@@ -2319,7 +2321,7 @@
         }
     } elsif ($env{'form.createdir'}) {
         if ($can_upload) {
-	    &createdir($r,$url);
+	    &createdir($r,$url,$group);
         } else {
             &missing_priv($r,$url,'upload');
         }
@@ -2334,7 +2336,7 @@
             &Apache::lonhtmlcommon::clear_breadcrumbs();
             $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
         }
-        my @dir_list=&get_dir_list($portfolio_root);
+        my @dir_list=&get_dir_list($portfolio_root,undef,$group);
 	if ($dir_list[0] eq 'no_such_dir'){
 	    # two main reasons for this:
             #    1) never been here, so directory structure not created
@@ -2350,8 +2352,9 @@
 		$current_path = '/'; # force it back to the root        
 	    }
 	    # now grab the directory list again, for the first time
-	    @dir_list=&Apache::lonnet::dirlist($current_path,
-					    $udom,$uname,$portfolio_root);
+	    @dir_list=
+                &Apache::lonnet::dirlist($portfolio_root.$current_path,
+                                         $udom,$uname,$getpropath);
         }
 	# need to know if directory is empty so it can be removed if desired
 	my $is_empty=(@dir_list == 2);

--raeburn1208387467--