HideTransactions: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
m (4 revisions imported)
(No difference)

Revision as of 15:11, 6 April 2016

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;
</%INIT>
<%ARGS>
$Transaction => undef
$skip => undef
</%ARGS>

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
  ...
  
  </%INIT>
  <%ONCE>
  my %SHOW = map { $_ => 1} qw(
      Create Comment Correspond
      EmailRecord CommentEmailRecord
  );
  </%ONCE>
  <%ARGS>
  $Transaction => undef
  $skip => undef
  </%ARGS>
  

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