diff options
author | mark <mark> | 2010-11-17 20:44:11 +0000 |
---|---|---|
committer | mark <mark> | 2010-11-17 20:44:11 +0000 |
commit | 5ef064aeca4a22dbe38b538e65d512d5d398fe2f (patch) | |
tree | 81959e7fd86bc537b61cf530983df26b01ca4fba /rt/lib | |
parent | 2a874cdff2e2bc0d5d6920aae306d5b7c3d4aa97 (diff) |
create ticket on custom field change, RT#10139
Diffstat (limited to 'rt/lib')
-rwxr-xr-x | rt/lib/RT/Action.pm | 11 | ||||
-rw-r--r-- | rt/lib/RT/Action/CreateTickets.pm | 19 | ||||
-rwxr-xr-x | rt/lib/RT/Condition.pm | 13 | ||||
-rw-r--r-- | rt/lib/RT/Condition/CustomFieldChange.pm | 56 | ||||
-rw-r--r-- | rt/lib/RT/Scrip_Overlay.pm | 4 |
5 files changed, 103 insertions, 0 deletions
diff --git a/rt/lib/RT/Action.pm b/rt/lib/RT/Action.pm index 1918a7e..42bf767 100755 --- a/rt/lib/RT/Action.pm +++ b/rt/lib/RT/Action.pm @@ -204,6 +204,17 @@ sub IsApplicable { } # }}} +sub Options { + my $self = shift; + return(); +} + +sub Rules { + my $self = shift; + return () if !$self->ScripObj or !$self->ScripObj->ActionRules; + return(split "\n", $self->ScripObj->ActionRules); +} + # {{{ sub DESTROY sub DESTROY { my $self = shift; diff --git a/rt/lib/RT/Action/CreateTickets.pm b/rt/lib/RT/Action/CreateTickets.pm index 4883ae3..74520ca 100644 --- a/rt/lib/RT/Action/CreateTickets.pm +++ b/rt/lib/RT/Action/CreateTickets.pm @@ -762,6 +762,7 @@ sub ParseLines { FinalPriority => $args{'finalpriority'} || 0, SquelchMailTo => $args{'squelchmailto'}, Type => $args{'type'}, + $self->Rules ); if ( $args{content} ) { @@ -1238,6 +1239,24 @@ sub PostProcess { } +sub Options { + my $self = shift; + my $queues = RT::Queues->new($self->CurrentUser); + $queues->UnLimit; + my @names; + while (my $queue = $queues->Next) { + push @names, $queue->Id, $queue->Name; + } + return ( + { + 'name' => 'Queue', + 'label' => 'In queue', + 'type' => 'select', + 'options' => \@names + } + ) +} + eval "require RT::Action::CreateTickets_Vendor"; die $@ if ( $@ && $@ !~ qr{^Can't locate RT/Action/CreateTickets_Vendor.pm} ); eval "require RT::Action::CreateTickets_Local"; diff --git a/rt/lib/RT/Condition.pm b/rt/lib/RT/Condition.pm index be7c4c5..dfd58e7 100755 --- a/rt/lib/RT/Condition.pm +++ b/rt/lib/RT/Condition.pm @@ -210,6 +210,19 @@ sub IsApplicable { } # }}} +sub Options { + my $self = shift; + return(); +} + +sub Rules { + my $self = shift; + return () if !$self->ScripObj or !$self->ScripObj->ConditionRules; + # By default, option names and values are on consecutive lines. + # Override this if you need anything more interesting. + return(split "\n", $self->ScripObj->ConditionRules); +} + # {{{ sub DESTROY sub DESTROY { my $self = shift; diff --git a/rt/lib/RT/Condition/CustomFieldChange.pm b/rt/lib/RT/Condition/CustomFieldChange.pm new file mode 100644 index 0000000..b9228a5 --- /dev/null +++ b/rt/lib/RT/Condition/CustomFieldChange.pm @@ -0,0 +1,56 @@ +package RT::Condition::CustomFieldChange; +use base 'RT::Condition'; +use strict; + +=head2 IsApplicable + +If a custom field has a particular value. + +=cut + +# Based on Chuck Boeheim's code posted on the RT Wiki 3/13/06 + +sub IsApplicable { + my $self = shift; + my $trans = $self->TransactionObj; + my $scrip = $self->ScripObj; + my %Rules = $self->Rules; + my ($field, $value) = @Rules{'field', 'value'}; + return if !defined($field) or !defined($value); + + if ($trans->Type eq 'Create') { + return 1 if $trans->TicketObj->FirstCustomFieldValue($field) eq $value; + } + if ($trans->Type eq 'CustomField') { + my $cf = RT::CustomField->new($self->CurrentUser); + $cf->Load($field); + return 1 if $trans->Field == $cf->Id and $trans->NewValue eq $value; + } + return undef; +} + +sub Options { + my $self = shift; + my %args = ( 'QueueObj' => undef, @_ ); + my $QueueObj = $args{'QueueObj'}; + my $cfs = $QueueObj->TicketCustomFields(); + my @fieldnames; + while ( my $cf = $cfs->Next ) { + push @fieldnames, $cf->Name, $cf->Name; + } + return ( + { + 'name' => 'field', + 'label' => 'Custom Field', + 'type' => 'select', + 'options' => \@fieldnames, + }, + { + 'name' => 'value', + 'label' => 'Value', + 'type' => 'text', + }, + ); +} +1; + diff --git a/rt/lib/RT/Scrip_Overlay.pm b/rt/lib/RT/Scrip_Overlay.pm index 6c2cbd5..b5beb34 100644 --- a/rt/lib/RT/Scrip_Overlay.pm +++ b/rt/lib/RT/Scrip_Overlay.pm @@ -103,6 +103,8 @@ sub Create { CustomPrepareCode => undef, CustomCommitCode => undef, CustomIsApplicableCode => undef, + ConditionRules => undef, + ActionRules => undef, @_ ); @@ -162,6 +164,8 @@ sub Create { CustomPrepareCode => $args{'CustomPrepareCode'}, CustomCommitCode => $args{'CustomCommitCode'}, CustomIsApplicableCode => $args{'CustomIsApplicableCode'}, + ConditionRules => $args{'ConditionRules'}, + ActionRules => $args{'ActionRules'}, ); if ( $id ) { return ( $id, $self->loc('Scrip Created') ); |