1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
6 # <sales@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.
76 Respects RT's NotifyActor configuration.
78 To send email to the selected receipients regardless of RT's NotifyActor
79 configuration, include AlwaysNotifyActor in the list of arguments.
86 my $arg = $self->Argument;
87 foreach( $self->__SplitArg( $arg ) ) {
88 $self->_HandleArgument( $_ );
91 $self->{'seen_ueas'} = {};
100 return if ( $instance eq 'AlwaysNotifyActor' );
102 if ( $instance !~ /\D/ ) {
103 my $obj = RT::Principal->new( $self->CurrentUser );
104 $obj->Load( $instance );
105 return $self->_HandlePrincipal( $obj );
108 my $group = RT::Group->new( $self->CurrentUser );
109 $group->LoadUserDefinedGroup( $instance );
110 # to check disabled and so on
111 return $self->_HandlePrincipal( $group->PrincipalObj )
114 require Email::Address;
116 my $user = RT::User->new( $self->CurrentUser );
117 if ( $instance =~ /^$Email::Address::addr_spec$/ ) {
118 $user->LoadByEmail( $instance );
119 return $self->__PushUserAddress( $instance )
122 $user->Load( $instance );
124 return $self->_HandlePrincipal( $user->PrincipalObj )
128 "'$instance' is not principal id, group name, user name,"
129 ." user email address or any email address"
135 sub _HandlePrincipal {
139 $RT::Logger->error( "Couldn't load principal #$obj" );
142 if( $obj->Disabled ) {
143 $RT::Logger->info( "Principal #$obj is disabled => skip" );
146 if( !$obj->PrincipalType ) {
147 $RT::Logger->crit( "Principal #$obj has empty type" );
148 } elsif( lc $obj->PrincipalType eq 'user' ) {
149 $self->__HandleUserArgument( $obj->Object );
150 } elsif( lc $obj->PrincipalType eq 'group' ) {
151 $self->__HandleGroupArgument( $obj->Object );
153 $RT::Logger->info( "Principal #$obj has unsupported type" );
158 sub __HandleUserArgument {
162 my $uea = $obj->EmailAddress;
164 $RT::Logger->warning( "User #". $obj->id ." has no email address" );
167 $self->__PushUserAddress( $uea );
170 sub __HandleGroupArgument {
174 my $members = $obj->UserMembersObj;
175 while( my $m = $members->Next ) {
176 $self->__HandleUserArgument( $m );
181 return grep length, map {s/^\s+//; s/\s+$//; $_} split /,/, $_[1];
184 sub __PushUserAddress {
187 push @{ $self->{'To'} }, $uea unless $self->{'seen_ueas'}{ $uea }++;
194 Ruslan U. Zakirov E<lt>ruz@bestpractical.comE<gt>
196 L<RT::Action::NotifyGroupAsComment>, F<rt-email-group-admin>
200 RT::Base->_ImportOverlays();