[Rt-commit] rt branch, lcore, updated. 552fb034effa07ab34afc7150f814c2be3c985b0
clkao at bestpractical.com
clkao at bestpractical.com
Wed Sep 2 04:40:44 EDT 2009
The branch, lcore has been updated
via 552fb034effa07ab34afc7150f814c2be3c985b0 (commit)
via 0254cc052bafe6079caece8feded10166ca47abf (commit)
via 5c883e2bf20f2825cb250c8cfe1def72c69df955 (commit)
via c0fa532e19ff0c4a704195e9f37279cf205f1c8c (commit)
via 6e61a36ba603ae8f3009dec922d5c36b263ac26a (commit)
from fb60f953f6e1d816144a51a3eb71b4cacbf43df8 (commit)
Summary of changes:
TODO.lorzy | 34 ++++++++++++++++++++++++++++++++++
lib/RT.pm | 2 +-
lib/RT/Lorzy.pm | 25 +++++++++++++++++++++++++
lib/RT/Lorzy/Package/RT.pm | 4 ++--
t/lorzy/accessor.t | 22 ++++++++++++++++++++++
5 files changed, 84 insertions(+), 3 deletions(-)
create mode 100644 t/lorzy/accessor.t
- Log -----------------------------------------------------------------
commit 6e61a36ba603ae8f3009dec922d5c36b263ac26a
Merge: 01d4824 83326c4
Author: Chia-liang Kao <clkao at clkao.org>
Date: Thu Aug 27 06:36:03 2009 +0800
Merge branch 'master' into lcore
diff --cc TODO.lorzy
index 51ebd47,be0623e..7911bf6
--- a/TODO.lorzy
+++ b/TODO.lorzy
@@@ -1,136 -1,2 +1,170 @@@
* lorzy code improvements: control flow handling like return, exception
* test and implement ordering of rules
+
+
+
+Possible rule workflows:
+
+
+On ticket creation, send email to the user who is the requestor of the ticket
+using a particular template.
+
+On ticket correspondence, if the requestor of the ticket wasn't the sender,
+send a copy to him.
+
+On ticket correspondence, send email to all members of the group
+"adminccs of ticket $ticket->id."
+
+On ticket correspondence, send email to jesse at example.com
+
+On ticket correspondence, add a copy of the correspondence as a comment
+on each ticket which depends on ticket $id
+
+On ticket creation, if the ticket subject matches /emergency/, send a pager
+email to sysadmin at example.com
+
+On ticket update, if the ticket's custom field "Foo" has a value that is in the list ("A", "B", "C"), set its status to 'stalled'.
+
+On ticket update, if its custom field "Foo" has a value that is > 20, create a new ticket owned by the ticket requestor's manager in the approvals queue which the original ticket depends on, copying various bits of ticket metadata. It subject should be "Approval for '$ticket->subject'"
+
+on ticket creation
+ If there is no owner, figure out which possible owner of tickets in this queue has the fewest open tickets and assign it to him.
+
+
+on ticket creation
+ If there is no owner, figure out which possible owner of tickets in this queue has the fewest minutes of work left on open tickets and assign it to him.
+
+on ticket creation
+ if the subject matches /mac/, assign to a member of the mac group
+ if the subject matches /windows/, assign to a member of the windows group
+ if the subject matches /linux/, assign to a member of the sysadmin group
+ if the subject matches /solaris/, assign to a member of the sysadmin group
+ if the subject matches /VAX/,
+ send a note back to the requestor saying we don't do VMS
+ and resolve the ticket
+
+
+
+ when =~ mac: $ticket->set_owner('bob');
+ when =~ pc: $ticket->set_owner('joe');
+ when =~ vax: $ticket->set_status('resolved'); send_email($ticket->requestors, "ha ha. no");
+
+
+ if
+
+on ticket resolve,
+ if this ticket has never been resolved before, send email
+ to the requestor telling them their ticket has been resolved.
+
+
+rules and language features we need
+
+
+ let
+
+ use variable
+
+ if/elsif/else
+
+ foreach
+
+ string match
+
+ integer operations
+
+ arithmetic
+
+ logical operators
+
+ on transaction batch - when all other rules complete?
+
+ "if ticket has no unresolved dependencies"
+
+ when ticket's status is set to rejected
+
+ if status is in the list of {inactive,active} statuses
+
+ find tickets:
+ takes ticketsql?
+ takes "template" to match against?
+
+ filter transactions by "template".
+ "grep" + accessors
+
+
+ ticket has unresolved dependencies
+ by type"
+
+ set status
+
+
+ find users
+ get watchers by type
+
+
+ add correspondence
+ takes a ticket id
+ might take a template
+ might take a block of text
+
+ add comment
+ see "add correspondence"
+
+ find tickets
+
+ call other lambda by name?
+
+ run rule action:
+ notify "set of people" with template "template"
+
+
+ "send email"
+ to
+ cc
+ bcc
+ subject
+ body
+ attachments
+ template
+ extra headers
+ encryption
+
+ create a ticket
+
+
+
+accessors "for everything"
++------------------------
++
++
++if ( ... )
++
++ Str -> .... -> Bool
++
++if ( ... ticket:subject [isdefined,not,...] .... )
++
++if ( ticket:subject matches [....] ) <- "enter something here"
++
++if ( ticket:subject matches "foo" ) <- ....
++
++
++
++-----
++
++Bool -> ... -> Bool
++[Bool] -> Bool
++
++if ( ticket:subject matches "foo" ) <- ....
++
++if ( (and (ticket:subject matches "foo" .... (+ -)
++ )
++
++
++
++-=-----
++
++Str -> .... -> Bool
++
++if ( ticket:subject )
++
++
commit c0fa532e19ff0c4a704195e9f37279cf205f1c8c
Merge: 6e61a36 fb60f95
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Tue Sep 1 21:58:14 2009 +0800
Merge branch 'lcore' of diesel.bestpractical.com:/git/rt into lcore
commit 5c883e2bf20f2825cb250c8cfe1def72c69df955
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Wed Sep 2 16:24:31 2009 +0800
use hashref for lcore::parameter.
diff --git a/lib/RT/Lorzy/Package/RT.pm b/lib/RT/Lorzy/Package/RT.pm
index e473f8c..8b1304d 100644
--- a/lib/RT/Lorzy/Package/RT.pm
+++ b/lib/RT/Lorzy/Package/RT.pm
@@ -89,7 +89,7 @@ __PACKAGE__->lcore_defun( 'Condition.OnReopen',
$RT::Lorzy::LCORE->env->set_symbol('RT.MkCondition.BeforeDue' => LCore::Primitive->new(
# format is "1d2h3m4s" for 1 day and 2 hours and 3 minutes and 4 seconds.
- parameters => [LCore::Parameter->new( name => 'datestring', type => 'Str' )],
+ parameters => [LCore::Parameter->new({ name => 'datestring', type => 'Str'})],
lazy => 0,
body => sub {
my $datestring = shift;
@@ -117,7 +117,7 @@ $RT::Lorzy::LCORE->env->set_symbol('RT.MkCondition.BeforeDue' => LCore::Primitiv
));
$RT::Lorzy::LCORE->env->set_symbol('RT.MkCondition.PriorityExceeds' => LCore::Primitive->new(
- parameters => [ LCore::Parameter->new( name => 'priority', type => 'Num' ) ],
+ parameters => [ LCore::Parameter->new({ name => 'priority', type => 'Num' }) ],
body => sub {
my $priority = shift;
return LCore::Primitive->new
commit 0254cc052bafe6079caece8feded10166ca47abf
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Wed Sep 2 16:35:04 2009 +0800
delay lorzy init time so we have access to jifty models.
diff --git a/lib/RT.pm b/lib/RT.pm
index 6166d82..26eb3b4 100644
--- a/lib/RT.pm
+++ b/lib/RT.pm
@@ -52,7 +52,6 @@ package RT;
use RT::CurrentUser;
use RT::DateTime;
-use RT::Lorzy;
use Jifty::Util;
use strict;
@@ -118,6 +117,7 @@ sub init {
init_system_objects();
init_plugins();
+ require RT::Lorzy;
# enable approval subsystem
require RT::Approval;
}
commit 552fb034effa07ab34afc7150f814c2be3c985b0
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Wed Sep 2 16:40:10 2009 +0800
basic ticket accessors (read only)
diff --git a/lib/RT/Lorzy.pm b/lib/RT/Lorzy.pm
index 2d2c1dc..52603c8 100644
--- a/lib/RT/Lorzy.pm
+++ b/lib/RT/Lorzy.pm
@@ -71,6 +71,31 @@ $LCORE->env->set_symbol('RT.RuleAction.Run' => LCore::Primitive->new
));
+sub install_ticket_accessors {
+ my ($env) = @_;
+ for my $column (RT::Model::Ticket->columns) {
+ my $name = $column->name;
+ my $type = $column->type;
+ $type = $type =~ m/^varchar/ ? 'Str'
+ : $type =~ m/int$/ ? 'Int'
+ : $type eq 'integer' ? 'Int'
+ : $type eq 'serial' ? 'Int'
+ : next;
+
+ $env->set_symbol('RT::Model::Ticket.'.$name => LCore::Primitive->new
+ ( body => sub {
+ my ($ticket) = @_;
+ $ticket->$name
+ },
+ lazy => 0,
+ parameters => [ LCore::Parameter->new({ name => 'ticket', type => 'RT::Model::Ticket' }) ],
+ return_type => $type
+ ));
+ }
+}
+
+RT::Lorzy::install_ticket_accessors($RT::Lorzy::LCORE->env);
+
my %cond_compat_map = ( 'On Create' => 'OnCreate',
'On Transaction' => 'OnTransaction',
diff --git a/t/lorzy/accessor.t b/t/lorzy/accessor.t
new file mode 100644
index 0000000..34b6ffb
--- /dev/null
+++ b/t/lorzy/accessor.t
@@ -0,0 +1,22 @@
+use Test::More tests => 3;
+use RT::Test;
+
+use strict;
+use warnings;
+
+use_ok('RT::Lorzy');
+my $l = $RT::Lorzy::LCORE;
+
+my $ticket_subject = $l->analyze_it(q{
+(lambda (ticket)
+ (RT::Model::Ticket.subject ticket))
+})->($l->env);
+
+my $queue = RT::Model::Queue->new(current_user => RT->system_user);
+my ($queue_id) = $queue->create( name => 'lorzy');
+ok( $queue_id, 'queue created' );
+
+my $ticket = RT::Model::Ticket->new(current_user => RT->system_user );
+my ($rv, $msg) = $ticket->create( subject => 'lorzy test', queue => $queue->name, requestor => 'foo at localhost' );
+
+is( $ticket_subject->apply($ticket), 'lorzy test' );
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list