AddSquelchedCc

From Request Tracker Wiki
Revision as of 03:41, 27 May 2010 by JesperCheetah (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

This script adds team members as watchers on a ticket, but squelch them (they'll not receive updates unless they are explicetely defined as requestors or cc or owners). When one of them creates a ticket, all the other will have access (you need to set at least ShowTicket right to "Cc". I'd recommend setting ShowTicket and ReplyToTicket to Cc and Requestors.

There are a script and a scrip. The script is to apply this behavior on all the tickets already created, the scrip is for the new tickets.

Script for tickets already created

Usage: - Create a group starting with "TEAM_", add people to the group (if you need unprivileged member, select the user and click "memberships") - Run the following script

#!/usr/bin/perl # Name: AddSquelchedCc.pl # # Description: # This script adds team members as watchers on a ticket, but squelch them # (they'll not receive updates unless they are explicetely defined as # requestors or cc or owners). # When one of them creates a ticket, all the other will have access (you # need to set at least ShowTicket right to "Cc". # I'd recommend setting ShowTicket and ReplyToTicket to Cc and Requestors. # # Usage: # - Create a group starting with "TEAM_", add people to the group # (if you need unprivileged member, select the user and click "memberships") # - Run the script # Author: <Christophe.Sahut {at} sgs {dot} com> # License: This module is free software; you can redistribute it # and/or modify it under the GPLv2 licence. use warnings; use strict; use lib qw(/opt/rt/lib); use RT; use RT::Users; use RT::User; use RT::Tickets; use RT::Ticket; use RT::Groups; RT::LoadConfig(); RT::Init(); my $return; my $message = ""; my $ticket = RT::Ticket->new($RT::SystemUser); my $tickets = RT::Tickets->new($RT::SystemUser); $tickets->UnLimit(); #$tickets->LimitId(OPERATOR=>'>',VALUE=>'15000'); ##$tickets->LimitStatus(VALUE=>'open'); while (my $ticket = $tickets->Next()) { <code><pre> print "== Working on ticket ".$ticket-&gt;Id." ==\n"; my $groups = RT::Groups-&gt;new($RT::SystemUser); $groups-&gt;LimitToUserDefinedGroups(); while (my $group = $groups-&gt;Next()) { next unless $group-&gt;Name =~ /^TEAM_/; if($group-&gt;HasMemberRecursively($ticket-&gt;Creator)){ print "Creator found in ".$group-&gt;Name."\n"; ($return,$message)=$ticket-&gt;AddWatcher(Type=&gt;"Cc",PrincipalId=&gt;$group-&gt;Id); print "Adding ".$group-&gt;Name." as a Cc Watcher (".$message.")\n"; foreach my $email($group-&gt;MemberEmailAddresses){ if($email) { my $user = RT::User-&gt;new(RT-&gt;SystemUser); $user-&gt;LoadByEmail($email); # Don't squelch these users next if $ticket-&gt;IsRequestor($user-&gt;Id) or $ticket-&gt;IsCc($user-&gt;Id) or $ticket-&gt;IsOwner($user); $ticket-&gt;SquelchMailTo($email); print "Squelching ".$email."\n"; } } } } </pre></code> }

Scrip for new tickets

  • Create a new scrip, on your incoming queue for example :

Description: AddSquelchedCc

Condition: OnCreate

Action: User Defined

Template: Global Template: blank

Stage: TransactionCreate

Custom condition:

return 1;

Custom action preparation code:

my $ticket = $self->TicketObj;

my $groups = RT::Groups->new($RT::SystemUser);

$groups->LimitToUserDefinedGroups();

while (my $group = $groups->Next()) {

      next unless $group->Name =~ /^TEAM_/;
      if($group->HasMemberRecursively($ticket->Creator)){
              $ticket->AddWatcher(Type=>"Cc",PrincipalId=>$group->Id);
              foreach my $email($group->MemberEmailAddresses){
                      if($email) {
                              my $user = RT::User->new(RT->SystemUser);
                              $user->LoadByEmail($email);
                              # Don't squelch these users
                              next if $ticket->IsRequestor($user->Id) or
                                      $ticket->IsCc($user->Id) or
                                      $ticket->IsOwner($user);
                              $ticket->SquelchMailTo($email);
                      }
              }
      }
}
return 1;

Custom action cleanup code:

return 1;