AddAdminCc

From Request Tracker Wiki
Jump to navigation Jump to search

Contributed by JohannesVerelst Overview

This scrip will add the emailaddress 'somebody@somewhere.com' as an AdminCc (it needs to be available as a user already). You can use this if you reroute tickets between queues, and do not want to set AdminCc on all those queues. Scrip

Description: AddAdminCC
Condition: On Create
Action: User defined
Template: Global template: blank
Stage: TransactionCreate
Custom Condition:
Custom action preparation code: return 1;
Custom action cleanup code:
 my $admincclist = $self->TicketObj->AdminCc;

 my $user = RT::User->new($RT::SystemUser);
 $user->LoadByEmail('somebody@somewhere.com');

 $admincclist->AddMember($user->Id);

Modification

Modification: Adding someone as an AdminCc for a ticket if it moves from a specific queue to another specific queue. - By Mike Patterson. Help From Stephen Turner on mailing list.

If a ticket moves from our "web" queue (#5) to our "systems" queue (#10) I want "myuser@myuniversity.edu" to become an AdminCc for that ticket. I create this scrip on the queue I'm moving the ticket into. Scrip

Description: AddAdminCCIfFromWeb
Condition: On Queue Change
Action: User defined
Template: Global template: blank
Stage: TransactionCreate
Custom Condition:
Custom action preparation code: return 1;
Custom action cleanup code:
 my $admincclist = $self->TicketObj->AdminCc;
 my $user = RT::User->new($RT::SystemUser);
 if ($self->TransactionObj->Type eq "Set"
     && $self->TransactionObj->Field eq "Queue"
     && $self->TransactionObj->OldValue eq "5"
   ) {
   $user->LoadByEmail('!myuser@myuniversity.edu');
   $admincclist->AddMember($user->Id);
 } else {
   return 0;
 }
 

A More Refined Version of That Idea

You can also use the verbosely-named RT::Extension::AddAdminCcsOnQueueChange (from CPAN) to do exactly what its name implies – add all the AdminCcs on the current queue to the ticket when it moves to a new queue. Another Modification

Modification: If you have many, weird aliases for a single Queue, RT sometimes adds those aliases to the CC of the ticket. Then when you correspond, it "bounces" because it trys to send to itself (the requester never sees this though). This scrip will remove these known aliases from the CC of a ticket Scrip

Description: DeleteCC
Condition: On Create
Action: User defined
Template: Global template: blank
Stage: TransactionCreate
Custom Condition:
Custom action preparation code: return 1;
Custom action cleanup code:
 $self->TicketObj->DeleteWatcher(Type=>"Cc",Email=>"somethingreallyweird\@domain.com");

Another Modification

by JFenal.

If you have a workflow between queues (Unix->Storage and back for instance), and having differents groups having rights on their only queues, you may allow ticket owners to still see the ticket they transfered by automatically adding them as AdminCc to the ticket on queue change.

You will need then to set global rights for AdminCc role such as ShowTicket, and maybe more, depending of your own setup : Scrip

Description: AddAsAdminCcOnQueueChange
Condition: On Queue Change
Action: User defined
Template: Global template: blank
Stage: TransactionCreate
Custom Condition:
Custom action preparation code: return 1;
Custom action cleanup code:
 
  my $owner = $self->TicketObj->Owner;
  return 1 if $owner == $RT::Nobody->id;
  my $admincclist = $self->TicketObj->AdminCc;
 
  if ($self->TransactionObj->Type eq "Set"
     && $self->TransactionObj->Field eq "Queue"
     && $self->TransactionObj->OldValue eq "8"    # 8: Storage queue -> any queue
     ) {
    my ($status, $msg) = $admincclist->AddMember($owner);
    unless( $status ) {
      $RT::Logger->warning( "can't add ticket owner as AdminCc : $msg" );
      return undef;
    }
  }
  else {
    return 0;
  }
 

You need to set this scrip as a global scrip, as OnQueueChange scrips on a queue B are executed when entering B from A, not leaving queue B. Thus, if you need to add AdminCc when going to more than one queue, you would need to set this scrip on many queue. A mess to administer... Here, you could manage that only by testing $self->TransactionObj->OldValue and $self->TransactionObj->Value and take appropriate action. Another Modification

by Riccardo Capecchi

Small change from the idea of the former, on queue change we needed to set all old watchers of the old queue as new AdminCc for the ticket, so they can follow the ticket also in different queue where they have no rights.

You will need then to set global rights for AdminCc role such as ShowTicket, and maybe more, depending of your own setup : Scrip

Description: AddAsAdminCcOnQueueChange
Condition: On Queue Change
Action: User defined
Template: Global template: blank
Stage: TransactionCreate
Custom Condition:
Custom action preparation code: return 1;
Custom action cleanup code:
 my $OldQueueID = $self->TransactionObj->OldValue;
 my $OldQueue = new RT::Queue($RT::SystemUser);
 $OldQueue->Load($OldQueueID);
 my @oldadmincclist = $OldQueue->AdminCc->MemberEmailAddresses;
 foreach my $addr (@oldadmincclist) {
   my ($success, $msg)= $self->TicketObj->AddWatcher(
                              Type => "AdminCc",
                              Email => $addr);
   if (! $success) {
     $RT::Logger->info($msg);
     return undef;
   }
 }
 return 1;

You can set this as global, then will work for any change of queue or set as scrip for only some queue, it depend on your workflow..