diff options
| -rw-r--r-- | FS/FS/TicketSystem.pm | 60 | ||||
| -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 | 
5 files changed, 157 insertions, 29 deletions
| diff --git a/FS/FS/TicketSystem.pm b/FS/FS/TicketSystem.pm index 1020a8cc3..9d11ff47b 100644 --- a/FS/FS/TicketSystem.pm +++ b/FS/FS/TicketSystem.pm @@ -38,32 +38,6 @@ sub _upgrade_data {    my $CurrentUser = $session->{'CurrentUser'}      or die 'freeside-upgrade must run as a valid RT user'; -  # CustomFieldChange scrip condition -  my $ScripCondition = RT::ScripCondition->new($CurrentUser); -  $ScripCondition->LoadByCols('ExecModule' => 'CustomFieldChange'); -  if (!defined($ScripCondition->Id)) { -    my ($val, $msg) = $ScripCondition->Create( -      'Name' => 'On Custom Field Change', -      'Description' => 'When a custom field is changed to some value', -      'ExecModule' => 'CustomFieldChange', -      'ApplicableTransTypes' => 'Any', -    ); -    die $msg if !$val; -  } - -  # SetPriority scrip action -  my $ScripAction = RT::ScripAction->new($CurrentUser); -  $ScripAction->LoadByCols('ExecModule' => 'SetPriority'); -  if (!defined($ScripAction->Id)) { -    my ($val, $msg) = $ScripAction->Create( -      'Name' => 'Set Priority', -      'Description' => 'Set ticket priority', -      'ExecModule' => 'SetPriority', -      'Argument' => '', -    ); -    die $msg if !$val; -  } -    # EscalateQueue custom field and friends    my $CF = RT::CustomField->new($CurrentUser);    $CF->Load('EscalateQueue'); @@ -85,7 +59,7 @@ sub _upgrade_data {      die $msg if !$val;    } -  # Create any missing scrips +  # Load from RT data file    our (@Groups, @Users, @ACL, @Queues, @ScripActions, @ScripConditions,         @Templates, @CustomFields, @Scrips, @Attributes, @Initial, @Final);    my $datafile = '%%%RT_PATH%%%/etc/initialdata'; @@ -95,6 +69,7 @@ sub _upgrade_data {      return;    } +  # Cache existing ScripCondition, ScripAction, and Template IDs    my $search = RT::ScripConditions->new($CurrentUser);    $search->UnLimit;    my %condition = map { lc($_->Name), $_->Id } @{ $search->ItemsArrayRef }; @@ -107,6 +82,37 @@ sub _upgrade_data {    $search->UnLimit;    my %template = map { lc($_->Name), $_->Id } @{ $search->ItemsArrayRef }; +  # ScripConditions +  my $ScripCondition = RT::ScripCondition->new($CurrentUser); +  foreach my $sc (@ScripConditions) { +    # $sc: Name, Description, ApplicableTransTypes, ExecModule, Argument +    next if exists( $condition{ lc($sc->{Name}) } ); +    my ($val, $msg) = $ScripCondition->Create( %$sc ); +    die $msg if !$val; +    $condition{ lc($ScripCondition->Name) } = $ScripCondition->Id; +  } + +  # ScripActions +  my $ScripAction = RT::ScripAction->new($CurrentUser); +  foreach my $sa (@ScripActions) { +    # $sa: Name, Description, ExecModule, Argument +    next if exists( $action{ lc($sa->{Name}) } ); +    my ($val, $msg) = $ScripAction->Create( %$sa ); +    die $msg if !$val; +    $action{ lc($ScripAction->Name) } = $ScripAction->Id; +  } + +  # Templates +  my $Template = RT::Template->new($CurrentUser); +  foreach my $t (@Templates) { +    # $t: Queue, Name, Description, Content +    next if exists( $template{ lc($t->{Name}) } ); +    my ($val, $msg) = $Template->Create( %$t ); +    die $msg if !$val; +    $template{ lc($Template->Name) } = $Template->Id; +  } + +  # Scrips    my $Scrip = RT::Scrip->new($CurrentUser);    foreach my $s ( @Scrips ) {      my $desc = $s->{'Description'}; 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> | 
