1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 # <jesse@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
51 RT::Action::NotifyGroup - RT Action that sends notifications to groups and/or users
55 RT action module that allow you to notify particular groups and/or users.
56 Distribution is shipped with C<rt-email-group-admin> script that
57 is command line tool for managing NotifyGroup scrip actions. For more
58 more info see its documentation.
62 package RT::Action::NotifyGroup;
66 use base qw(RT::Action::Notify);
75 Sets the recipients of this message to Groups and/or Users.
82 my $arg = $self->Argument;
83 foreach( $self->__SplitArg( $arg ) ) {
84 $self->_HandleArgument( $_ );
87 my $creator = $self->TransactionObj->CreatorObj->EmailAddress();
88 unless( $RT::NotifyActor ) {
89 @{ $self->{'To'} } = grep ( !/^\Q$creator\E$/, @{ $self->{'To'} } );
92 $self->{'seen_ueas'} = {};
101 if ( $instance !~ /\D/ ) {
102 my $obj = RT::Principal->new( $self->CurrentUser );
103 $obj->Load( $instance );
104 return $self->_HandlePrincipal( $obj );
107 my $group = RT::Group->new( $self->CurrentUser );
108 $group->LoadUserDefinedGroup( $instance );
109 # to check disabled and so on
110 return $self->_HandlePrincipal( $group->PrincipalObj )
113 require Email::Address;
115 my $user = RT::User->new( $self->CurrentUser );
116 if ( $instance =~ /^$Email::Address::addr_spec$/ ) {
117 $user->LoadByEmail( $instance );
118 return $self->__PushUserAddress( $instance )
121 $user->Load( $instance );
123 return $self->_HandlePrincipal( $user->PrincipalObj )
127 "'$instance' is not principal id, group name, user name,"
128 ." user email address or any email address"
134 sub _HandlePrincipal {
138 $RT::Logger->error( "Couldn't load principal #$obj" );
141 if( $obj->Disabled ) {
142 $RT::Logger->info( "Principal #$obj is disabled => skip" );
145 if( !$obj->PrincipalType ) {
146 $RT::Logger->crit( "Principal #$obj has empty type" );
147 } elsif( lc $obj->PrincipalType eq 'user' ) {
148 $self->__HandleUserArgument( $obj->Object );
149 } elsif( lc $obj->PrincipalType eq 'group' ) {
150 $self->__HandleGroupArgument( $obj->Object );
152 $RT::Logger->info( "Principal #$obj has unsupported type" );
157 sub __HandleUserArgument {
161 my $uea = $obj->EmailAddress;
163 $RT::Logger->warning( "User #". $obj->id ." has no email address" );
166 $self->__PushUserAddress( $uea );
169 sub __HandleGroupArgument {
173 my $members = $obj->UserMembersObj;
174 while( my $m = $members->Next ) {
175 $self->__HandleUserArgument( $m );
180 return grep length, map {s/^\s+//; s/\s+$//; $_} split /,/, $_[1];
183 sub __PushUserAddress {
186 push @{ $self->{'To'} }, $uea unless $self->{'seen_ueas'}{ $uea }++;
193 Ruslan U. Zakirov E<lt>ruz@bestpractical.comE<gt>
195 L<RT::Action::NotifyGroupAsComment>, F<rt-email-group-admin>
199 eval "require RT::Action::NotifyGroup_Vendor";
200 if ($@ && $@ !~ qr{^Can't locate RT/Action/NotifyGroup_Vendor.pm}) {
204 eval "require RT::Action::NotifyGroup_Local";
205 if ($@ && $@ !~ qr{^Can't locate RT/Action/NotifyGroup_Local.pm}) {