diff options
author | mark <mark> | 2011-05-13 23:20:53 +0000 |
---|---|---|
committer | mark <mark> | 2011-05-13 23:20:53 +0000 |
commit | cd34706f94273cf381952f57c5fcb7d6910fbae0 (patch) | |
tree | 8dc42aed01a79850884b1f9e70039336e6e806cd /rt | |
parent | 20950bb21ee5dd8839a05dfcd58efa0a98e48e5a (diff) |
notify on custom field change, #11274
Diffstat (limited to 'rt')
-rw-r--r-- | rt/FREESIDE_MODIFIED | 2 | ||||
-rw-r--r-- | rt/etc/initialdata | 30 | ||||
-rw-r--r-- | rt/lib/RT/Condition/CustomFieldTransaction.pm | 86 | ||||
-rw-r--r-- | rt/share/html/Admin/Elements/EditScripOptions | 8 |
4 files changed, 124 insertions, 2 deletions
diff --git a/rt/FREESIDE_MODIFIED b/rt/FREESIDE_MODIFIED index 1c303469a..c04e5e15e 100644 --- a/rt/FREESIDE_MODIFIED +++ b/rt/FREESIDE_MODIFIED @@ -6,6 +6,7 @@ config.layout.in etc/RT_SiteConfig.pm etc/schema.Pg etc/schema.mysql-4.1 +etc/initialdata lib/RT/Attribute_Overlay.pm #bugfix lib/RT/Config.pm @@ -24,6 +25,7 @@ lib/RT/Action/EscalateQueue.pm #ticket escalation lib/RT/Action/SetPriority_Local.pm #ticket escalation lib/RT/CustomFieldValues/Queues.pm #ticket escalation lib/RT/Condition/CustomFieldChange.pm #create ticket on custom field change +lib/RT/Condition/CustomFieldTransaction.pm #notify on custom field change lib/RT/Interface/Web_Vendor.pm lib/RT/Interface/Web/Handler.pm #freeside comp_root for dashboard emails lib/RT/Record.pm #and customfield date patch #fix transaction custom fields diff --git a/rt/etc/initialdata b/rt/etc/initialdata index 9b5506b02..fc2ed2ffb 100644 --- a/rt/etc/initialdata +++ b/rt/etc/initialdata @@ -97,6 +97,13 @@ { Name => 'Extract Subject Tag', # loc Description => 'Extract tags from a Transaction\'s subject and add them to the Ticket\'s subject.', # loc ExecModule => 'ExtractSubjectTag' }, + + #freeside + { Name => 'Set Priority', + Description => 'Set ticket priority', + ExecModule => 'SetPriority', + Argument => '', + }, ); @ScripConditions = ( @@ -185,6 +192,18 @@ ExecModule => 'ReopenTicket', }, + #freeside + { Name => 'On Custom Field Transaction', + Description => 'When a custom field is changed', + ExecModule => 'CustomFieldTransaction', + ApplicableTransTypes => 'Any', + }, + { Name => 'On Custom Field Change', + Description => 'When a custom field is changed to some value', + ExecModule => 'CustomFieldChange', + ApplicableTransTypes => 'Any', + }, + ); @Templates = ( @@ -486,6 +505,17 @@ Hour: { $SubscriptionObj->SubValue('Hour') } } } }, + { Queue => 0, + Name => 'Custom Field Transaction', + Description => 'Custom field value changed', + Content => q[Subject: {$Transaction->BriefDescription()} + +{RT->Config->Get('WebURL')}Ticket/Display.html?id={$Ticket->id} + +{$Transaction->Content()} +], + }, + ); # }}} diff --git a/rt/lib/RT/Condition/CustomFieldTransaction.pm b/rt/lib/RT/Condition/CustomFieldTransaction.pm new file mode 100644 index 000000000..137f74aa6 --- /dev/null +++ b/rt/lib/RT/Condition/CustomFieldTransaction.pm @@ -0,0 +1,86 @@ +package RT::Condition::CustomFieldTransaction; +use base 'RT::Condition'; +use strict; + +=head1 NAME + +RT::Condition::CustomFieldTransaction + +=head1 DESCRIPTION + +Returns true if a transaction changed the value of a custom field. Unlike +CustomFieldChange, this condition doesn't care what the value was, only that +it changed. + +=head2 Parameters + +=over 4 + +=item field (string) + +Only return true if the transaction changed a custom field with this name. +If empty, returns true for any CustomField-type transaction. + +=item include_create (boolean) - Also return true for Create-type transactions. +If 'field' is specified, return true if that field is non-empty in the newly +created object. + +=back + +=head2 IsApplicable + +If the transaction has changed the value of a custom field. + +=head1 BUGS + +Probably interacts badly with multiple custom fields with the same name. + +=cut + +sub IsApplicable { + my $self = shift; + my $trans = $self->TransactionObj; + my $scrip = $self->ScripObj; + my %Rules = $self->Rules; + my ($field, $include_create) = @Rules{'field', 'include_create'}; + + if ( $include_create and $trans->Type eq 'Create' ) { + return 1 if !defined($field); + return 1 if defined($trans->TicketObj->FirstCustomFieldValue($field)); + } + if ($trans->Type eq 'CustomField') { + return 1 if !defined($field); + my $cf = RT::CustomField->new($self->CurrentUser); + $cf->Load($field); + return 1 if defined($cf->Id) and $trans->Field == $cf->Id; + } + return undef; +} + +sub Options { + my $self = shift; + my %args = ( 'QueueObj' => undef, @_ ); + my $cfs = RT::CustomFields->new($self->CurrentUser); + # Allow any ticket custom field to be selected; if it doesn't apply to the + # ticket, it will never contain a value and that's fine. + $cfs->LimitToLookupType('RT::Queue-RT::Ticket'); + my @fieldnames = ('', '(any field)'); + while ( my $cf = $cfs->Next ) { + push @fieldnames, $cf->Name, $cf->Name; + } + return ( + { + 'name' => 'field', + 'label' => 'Custom Field', + 'type' => 'select', + 'options' => \@fieldnames, + }, + { + 'name' => 'include_create', + 'label' => 'Trigger on ticket creation', + 'type' => 'checkbox', + }, + ); +} +1; + diff --git a/rt/share/html/Admin/Elements/EditScripOptions b/rt/share/html/Admin/Elements/EditScripOptions index 7b3848419..264ca3a20 100644 --- a/rt/share/html/Admin/Elements/EditScripOptions +++ b/rt/share/html/Admin/Elements/EditScripOptions @@ -2,10 +2,14 @@ <tr><td></td><td><table> % my $prefix = $Name.'Rules-'; % foreach my $o (@options) { +% my $curr_value = $rules{ $o->{'name'} }; <tr><td align="right"><% $o->{'label'} %>:</td> <td> % if ( $o->{'type'} eq 'text' ) { - <input type="text" name="<% $prefix.$o->{'name'} %>" value="<% $rules{$o->{'name'}} %>"> + <input type="text" name="<% $prefix.$o->{'name'} %>" value="<% $curr_value %>"> +% } +% elsif ( $o->{'type'} eq 'checkbox' ) { + <input type="checkbox" name="<% $prefix.$o->{'name'} %>" value="1" <% $curr_value ? 'CHECKED' : '' %>> % } % elsif ( $o->{'type'} eq 'select' and ref $o->{'options'} ) { <select name="<% $prefix.$o->{'name'} %>"> @@ -13,7 +17,7 @@ % while (@choices) { % my $v = shift @choices; % my $l = shift @choices; - <option value="<% $v %>"<% ($rules{$o->{'name'}} eq $v) ? ' SELECTED' : ''%>> + <option value="<% $v %>"<% ($curr_value eq $v) ? ' SELECTED' : ''%>> <% $l %></option> % } </select> |