<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://rt-wiki.bestpractical.com/index.php?action=history&amp;feed=atom&amp;title=EditAttachment</id>
	<title>EditAttachment - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://rt-wiki.bestpractical.com/index.php?action=history&amp;feed=atom&amp;title=EditAttachment"/>
	<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/index.php?title=EditAttachment&amp;action=history"/>
	<updated>2026-08-23T01:54:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://rt-wiki.bestpractical.com/index.php?title=EditAttachment&amp;diff=1037&amp;oldid=prev</id>
		<title>Admin: 3 revisions imported</title>
		<link rel="alternate" type="text/html" href="https://rt-wiki.bestpractical.com/index.php?title=EditAttachment&amp;diff=1037&amp;oldid=prev"/>
		<updated>2016-04-06T20:08:52Z</updated>

		<summary type="html">&lt;p&gt;3 revisions imported&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Edit Attachment==&lt;br /&gt;
Sometimes, it becomes difficult to follow a ticket because your users do top-posting or they have a disclamer of 2 pages. It&amp;#039;s not in RT philosophy to change an Object after his creation, even if adding this modification as a transaction and a new version can be very useful. The hack presented here won&amp;#039;t work if you are using GPG to sign messages.&lt;br /&gt;
&lt;br /&gt;
First, add this CallBack&lt;br /&gt;
&lt;br /&gt;
local/html/Callbacks/AName/Ticket/Elements/ShowTransactionAttachments/AfterDownloadLinks&lt;br /&gt;
  / &amp;lt;a href=&amp;quot;&amp;lt;% $AttachPath %&amp;gt;/Edit/&amp;lt;% $ticket-&amp;gt;Id %&amp;gt;/&amp;lt;% $trans-&amp;gt;Id %&amp;gt;/&amp;lt;% $message-&amp;gt;Id %&amp;gt;&amp;quot;&amp;gt;&amp;lt;% loc(&amp;#039;Edit&amp;#039;) %&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
 &amp;lt;%ARGS&amp;gt;&lt;br /&gt;
 $AttachPath =&amp;gt; RT-&amp;gt;Config-&amp;gt;Get(&amp;#039;WebPath&amp;#039;).&amp;quot;/Ticket/Attachment&amp;quot;&lt;br /&gt;
 $message =&amp;gt; $ARGS{Attachment}&lt;br /&gt;
 $ticket =&amp;gt; $ARGS{Ticket}&lt;br /&gt;
 $trans =&amp;gt; $ARGS{Transaction}&lt;br /&gt;
 &amp;lt;/%ARGS&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then, add this module (You can limit this function to a special group, here &amp;quot;Support Group&amp;quot;&lt;br /&gt;
&lt;br /&gt;
local/html/Ticket/Attachment/Edit/dhandler&lt;br /&gt;
 &amp;lt;%perl&amp;gt;&lt;br /&gt;
     my ($ticket, $trans, $attach, $filename);&lt;br /&gt;
     my $arg = $m-&amp;gt;dhandler_arg;                # get rest of path&lt;br /&gt;
     if ($arg =~ &amp;#039;^(\d+)/(\d+)/(\d+)&amp;#039;) {&lt;br /&gt;
         $ticket = $1;&lt;br /&gt;
         $trans = $2;&lt;br /&gt;
         $attach = $3;&lt;br /&gt;
     }&lt;br /&gt;
     else {&lt;br /&gt;
         Abort(&amp;quot;Corrupted attachment URL.&amp;quot;);&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     my $ok=0;&lt;br /&gt;
     my $BSGroup = RT::Group-&amp;gt;new($RT::SystemUser);&lt;br /&gt;
     $BSGroup-&amp;gt;LoadUserDefinedGroup(&amp;#039;Support Group&amp;#039;);&lt;br /&gt;
     my $principal = $session{&amp;#039;CurrentUser&amp;#039;}-&amp;gt;PrincipalObj;&lt;br /&gt;
     &lt;br /&gt;
     # by default, users goes to SelfService&lt;br /&gt;
     if ($BSGroup-&amp;gt;HasMemberRecursively($principal)) {&lt;br /&gt;
         $ok = 1;&lt;br /&gt;
     } elsif ($principal-&amp;gt;HasRight(Right =&amp;gt; &amp;#039;SuperUser&amp;#039;, Object=&amp;gt;$RT::System)) {&lt;br /&gt;
         $ok = 1;&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     if (!$ok) {&lt;br /&gt;
        Abort(&amp;quot;You can&amp;#039;t edit a message&amp;quot;);&lt;br /&gt;
     }&lt;br /&gt;
      my $AttachmentObj = new RT::Attachment($session{&amp;#039;CurrentUser&amp;#039;});&lt;br /&gt;
      $AttachmentObj-&amp;gt;Load($attach) || Abort(&amp;quot;Attachment &amp;#039;$attach&amp;#039; could not be loaded&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
      unless ($AttachmentObj-&amp;gt;id) {&lt;br /&gt;
         Abort(&amp;quot;Bad attachment id. Couldn&amp;#039;t find attachment &amp;#039;$attach&amp;#039;\n&amp;quot;);&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
      if ($ARGS{&amp;#039;content&amp;#039;}) {&lt;br /&gt;
         my $dbh = DBI-&amp;gt;connect(RT::Handle-&amp;gt;DSN, RT-&amp;gt;Config-&amp;gt;Get(&amp;#039;DatabaseUser&amp;#039;), RT-&amp;gt;Config-&amp;gt;Get(&amp;#039;DatabasePassword&amp;#039;));&lt;br /&gt;
         unless ( $dbh ) {&lt;br /&gt;
            Abort(&amp;quot;Can&amp;#039;t connect to database\n&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
         my $text = $dbh-&amp;gt;quote($ARGS{&amp;#039;content&amp;#039;});&lt;br /&gt;
         my $old = $dbh-&amp;gt;quote($AttachmentObj-&amp;gt;OriginalContent);&lt;br /&gt;
 &lt;br /&gt;
         # CREATE TABLE AttachmentsHistory (Id int, Content text, Updated TimeStamp)&lt;br /&gt;
         $dbh-&amp;gt;do(&amp;quot;INSERT INTO AttachmentsHistory (Id, Content, Updated) VALUES ($attach, $old, NOW())&amp;quot;);&lt;br /&gt;
         $dbh-&amp;gt;do(&amp;quot;UPDATE Attachments SET Content=$text WHERE Id=$attach&amp;quot;);&lt;br /&gt;
         $dbh-&amp;gt;disconnect();&lt;br /&gt;
         return RT::Interface::Web::Redirect( RT-&amp;gt;Config-&amp;gt;Get(&amp;#039;WebURL&amp;#039;) . &amp;quot;Ticket/Display.html?id=&amp;quot; . $ticket . &amp;quot;#txn-&amp;quot; . $trans);&lt;br /&gt;
      }&lt;br /&gt;
      $r-&amp;gt;content_type(&amp;quot;text/html&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
      my $content_type = $AttachmentObj-&amp;gt;ContentType || &amp;#039;text/plain&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
      if ($content_type !~ /^text\/plain/i) {&lt;br /&gt;
         Abort(&amp;quot;Can&amp;#039;t edit non text attachment\n&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
 &lt;br /&gt;
      if (my $enc = $AttachmentObj-&amp;gt;OriginalEncoding) {&lt;br /&gt;
         my $iana = Encode::find_encoding( $enc );&lt;br /&gt;
         $iana = $iana? $iana-&amp;gt;mime_name : $enc;&lt;br /&gt;
         $content_type .= &amp;quot;;charset=$iana&amp;quot;;&lt;br /&gt;
      }&lt;br /&gt;
 &lt;br /&gt;
      # unless (RT-&amp;gt;Config-&amp;gt;Get(&amp;#039;TrustMIMEAttachments&amp;#039;)) {&lt;br /&gt;
      #     $content_type = &amp;#039;application/octet-stream&amp;#039;;&lt;br /&gt;
      # }&lt;br /&gt;
 &lt;br /&gt;
      $m-&amp;gt;clear_buffer();&lt;br /&gt;
      $m-&amp;gt;out(&amp;quot;&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;Edit Attachment Id $attach&amp;lt;form action=&amp;#039;?&amp;#039; enctype=&amp;#039;multipart/form-data&amp;#039; method=&amp;#039;post&amp;#039;&amp;gt;&amp;lt;textarea name=&amp;#039;content&amp;#039; cols=&amp;#039;120&amp;#039; rows=&amp;#039;40&amp;#039;&amp;gt;&amp;quot;);&lt;br /&gt;
      $m-&amp;gt;out($AttachmentObj-&amp;gt;OriginalContent);&lt;br /&gt;
      $m-&amp;gt;out(&amp;quot;&amp;lt;/textarea&amp;gt;&amp;quot;); &lt;br /&gt;
      if ($ARGS{&amp;#039;content&amp;#039;}) {&lt;br /&gt;
         $m-&amp;gt;out(&amp;quot;&amp;amp;lt;pre&amp;amp;gt;&amp;quot;);&lt;br /&gt;
         $m-&amp;gt;out($ARGS{&amp;#039;content&amp;#039;});&lt;br /&gt;
         $m-&amp;gt;out(&amp;quot;&amp;amp;lt;/pre&amp;amp;gt;&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
      $m-&amp;gt;out(&amp;quot;&lt;br /&gt;
 &amp;lt;input type=&amp;#039;submit&amp;#039; name=&amp;#039;action&amp;#039; value=&amp;#039;Save&amp;#039;&amp;gt;&amp;lt;/form&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&amp;quot;);&lt;br /&gt;
      $m-&amp;gt;abort; &lt;br /&gt;
 &amp;lt;/%perl&amp;gt;&lt;br /&gt;
 &amp;lt;%attr&amp;gt;&lt;br /&gt;
 AutoFlush =&amp;gt; 0&lt;br /&gt;
 &amp;lt;/%attr&amp;gt;&lt;br /&gt;
 &amp;lt;%ARGS&amp;gt;&lt;br /&gt;
 $id =&amp;gt; undef&lt;br /&gt;
 &amp;lt;/%ARGS&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To keep version history, you can create this table to your RT instance&lt;br /&gt;
 CREATE TABLE AttachmentsHistory (Id int, Content text, Updated TimeStamp);&lt;br /&gt;
&lt;br /&gt;
A future version can also log the current user name, and display versions in a tab.&lt;br /&gt;
&lt;br /&gt;
Enjoy.&lt;br /&gt;
[[Category:Hack Attachment]]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>