[LON-CAPA-cvs] cvs: loncom /publisher loncfile.pm

www lon-capa-cvs@mail.lon-capa.org
Mon, 05 Jan 2004 16:48:50 -0000


www		Mon Jan  5 11:48:50 2004 EDT

  Modified files:              
    /loncom/publisher	loncfile.pm 
  Log:
  Bug #2361: find out if file is unpublished or obsolete before deleting,
  renaming or moving.
  
  
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.49 loncom/publisher/loncfile.pm:1.50
--- loncom/publisher/loncfile.pm:1.49	Mon Dec 29 14:01:27 2003
+++ loncom/publisher/loncfile.pm	Mon Jan  5 11:48:50 2004
@@ -9,7 +9,7 @@
 #  and displays a page showing the results of the action.
 #
 #
-# $Id: loncfile.pm,v 1.49 2003/12/29 19:01:27 www Exp $
+# $Id: loncfile.pm,v 1.50 2004/01/05 16:48:50 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -173,6 +173,28 @@
     return '<tt>'.$fn.'</tt>';
 }
 
+
+# see if the file is
+# a) published (return 0 if not)
+# b) if, so obsolete (return 0 if not)
+
+sub obsolete_unpub {
+    my ($user,$domain,$construct)=@_;
+    my $published=$construct;
+    $published=~
+	s/^\/home\/$user\/public\_html\//\/home\/httpd\/html\/res\/$domain\/$user\//;
+    if (-e $published) {
+	if (&Apache::lonnet::metadata($published,'obsolete')) {
+	    return 1;
+	}
+	return 0;
+    } else {
+	return 1;
+    }
+}
+
+
+
 =pod
 
 =item exists($user, $domain, $file)
@@ -414,6 +436,11 @@
 		$request->print('<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
 		return;
 	    }
+	    unless (&obsolete_unpub($user,$domain,$fn)) {
+		$request->print('<h3>'.&mt('Cannot rename or move non-obsolete published file').'</h3>'.
+				'<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
+		return;
+	    }
 	    $request->print('<input type="hidden" name="newfilename" value="'.
 			    $newfilename.
 			    '" /><p>'.&mt('Rename').' '.&display($fn).
@@ -459,6 +486,11 @@
   if( -e $fn) {
     $request->print('<input type="hidden" name="newfilename" value="'.
 		    $fn.'"/>');
+    unless (&obsolete_unpub($user,$domain,$fn)) {
+	$request->print('<h3>'.&mt('Cannot delete non-obsolete published file').'</h3>'.
+			'<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
+	return;
+    }
     $request->print('<p>'.&mt('Delete').' '.&display($fn).'?</p>');
     &CloseForm1($request, $fn);
   } else {