From 1b821166888962897d6f4b0c87acb00d6b9f392d Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Thu, 10 Dec 2015 01:01:21 -0800 Subject: [PATCH] fix some problems with creation of subtask tickets, #34061 --- rt/lib/RT/Condition/CustomFieldEquals.pm | 7 ++++--- rt/lib/RT/Template_Vendor.pm | 34 ++++++++++++++++++++++++++++++++ rt/share/html/Admin/Queues/Tasks.html | 18 ++++++++--------- 3 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 rt/lib/RT/Template_Vendor.pm diff --git a/rt/lib/RT/Condition/CustomFieldEquals.pm b/rt/lib/RT/Condition/CustomFieldEquals.pm index 69dedcbca..8ebf94b2b 100644 --- a/rt/lib/RT/Condition/CustomFieldEquals.pm +++ b/rt/lib/RT/Condition/CustomFieldEquals.pm @@ -28,9 +28,10 @@ sub IsApplicable { if ($trans->Type eq 'CustomField') { my $cf = RT::CustomField->new($self->CurrentUser); $cf->Load($field); - return $trans->Field == $cf->Id - and ($trans->NewValue eq $value) - and ($trans->OldValue ne $value) + return ( $trans->Field == $cf->Id + and $trans->NewValue eq $value + and $trans->OldValue ne $value + ); } return undef; } diff --git a/rt/lib/RT/Template_Vendor.pm b/rt/lib/RT/Template_Vendor.pm new file mode 100644 index 000000000..f1a276c3d --- /dev/null +++ b/rt/lib/RT/Template_Vendor.pm @@ -0,0 +1,34 @@ +package RT::Template; + +=item LoadByName + +Takes Name and Queue arguments. Tries to load queue specific template +first, then global. If Queue argument is omitted then global template +is tried, not template with the name in any queue. + +=cut + +sub LoadByName { + my $self = shift; + my %args = ( + Queue => undef, + Name => undef, + @_ + ); + my $queue = $args{'Queue'}; + if ( blessed $queue ) { + $queue = $queue->id; + } elsif ( defined $queue and $queue =~ /\D/ ) { + my $tmp = RT::Queue->new( $self->CurrentUser ); + $tmp->Load($queue); + $queue = $tmp->id; + } + + return $self->LoadGlobalTemplate( $args{'Name'} ) unless $queue; + + $self->LoadQueueTemplate( Queue => $queue, Name => $args{'Name'} ); + return $self->id if $self->id; + return $self->LoadGlobalTemplate( $args{'Name'} ); +} + +1; diff --git a/rt/share/html/Admin/Queues/Tasks.html b/rt/share/html/Admin/Queues/Tasks.html index 30ec12b1c..94df549cc 100755 --- a/rt/share/html/Admin/Queues/Tasks.html +++ b/rt/share/html/Admin/Queues/Tasks.html @@ -92,7 +92,7 @@ my $title = loc("Set up subtasks for queue [_1]", $QueueObj->Name); my $TEMPLATE_NAME = '[Subtask]'; my $SCRIPCONDITION_NAME = '[Subtask] Queue='.$Queue; -my $SUBJECT_PREFIX = q({ $Tickets{'TOP'}->Subject }-); +my $SUBJECT_PREFIX = q({ $TOP->Subject }-); my ($Scrip, $ScripCondition, $Template, $CustomField); @@ -112,7 +112,7 @@ $Scrip = RT::Scrip->new($RT::SystemUser); { my $Scrips = RT::Scrips->new($RT::SystemUser); $Scrips->LimitToQueue($Queue); - $Scrips->Limit( FIELD => 'Template', VALUE => $TEMPLATE_NAME ); + $Scrips->Limit( FIELD => 'Template', VALUE => $Template->Id ); if ( $Scrips->Count > 0 ) { $Scrip = $Scrips->First; } @@ -138,12 +138,13 @@ if ( $ARGS{task_id} ) { # actually contains numeric indices my %task_opts = map { $_ => $ARGS{$_} } grep /^$task_id-/, keys(%ARGS); my $task_content = "===Create-Ticket: $task_id +CF-$cfname:" . q[ Depended-On-By: TOP -CF-$cfname: -"; - # any other static content can go here, but we always want the child - # ticket relationship, and we want to force the ConditionCF to be empty - # to avoid recursion. +Owner: { $TOP->Owner } +{ join("\n", map { "Requestor: $_" } + $TOP->Requestors->MemberEmailAddresses) } +]; + # any other attributes to put on subtask tickets should go here also. my $has_content = 0; @@ -171,7 +172,6 @@ CF-$cfname: $new_content .= $task_content; } } - warn "NEW CONTENT:\n$new_content\n\n"; # XXX if ( ! $Template->Id ) { my ( $val, $msg ) = $Template->Create( @@ -252,12 +252,10 @@ my $Action = $action_class->new( CurrentUser => $session{'CurrentUser'}, ); # this will populate $Action with the 'create_tickets' hash -warn $Template->Content; $Action->Parse( Content => $Template->Content, _ActiveContent => 0, ); -warn Dumper \$Action; my @task_ids; @task_ids = @{ $Action->{create_tickets} } if exists $Action->{create_tickets}; -- 2.11.0