[Rt-commit] [svn] r1266 - in rt/branches/3.2-RELEASE: . bin
lib/RT/Action lib/RT/Search lib/t
jesse at pallas.eruditorum.org
jesse at pallas.eruditorum.org
Tue Jul 20 17:30:06 EDT 2004
Author: jesse
Date: Tue Jul 20 17:30:05 2004
New Revision: 1266
Added:
rt/branches/3.2-RELEASE/lib/RT/Action/RecordComment.pm
rt/branches/3.2-RELEASE/lib/RT/Action/RecordCorrespondence.pm
rt/branches/3.2-RELEASE/lib/RT/Search/FromSQL.pm
rt/branches/3.2-RELEASE/lib/t/05cronsupport.pl.in
Modified:
rt/branches/3.2-RELEASE/ (props changed)
rt/branches/3.2-RELEASE/bin/rt-crontool.in
rt/branches/3.2-RELEASE/configure.ac
rt/branches/3.2-RELEASE/lib/t/02regression.t.in
Log:
----------------------------------------------------------------------
r8258 at tinbook: jesse | 2004-07-20T21:24:03.019565Z
Crontool additions to support scripted notifications [Tara Andrews, for BPS]
----------------------------------------------------------------------
Modified: rt/branches/3.2-RELEASE/bin/rt-crontool.in
==============================================================================
--- rt/branches/3.2-RELEASE/bin/rt-crontool.in (original)
+++ rt/branches/3.2-RELEASE/bin/rt-crontool.in Tue Jul 20 17:30:05 2004
@@ -97,8 +97,8 @@
# load template if specified
my $template_obj;
if ($template_id) {
- $template_obj = RT::Template->new($RT::Nobody);
- $template_obj->LoadById($template_id);
+ $template_obj = RT::Template->new($CurrentUser);
+ $template_obj->Load($template_id);
}
#At the appointed time:
@@ -118,7 +118,7 @@
#for each ticket we've found
while ( my $ticket = $tickets->Next() ) {
- print "\n" . $ticket->Id() . ": " if ($verbose);
+ print $ticket->Id() . ": " if ($verbose);
# perform some more advanced check
if ($condition) {
@@ -146,7 +146,7 @@
#commit our action.
next unless ( $action_obj->Commit );
- print loc("Action committed.") if ($verbose);
+ print loc("Action committed.\n") if ($verbose);
}
# {{{ load_module
Modified: rt/branches/3.2-RELEASE/configure.ac
==============================================================================
--- rt/branches/3.2-RELEASE/configure.ac (original)
+++ rt/branches/3.2-RELEASE/configure.ac Tue Jul 20 17:30:05 2004
@@ -237,6 +237,7 @@
lib/t/02regression.t
lib/t/03web.pl
lib/t/04_send_email.pl
+ lib/t/05cronsupport.pl
bin/mason_handler.fcgi
bin/mason_handler.scgi
bin/standalone_httpd
Added: rt/branches/3.2-RELEASE/lib/RT/Action/RecordComment.pm
==============================================================================
--- (empty file)
+++ rt/branches/3.2-RELEASE/lib/RT/Action/RecordComment.pm Tue Jul 20 17:30:05 2004
@@ -0,0 +1,97 @@
+# BEGIN LICENSE BLOCK
+#
+# Copyright (c) 1996-2003 Jesse Vincent <jesse at bestpractical.com>
+#
+# (Except where explictly superceded by other copyright notices)
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# Unless otherwise specified, all modifications, corrections or
+# extensions to this work which alter its source code become the
+# property of Best Practical Solutions, LLC when submitted for
+# inclusion in the work.
+#
+#
+# END LICENSE BLOCK
+#
+package RT::Action::RecordComment;
+require RT::Action::Generic;
+use strict;
+use vars qw/@ISA/;
+ at ISA = qw(RT::Action::Generic);
+
+=head1 NAME
+
+RT::Action::RecordComment - An Action which can be used from an
+external tool, or in any situation where a ticket transaction has not
+been started, to make a comment on the ticket.
+
+=head1 SYNOPSIS
+
+my $action_obj = RT::Action::RecordComment->new('TicketObj' => $ticket_obj,
+ 'TemplateObj' => $template_obj,
+ );
+my $result = $action_obj->Prepare();
+$action_obj->Commit() if $result;
+
+=head1 METHODS
+
+=head2 Prepare
+
+Check for the existence of a Transaction. If a Transaction already
+exists, and is of type "Comment" or "Correspond", abort because that
+will give us a loop.
+
+=cut
+
+
+sub Prepare {
+ my $self = shift;
+ if (defined $self->{'TransactionObj'} &&
+ $self->{'TransactionObj'}->Type =~ /^(Comment|Correspond)$/) {
+ return undef;
+ }
+ return 1;
+}
+
+=head2 Commit
+
+Create a Transaction by calling the ticket's Comment method on our
+parsed Template, which may have an RT-Send-Cc or RT-Send-Bcc header.
+The Transaction will be of type Comment. This Transaction can then be
+used by the scrips that actually send the email.
+
+=cut
+
+sub Commit {
+ my $self = shift;
+ $self->CreateTransaction();
+}
+
+sub CreateTransaction {
+ my $self = shift;
+
+ my ($result, $msg) = $self->{'TemplateObj'}->Parse(
+ TicketObj => $self->{'TicketObj'});
+ return undef unless $result;
+
+ my ($trans, $desc, $transaction) = $self->{'TicketObj'}->Comment(
+ MIMEObj => $self->TemplateObj->MIMEObj);
+ $self->{'TransactionObj'} = $transaction;
+}
+
+
+eval "require RT::Action::RecordComment_Vendor";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RecordComment_Vendor.pm});
+eval "require RT::Action::RecordComment_Local";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RecordComment_Local.pm});
+
+1;
Added: rt/branches/3.2-RELEASE/lib/RT/Action/RecordCorrespondence.pm
==============================================================================
--- (empty file)
+++ rt/branches/3.2-RELEASE/lib/RT/Action/RecordCorrespondence.pm Tue Jul 20 17:30:05 2004
@@ -0,0 +1,98 @@
+# BEGIN LICENSE BLOCK
+#
+# Copyright (c) 1996-2003 Jesse Vincent <jesse at bestpractical.com>
+#
+# (Except where explictly superceded by other copyright notices)
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# Unless otherwise specified, all modifications, corrections or
+# extensions to this work which alter its source code become the
+# property of Best Practical Solutions, LLC when submitted for
+# inclusion in the work.
+#
+#
+# END LICENSE BLOCK
+#
+package RT::Action::RecordCorrespondence;
+require RT::Action::Generic;
+use strict;
+use vars qw/@ISA/;
+ at ISA = qw(RT::Action::Generic);
+
+=head1 NAME
+
+RT::Action::RecordCorrespondence - An Action which can be used from an
+external tool, or in any situation where a ticket transaction has not
+been started, to make a comment on the ticket.
+
+=head1 SYNOPSIS
+
+my $action_obj = RT::Action::RecordCorrespondence->new(
+ 'TicketObj' => $ticket_obj,
+ 'TemplateObj' => $template_obj,
+ );
+my $result = $action_obj->Prepare();
+$action_obj->Commit() if $result;
+
+=head1 METHODS
+
+=head2 Prepare
+
+Check for the existence of a Transaction. If a Transaction already
+exists, and is of type "Comment" or "Correspond", abort because that
+will give us a loop.
+
+=cut
+
+
+sub Prepare {
+ my $self = shift;
+ if (defined $self->{'TransactionObj'} &&
+ $self->{'TransactionObj'}->Type =~ /^(Comment|Correspond)$/) {
+ return undef;
+ }
+ return 1;
+}
+
+=head2 Commit
+
+Create a Transaction by calling the ticket's Correspond method on our
+parsed Template, which may have an RT-Send-Cc or RT-Send-Bcc header.
+The Transaction will be of type Correspond. This Transaction can then
+be used by the scrips that actually send the email.
+
+=cut
+
+sub Commit {
+ my $self = shift;
+ $self->CreateTransaction();
+}
+
+sub CreateTransaction {
+ my $self = shift;
+
+ my ($result, $msg) = $self->{'TemplateObj'}->Parse(
+ TicketObj => $self->{'TicketObj'});
+ return undef unless $result;
+
+ my ($trans, $desc, $transaction) = $self->{'TicketObj'}->Correspond(
+ MIMEObj => $self->TemplateObj->MIMEObj);
+ $self->{'TransactionObj'} = $transaction;
+}
+
+
+eval "require RT::Action::RecordCorrespondence_Vendor";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RecordCorrespondence_Vendor.pm});
+eval "require RT::Action::RecordCorrespondence_Local";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/RecordCorrespondence_Local.pm});
+
+1;
Added: rt/branches/3.2-RELEASE/lib/RT/Search/FromSQL.pm
==============================================================================
--- (empty file)
+++ rt/branches/3.2-RELEASE/lib/RT/Search/FromSQL.pm Tue Jul 20 17:30:05 2004
@@ -0,0 +1,86 @@
+# BEGIN LICENSE BLOCK
+#
+# Copyright (c) 1996-2003 Jesse Vincent <jesse at bestpractical.com>
+#
+# (Except where explictly superceded by other copyright notices)
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# Unless otherwise specified, all modifications, corrections or
+# extensions to this work which alter its source code become the
+# property of Best Practical Solutions, LLC when submitted for
+# inclusion in the work.
+#
+#
+# END LICENSE BLOCK
+=head1 NAME
+
+ RT::Search::FromSQL
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+Find all tickets described by the SQL statement passed as an argument
+
+=head1 METHODS
+
+
+=begin testing
+
+ok (require RT::Search::Generic);
+
+=end testing
+
+
+=cut
+
+package RT::Search::FromSQL;
+
+use strict;
+use base qw(RT::Search::Generic);
+
+=head2 Describe
+
+Returns a localized string describing the module's function.
+
+=cut
+
+# {{{ sub Describe
+sub Describe {
+ my $self = shift;
+ return ($self->loc("TicketSQL search module", ref $self));
+}
+# }}}
+
+=head2 Prepare
+
+The meat of the module. Runs a search on its Tickets object, using
+the SQL string described in its Argument object. The Tickets object
+is reduced to those tickets matching the SQL query.
+
+=cut
+
+# {{{ sub Prepare
+sub Prepare {
+ my $self = shift;
+
+ $self->TicketsObj->FromSQL($self->Argument);
+ return(1);
+}
+# }}}
+
+eval "require RT::Search::FromSQL_Vendor";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Search/FromSQL_Vendor.pm});
+eval "require RT::Search::FromSQL_Local";
+die $@ if ($@ && $@ !~ qr{^Can't locate RT/Search/FromSQL_Local.pm});
+
+1;
Modified: rt/branches/3.2-RELEASE/lib/t/02regression.t.in
==============================================================================
--- rt/branches/3.2-RELEASE/lib/t/02regression.t.in (original)
+++ rt/branches/3.2-RELEASE/lib/t/02regression.t.in Tue Jul 20 17:30:05 2004
@@ -44,3 +44,4 @@
require "@RT_LIB_PATH@/t/03web.pl";
require "@RT_LIB_PATH@/t/04_send_email.pl";
+require "@RT_LIB_PATH@/t/05cronsupport.pl";
Added: rt/branches/3.2-RELEASE/lib/t/05cronsupport.pl.in
==============================================================================
--- (empty file)
+++ rt/branches/3.2-RELEASE/lib/t/05cronsupport.pl.in Tue Jul 20 17:30:05 2004
@@ -0,0 +1,84 @@
+#!@PERL@ -w
+
+use strict;
+
+### Set up some testing data. Test the testing data because why not?
+
+# Create a user with rights, a queue, and some tickets.
+my $user_obj = RT::User->new($RT::SystemUser);
+my ($ret, $msg) = $user_obj->LoadOrCreateByEmail('tara at example.com');
+ok($ret, 'record test user creation');
+$user_obj->SetName('tara');
+$user_obj->PrincipalObj->GrantRight(Right => 'SuperUser');
+my $CurrentUser = RT::CurrentUser->new('tara');
+
+# Create our template, which will be used for tests of RT::Action::Record*.
+
+my $template_content = 'RT-Send-Cc: tla at example.com
+RT-Send-Bcc: jesse at example.com
+
+This is a content string with no content.';
+
+my $template_obj = RT::Template->new($CurrentUser);
+$template_obj->Create(Queue => '0',
+ Name => 'recordtest',
+ Description => 'testing Record actions',
+ Content => $template_content,
+ );
+
+# Create a queue and some tickets.
+
+my $queue_obj = RT::Queue->new($CurrentUser);
+($ret, $msg) = $queue_obj->Create(Name => 'recordtest', Description => 'queue for Action::Record testing');
+ok($ret, 'record test queue creation');
+
+my $ticket1 = RT::Ticket->new($CurrentUser);
+my ($id, $tobj, $msg2) = $ticket1->Create(Queue => $queue_obj,
+ Requestor => ['tara at example.com'],
+ Subject => 'bork bork bork',
+ Priority => 22,
+ );
+ok($id, 'record test ticket creation 1');
+my $ticket2 = RT::Ticket->new($CurrentUser);
+($id, $tobj, $msg2) = $ticket2->Create(Queue => $queue_obj,
+ Requestor => ['root at localhost'],
+ Subject => 'hurdy gurdy'
+ );
+ok($id, 'record test ticket creation 2');
+
+
+### OK. Have data, will travel.
+
+# First test the search.
+
+ok(require RT::Search::FromSQL, "Search::FromSQL loaded");
+my $ticketsqlstr = "Requestor.EmailAddress = '" . $CurrentUser->EmailAddress .
+ "' AND Priority > '20'";
+my $search = RT::Search::FromSQL->new(Argument => $ticketsqlstr, TicketsObj => RT::Tickets->new($CurrentUser),
+ );
+is(ref($search), 'RT::Search::FromSQL', "search created");
+ok($search->Prepare(), "fromsql search run");
+my $counter = 0;
+while(my $t = $search->TicketsObj->Next() ) {
+ is($t->Id(), $ticket1->Id(), "fromsql search results 1");
+ $counter++;
+}
+is ($counter, 1, "fromsql search results 2");
+
+# Right. Now test the actions.
+
+ok(require RT::Action::RecordComment);
+ok(require RT::Action::RecordCorrespondence);
+
+my ($comment_act, $correspond_act);
+ok($comment_act = RT::Action::RecordComment->new(TicketObj => $ticket1, TemplateObj => $template_obj, CurrentUser => $CurrentUser), "RecordComment created");
+ok($correspond_act = RT::Action::RecordCorrespondence->new(TicketObj => $ticket2, TemplateObj => $template_obj, CurrentUser => $CurrentUser), "RecordCorrespondence created");
+ok($comment_act->Prepare(), "Comment prepared");
+ok($correspond_act->Prepare(), "Correspond prepared");
+ok($comment_act->Commit(), "Comment committed");
+ok($correspond_act->Commit(), "Correspondence committed");
+
+# Now test for loop suppression.
+my ($trans, $desc, $transaction) = $ticket2->Comment(MIMEObj => $template_obj->MIMEObj);
+my $bogus_action = RT::Action::RecordComment->new(TicketObj => $ticket1, TemplateObj => $template_obj, TransactionObj => $transaction, CurrentUser => $CurrentUser);
+ok(!$bogus_action->Prepare(), "Comment aborted to prevent loop");
More information about the Rt-commit
mailing list