AddSquelchedCc

From Request Tracker Wiki
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()) {
 
       print "== Working on ticket ".$ticket->Id." ==\n";
 
       my $groups = RT::Groups->new($RT::SystemUser);
       $groups->LimitToUserDefinedGroups();
 
       while (my $group = $groups->Next()) {
               next unless $group->Name =~ /^TEAM_/;
               if($group->HasMemberRecursively($ticket->Creator)){
                       print "Creator found in ".$group->Name."\n";
                       ($return,$message)=$ticket->AddWatcher(Type=>"Cc",PrincipalId=>$group->Id);
                       print "Adding ".$group->Name." as a Cc Watcher (".$message.")\n";
 
                       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);
                                       print "Squelching ".$email."\n";
                               }
                       }
               }
       }
 }
 

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;