Difference between revisions of "HideTransactions"

From Request Tracker Wiki
Jump to navigation Jump to search
Line 23: Line 23:
== Sane template for your custom code ==
== Sane template for your custom code ==


<nowiki>&lt;%INIT&gt;
<code>
  # do nothing if transaction is already flagged for skipping
    <%INIT>
  # yes, this is possible, you may have many callbacks that
    # do nothing if transaction is already flagged for skipping
  # skip using different conditions
    # yes, this is possible, you may have many callbacks that
  return if $$skip;
    # skip using different conditions
 
    return if $$skip;
  # do nothing if it's not system user
 
  return unless $Transaction-&gt;Creator == $RT::SystemUser-&gt;id;
    # do nothing if it's not system user
 
    return unless $Transaction->Creator == $RT::SystemUser->id;
  # this is not good idea to skip some transaction types
 
  # even if those are created by system user
    # this is not good idea to skip some transaction types
  return if $SHOW{ $Transaction-&gt;Type };
    # even if those are created by system user
 
    return if $SHOW{ $Transaction->Type };
  ...
 
  here add your additional conditions
    ...
  ...
    here add your additional conditions
 
    ...
  &lt;/%INIT&gt;
 
  &lt;%ONCE&gt;
    </%INIT>
  my %SHOW = map { $_ =&gt; 1} qw(
    <%ONCE>
      Create Comment Correspond
    my %SHOW = map { $_ => 1} qw(
      EmailRecord CommentEmailRecord
        Create Comment Correspond
  );
        EmailRecord CommentEmailRecord
  &lt;/%ONCE&gt;
    );
  &lt;%ARGS&gt;
    </%ONCE>
  $Transaction =&gt; undef
    <%ARGS>
  $skip =&gt; undef
    $Transaction => undef
  &lt;/%ARGS&gt;
    $skip => undef
  </nowiki>
    </%ARGS>
</code>


== Additional code snippets ==
== Additional code snippets ==

Revision as of 13:33, 8 January 2017

Hiding transactions in tickets' history

Introdduction

You should be familiar with CustomizingWithCallbacks as all examples here are based on 'SkipTransaction' callback in Ticket/Elements/ShowHistory Mason component. Create a Callback 'SkipTransaction' in local/html/Callbacks/<MyCallbacks>/Ticket/Elements/ShowHistory/SkipTransaction and pick code below.

For RT 4.2.0 and above Ticket/Elements/ShowHistory no longer exists.  You will need to hook Elements/ShowHistory's SkipTransaction instead.  Keep in mind that this means your transactions may apply to users or queues in addition to tickets and you should tread carefully.

SkipTransaction callback allows your code to set $$skip variable if you want to skip the current transaction.

Minimal example

This is minimal example as starting point that hides all transactions created by the system user.

   <%INIT>
   $$skip = 1 if $Transaction->Creator == $RT::SystemUser->id;
   
   <%ARGS>
   $Transaction => undef
   $skip => undef
   

Sane template for your custom code

   <%INIT>
   # do nothing if transaction is already flagged for skipping
   # yes, this is possible, you may have many callbacks that
   # skip using different conditions
   return if $$skip;
   # do nothing if it's not system user
   return unless $Transaction->Creator == $RT::SystemUser->id;
   # this is not good idea to skip some transaction types
   # even if those are created by system user
   return if $SHOW{ $Transaction->Type };
   ...
   here add your additional conditions
   ...
   
   <%ONCE>
   my %SHOW = map { $_ => 1} qw(
       Create Comment Correspond
       EmailRecord CommentEmailRecord
   );
   
   <%ARGS>
   $Transaction => undef
   $skip => undef
   

Additional code snippets

Do not hide on History.html page

If you'd like to have an abbreviated history on the main ticket display, but would like the full history in the History tab display, then add the following:

...
  # do nothing if we're on history page
  return if $r->uri =~ /History\.html/;
  ...
  

RT::Extension::HistoryFilter

I created an extension where you can define which transaction types are shown on the ticket display page. The ticket history page shows always the full history. You can find it at github: http://github.com/cloos/rt-extension-historyfilter

See also

CustomizingWithCallbacks