[Rt-commit] r19010 - in rt/3.999/branches/lorzy: lib/RT lib/RT/Lorzy lib/RT/Model t/api t/lorzy
clkao at bestpractical.com
clkao at bestpractical.com
Wed Apr 1 09:38:01 EDT 2009
Author: clkao
Date: Wed Apr 1 09:38:00 2009
New Revision: 19010
Added:
rt/3.999/branches/lorzy/lib/RT/Model/Rule.pm
Modified:
rt/3.999/branches/lorzy/lib/RT/Bootstrap.pm
rt/3.999/branches/lorzy/lib/RT/Lorzy.pm
rt/3.999/branches/lorzy/lib/RT/Lorzy/Dispatcher.pm
rt/3.999/branches/lorzy/t/api/action-createtickets.t
rt/3.999/branches/lorzy/t/approval/basic.t
rt/3.999/branches/lorzy/t/lorzy/basic.t
Log:
make lorzy rules serialized in model.
Modified: rt/3.999/branches/lorzy/lib/RT/Bootstrap.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Bootstrap.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/Bootstrap.pm Wed Apr 1 09:38:00 2009
@@ -446,14 +446,15 @@
require RT::Lorzy;
require Lorzy::Builder;
for my $item (sort { $a->{description} cmp $b->{description} } @Scrips) {
- my $rule = RT::Lorzy->create_scripish(
+ my $rule_factory = RT::Lorzy->create_scripish(
$item->{scrip_condition},
$item->{scrip_action},
$item->{template},
$item->{description},
);
- RT::Lorzy::Dispatcher->add_rule( $rule );
+ my $rule = RT::Model::Rule->new( current_user => RT->system_user );
+ $rule->create_from_factory( $rule_factory );
}
}
Modified: rt/3.999/branches/lorzy/lib/RT/Lorzy.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Lorzy.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/Lorzy.pm Wed Apr 1 09:38:00 2009
@@ -6,7 +6,7 @@
use Lorzy::Evaluator;
use RT::Lorzy::Dispatcher;
-RT::Ruleset->register( RT::Lorzy::Dispatcher->new );
+RT::Ruleset->register( 'RT::Lorzy::Dispatcher' );
our $EVAL = Lorzy::Evaluator->new();
$EVAL->load_package($_) for qw(Str Native);
$EVAL->load_package('RT', 'RT::Lorzy::Package::RT');
Modified: rt/3.999/branches/lorzy/lib/RT/Lorzy/Dispatcher.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Lorzy/Dispatcher.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/Lorzy/Dispatcher.pm Wed Apr 1 09:38:00 2009
@@ -1,18 +1,27 @@
package RT::Lorzy::Dispatcher;
-use base 'RT::Ruleset';
-
-my $rules = [];
+use strict;
+use warnings;
+#use base 'RT::Ruleset';
sub reset_rules {
- $rules = [];
-}
-
-sub add_rule {
- my ($self, $rule) = @_;
- push @$rules, $rule;
+ my $rules = RT::Model::RuleCollection->new( current_user => RT::CurrentUser->superuser);
+ for (@$rules) {
+ $_->delete;
+ }
}
sub rules {
+ my $rules = RT::Model::RuleCollection->new( current_user => RT::CurrentUser->superuser);
+ $rules->unlimit;
+ return [ map {
+ RT::Lorzy::RuleFactory->make_factory(
+ { condition => Jifty::YAML::Load($_->condition),
+ prepare => Jifty::YAML::Load($_->prepare),
+ action => Jifty::YAML::Load($_->action),
+ description => $_->description,
+ _stage => 'transaction_create' })
+ } @$rules];
+
return $rules;
}
Added: rt/3.999/branches/lorzy/lib/RT/Model/Rule.pm
==============================================================================
--- (empty file)
+++ rt/3.999/branches/lorzy/lib/RT/Model/Rule.pm Wed Apr 1 09:38:00 2009
@@ -0,0 +1,89 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
+# <jesse at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/copyleft/gpl.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+=head1 NAME
+
+RT::Model::Rule - an RT Rule object represening lorzy code
+
+=head1 METHODS
+
+
+=cut
+
+use strict;
+use warnings;
+
+package RT::Model::Rule;
+
+use base qw'RT::Record';
+
+sub table {'Rules'}
+use Jifty::DBI::Schema;
+use Jifty::DBI::Record schema {
+ column action => type is 'text';
+ column condition => type is 'text';
+ column prepare => type is 'text';
+ column description => type is 'text';
+};
+use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata map => {
+ created_by => 'creator',
+ created_on => 'created',
+ updated_by => 'last_updated_by',
+ updated_on => 'last_updated'
+};
+
+sub create_from_factory {
+ my ($self, $factory) = @_;
+ my %args = map { $_ => Jifty::YAML::Dump( $factory->$_ ) }
+ qw(action condition prepare );
+ $self->SUPER::create( %args,
+ description => $factory->description );
+}
+
+1;
+
Modified: rt/3.999/branches/lorzy/t/api/action-createtickets.t
==============================================================================
--- rt/3.999/branches/lorzy/t/api/action-createtickets.t (original)
+++ rt/3.999/branches/lorzy/t/api/action-createtickets.t Wed Apr 1 09:38:00 2009
@@ -55,14 +55,15 @@
$q->create(name => 'WorkflowTest');
ok ($q->id, "Created workflow test queue");
-my $rule = RT::Lorzy->create_scripish(
+my $rule_factory = RT::Lorzy->create_scripish(
'On Transaction',
'Create Tickets',
'Approvals',
'Create approval tickets',
$q->id);
-RT::Lorzy::Dispatcher->add_rule( $rule );
+my $rule = RT::Model::Rule->new( current_user => RT->system_user );
+$rule->create_from_factory( $rule_factory );
my $t = RT::Model::Ticket->new(current_user => RT->system_user);
my($tid, $ttrans, $tmsg) = $t->create(subject => "Sample workflow test",
Modified: rt/3.999/branches/lorzy/t/approval/basic.t
==============================================================================
--- rt/3.999/branches/lorzy/t/approval/basic.t (original)
+++ rt/3.999/branches/lorzy/t/approval/basic.t Wed Apr 1 09:38:00 2009
@@ -70,14 +70,15 @@
ok ($q->id, "Created PO queue");
# XXX: limit to one queue
-my $rule = RT::Lorzy->create_scripish(
+my $rule_factory = RT::Lorzy->create_scripish(
'On Create',
'Create Tickets',
'PO Approvals',
$q->id,
);
-RT::Lorzy::Dispatcher->add_rule( $rule );
+my $rule = RT::Model::Rule->new( current_user => RT->system_user );
+$rule->create_from_factory( $rule_factory );
my $t = RT::Model::Ticket->new(current_user => RT->system_user);
my ($tid, $ttrans, $tmsg);
Modified: rt/3.999/branches/lorzy/t/lorzy/basic.t
==============================================================================
--- rt/3.999/branches/lorzy/t/lorzy/basic.t (original)
+++ rt/3.999/branches/lorzy/t/lorzy/basic.t Wed Apr 1 09:38:00 2009
@@ -59,16 +59,17 @@
ok($ret);
use RT::Lorzy;
-
+# XXX: rework the test to use a context object
my $action_is_run = 0;
-RT::Lorzy::Dispatcher->add_rule(
+my $rule = RT::Model::Rule->new( current_user => RT->system_user );
+$rule->create_from_factory(
RT::Lorzy::RuleFactory->make_factory
( { condition => $is_open,
_stage => 'transaction_create',
action => sub { $action_is_run++ } } )
);
-
+warn $rule->id;
$ticket->comment(content => 'lorzy lorzy in the code');
ok($action_is_run);
More information about the Rt-commit
mailing list