[LON-CAPA-cvs] cvs: loncom /interface lonmeta.pm /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 12 Jan 2007 22:14:29 -0000


albertel		Fri Jan 12 17:14:29 2007 EDT

  Modified files:              
    /loncom/interface	lonmeta.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - trying to remove some code duplication
  
  
Index: loncom/interface/lonmeta.pm
diff -u loncom/interface/lonmeta.pm:1.195 loncom/interface/lonmeta.pm:1.196
--- loncom/interface/lonmeta.pm:1.195	Fri Jan 12 15:04:16 2007
+++ loncom/interface/lonmeta.pm	Fri Jan 12 17:13:51 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Metadata display handler
 #
-# $Id: lonmeta.pm,v 1.195 2007/01/12 20:04:16 raeburn Exp $
+# $Id: lonmeta.pm,v 1.196 2007/01/12 22:13:51 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1409,22 +1409,14 @@
 
 sub update_metadata_table {
     my ($uri) = @_;
-    my ($group,$file_name);
-    my ($udom,$uname,$remainder) =
-        ($uri=~m -^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$-);
-
-    if ($remainder =~ /^groups\/(\w+)\/portfolio(\/.+)$/) {
-        $group = $1;
-        $file_name = $2;
-    } elsif ($remainder =~ /^portfolio(\/.+)$/) {
-        $file_name = $1;
-    }
+    my ($type,$udom,$uname,$file_name,$group) =
+	&Apache::lonnet::parse_portfolio_url($uri);
     $file_name =~ s/\.meta$//;
     my $current_permissions =
         &Apache::lonnet::get_portfile_permissions($udom,$uname);
     my %access_controls =
         &Apache::lonnet::get_access_controls($current_permissions,$group,
-                                             $group.$file_name);
+                                             $file_name);
     my $access_hash = $access_controls{$file_name};
     my $available = 0;
     if (ref($access_hash) eq 'HASH') {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.822 loncom/lonnet/perl/lonnet.pm:1.823
--- loncom/lonnet/perl/lonnet.pm:1.822	Thu Jan 11 16:09:10 2007
+++ loncom/lonnet/perl/lonnet.pm	Fri Jan 12 17:14:28 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.822 2007/01/11 21:09:10 albertel Exp $
+# $Id: lonnet.pm,v 1.823 2007/01/12 22:14:28 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1701,15 +1701,10 @@
         if (($fname !~ /\.meta$/) && (&is_portfolio_file($fname))) {
             my $metafile = $fname.'.meta';
             my $metaresult = &removeuserfile($docuname,$docudom,$metafile); 
-            my ($group,$file);
-            if ($fname =~ /^groups\/(\w+)\/portfolio(\/.+)$/) {
-                $group = $1;
-                $file = $2;
-            } elsif ($fname =~ /^portfolio(\/.+)$/) {
-                $file = $1;
-            }
+	    my $url = "/uploaded/$docudom/$docuname/$fname";
+            my ($file,$group) = (&parse_portfolio_url($url))[3,4];
             my $sqlresult = 
-                &update_portfolio_table($docuname,$docudom,$group.$file,
+                &update_portfolio_table($docuname,$docudom,$file,
                                         'portfolio_metadata',$group,
                                         'delete');
         }
@@ -1734,15 +1729,10 @@
             my $newmeta = $new.'.meta';
             my $metaresult = 
                 &renameuserfile($docuname,$docudom,$oldmeta,$newmeta);
-            my ($group,$file);
-            if ($old =~ /^groups\/(\w+)\/portfolio(\/.+)$/) {
-                $group = $1;
-                $file = $2;
-            } elsif ($old =~ /^portfolio(\/.+)$/) {
-                $file = $1;
-            }
+	    my $url = "/uploaded/$docudom/$docuname/$old";
+            my ($file,$group) = (&parse_portfolio_url($url))[3,4];
             my $sqlresult = 
-                &update_portfolio_table($docuname,$docudom,$group.$file,
+                &update_portfolio_table($docuname,$docudom,$file,
                                         'portfolio_metadata',$group,
                                         'delete');
         }
@@ -3559,12 +3549,12 @@
 
     my ($type,$udom,$unum,$group,$file_name);
     
-    if ($url =~  m-^/*uploaded/($match_domain)/($match_username)/portfolio(/.+)$-) {
+    if ($url =~  m-^/*(?:uploaded|editupload)/($match_domain)/($match_username)/portfolio(/.+)$-) {
 	$type = 1;
         $udom = $1;
         $unum = $2;
         $file_name = $3;
-    } elsif ($url =~ m-^/*uploaded/($match_domain)/($match_courseid)/groups/([^/]+)/portfolio/(.+)$-) {
+    } elsif ($url =~ m-^/*(?:uploaded|editupload)/($match_domain)/($match_courseid)/groups/([^/]+)/portfolio/(.+)$-) {
 	$type = 2;
         $udom = $1;
         $unum = $2;