[freeside-commits] freeside/httemplate/edit/process cust_main_attach.cgi, 1.1, 1.2

Mark Wells mark at wavetail.420.am
Mon Aug 10 16:04:59 PDT 2009


Update of /home/cvs/cvsroot/freeside/httemplate/edit/process
In directory wavetail.420.am:/tmp/cvs-serv15451/httemplate/edit/process

Modified Files:
	cust_main_attach.cgi 
Log Message:
Improve handling of deleted attachments

Index: cust_main_attach.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/edit/process/cust_main_attach.cgi,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cust_main_attach.cgi	9 Aug 2009 09:05:37 -0000	1.1
+++ cust_main_attach.cgi	10 Aug 2009 23:04:57 -0000	1.2
@@ -4,6 +4,7 @@
 %} else {
 % my $act = 'added';
 % $act = 'updated' if ($attachnum);
+% $act = 'purged' if($attachnum and $purge);
 % $act = 'undeleted' if($attachnum and $undelete);
 % $act = 'deleted' if($attachnum and $delete);
 <% header('Attachment ' . $act ) %>
@@ -23,12 +24,13 @@
   or die "Illegal attachnum: ". $cgi->param('attachnum');
 my $attachnum = $1;
 
-my $otaker = $FS::CurrentUser::CurrentUser->name;
-$otaker = $FS::CurrentUser::CurrentUser->username
-  if ($otaker eq "User, Legacy");
+my $curuser = $FS::CurrentUser::CurrentUser;
+my $otaker = $curuser->name;
+$otaker = $curuser->username if ($otaker eq "User, Legacy");
 
 my $delete = $cgi->param('delete');
 my $undelete = $cgi->param('undelete');
+my $purge = $cgi->param('purge');
 
 my $new = new FS::cust_attachment ( {
   attachnum => $attachnum,
@@ -44,6 +46,8 @@
   if(!$old) {
     $error = "Attachnum '$attachnum' not found";
   }
+  elsif($purge) { # do nothing
+  }
   else {
     map { $new->$_($old->$_) } 
       ('_date', 'otaker', 'body', 'disabled');
@@ -72,12 +76,19 @@
     $error = 'No file uploaded';
   }
 }
-my $user = $FS::CurrentUser::CurrentUser;
+my $action = 'Add';
+$action = 'Edit' if $attachnum;
+$action = 'Delete' if $attachnum and $delete;
+$action = 'Undelete' if $attachnum and $undelete;
+$action = 'Purge' if $attachnum and $purge;
 
-$error = 'access denied' unless $user->access_right(($old ? 'Edit' : 'Add') . ' attachment');
+$error = 'access denied' unless $curuser->access_right($action . ' attachment');
 
 if(!$error) {
-  if($old) {
+  if($old and $old->disabled and $purge) {
+    $error = $old->delete;
+  }
+  elsif($old) {
     $error = $new->replace($old);
   }
   else {



More information about the freeside-commits mailing list