[Bps-public-commit] rt-extension-tags branch, master, updated. ee9d3061fa3e603f4276a5ae2c794b9e851a914d
Alex Vandiver
alexmv at bestpractical.com
Wed Jul 13 05:35:50 EDT 2016
The branch, master has been updated
via ee9d3061fa3e603f4276a5ae2c794b9e851a914d (commit)
via c924eb23c99ffa232c26d50df0da4d838e70be16 (commit)
via d5a17d2ce02eac4ed1106020531edc18080d5b75 (commit)
via f84f3546d4171f7c651b40266058fd9ed3f7a332 (commit)
via 72a7cbc6ae044ffa1fc583074fce52c15889be88 (commit)
via 34c9350b2c86381e8bc054b0fb61139090a3d11c (commit)
via f5f675531064ac1381e52ebf9e67e240540d80d0 (commit)
via 8f3584870caa6d3bc0bea3847aebce59afcc2aed (commit)
via d2cfa38e2efaa99ebcc20833441801a74068ce7d (commit)
from f8b5595b63aa234e4ddaad9ed2f3c8ef0ba17927 (commit)
Summary of changes:
etc/initialdata | 33 +++++++-----------
lib/RT/Action/AddNewCFValue.pm | 78 ++++++++++++++++++++++++------------------
2 files changed, 57 insertions(+), 54 deletions(-)
- Log -----------------------------------------------------------------
commit d2cfa38e2efaa99ebcc20833441801a74068ce7d
Author: Alex Vandiver <alex at chmrr.net>
Date: Wed Jul 13 00:19:08 2016 -0700
Remove debugging lines
diff --git a/lib/RT/Action/AddNewCFValue.pm b/lib/RT/Action/AddNewCFValue.pm
index 3e936d3..2e46cb1 100644
--- a/lib/RT/Action/AddNewCFValue.pm
+++ b/lib/RT/Action/AddNewCFValue.pm
@@ -58,8 +58,6 @@ sub Commit {
foreach my $value ( @current_values ){
# Already have it
- warn "Content is: " . $cf_value->Content;
- warn "Value is: $value";
return 1 if $cf_value->Content eq $value;
}
commit 8f3584870caa6d3bc0bea3847aebce59afcc2aed
Author: Alex Vandiver <alex at chmrr.net>
Date: Wed Jul 13 00:49:05 2016 -0700
perltidy using RT's .perltidyrc
diff --git a/lib/RT/Action/AddNewCFValue.pm b/lib/RT/Action/AddNewCFValue.pm
index 2e46cb1..f6e22b7 100644
--- a/lib/RT/Action/AddNewCFValue.pm
+++ b/lib/RT/Action/AddNewCFValue.pm
@@ -20,8 +20,8 @@ action when the action is installed.
=cut
sub Commit {
- my $self = shift;
- my $txn = $self->TransactionObj;
+ my $self = shift;
+ my $txn = $self->TransactionObj;
my $cf_name = $self->Argument;
my $cf = $self->TicketObj->LoadCustomFieldByIdentifier($cf_name);
@@ -29,34 +29,38 @@ sub Commit {
my $values_obj = $cf->Values;
my @current_values;
- while ( my $cf_value = $values_obj->Next ){
+ while ( my $cf_value = $values_obj->Next ) {
push @current_values, $cf_value->Name;
}
- if ( $txn->Type eq 'Create') {
+ if ( $txn->Type eq 'Create' ) {
+
# Can get multiple new values from create, so check them all
- my @ticket_values =
- split /\n/, $self->TicketObj->CustomFieldValuesAsString($cf_name);
+ my @ticket_values = split /\n/,
+ $self->TicketObj->CustomFieldValuesAsString($cf_name);
+
+ foreach my $value (@ticket_values) {
- foreach my $value ( @ticket_values ){
# Already got it
- next if grep {$value eq $_} @current_values;
+ next if grep { $value eq $_ } @current_values;
# Don't have it, so add it
$cf->AddValue( Name => $value );
}
return 1;
- }
- else{
+ } else {
+
# CF update transaction
my $cf_value = $self->NewReferenceObject($txn);
- if ( not $cf_value->Id ){
- RT::Logger->error("Unable to load referenced transaction object "
- . "for transaction " . $txn->Id);
+ if ( not $cf_value->Id ) {
+ RT::Logger->error( "Unable to load referenced transaction object "
+ . "for transaction "
+ . $txn->Id );
return 0;
}
- foreach my $value ( @current_values ){
+ foreach my $value (@current_values) {
+
# Already have it
return 1 if $cf_value->Content eq $value;
}
@@ -71,14 +75,14 @@ sub Commit {
# after 4.0 support drops.
sub NewReferenceObject {
- my $self = shift;
- my $txn = shift;
- my $type = $txn->__Value("ReferenceType");
- my $id = $txn->__Value("NewReference");
+ my $self = shift;
+ my $txn = shift;
+ my $type = $txn->__Value("ReferenceType");
+ my $id = $txn->__Value("NewReference");
return unless $type and $id;
- my $object = $type->new($self->CurrentUser);
- $object->Load( $id );
+ my $object = $type->new( $self->CurrentUser );
+ $object->Load($id);
return $object;
}
commit f5f675531064ac1381e52ebf9e67e240540d80d0
Author: Alex Vandiver <alex at chmrr.net>
Date: Wed Jul 13 00:51:56 2016 -0700
Defer to core's NewReferenceObject
Since the implementation here is purely for backwards compatibility,
defer to the implementation in core in case it improves or changes.
Doing so also makes explicit what to replace
`$self->NewReferenceObject($txn)` with once 4.0 support drops.
diff --git a/lib/RT/Action/AddNewCFValue.pm b/lib/RT/Action/AddNewCFValue.pm
index f6e22b7..41ebe07 100644
--- a/lib/RT/Action/AddNewCFValue.pm
+++ b/lib/RT/Action/AddNewCFValue.pm
@@ -50,8 +50,11 @@ sub Commit {
return 1;
} else {
- # CF update transaction
- my $cf_value = $self->NewReferenceObject($txn);
+ # Defer to core's NewReferenceObject if possible
+ my $cf_value = $txn->can("NewReferenceObject")
+ ? $txn->NewReferenceObject
+ : $self->NewReferenceObject($txn);
+
if ( not $cf_value->Id ) {
RT::Logger->error( "Unable to load referenced transaction object "
. "for transaction "
@@ -71,8 +74,8 @@ sub Commit {
}
}
-# Lifted from later RT for compatibility with RT 4.0. Can be removed
-# after 4.0 support drops.
+# Lifted from RT 4.2's RT::Transaction, for compatibility with RT
+# 4.0. Can be removed after 4.0 support drops.
sub NewReferenceObject {
my $self = shift;
commit 34c9350b2c86381e8bc054b0fb61139090a3d11c
Author: Alex Vandiver <alex at chmrr.net>
Date: Wed Jul 13 00:56:17 2016 -0700
Don't error on CF value removals
When an OCFV is removed, the NewReferenceObject has a null value for
NewReference; as such, ->NewReferenceObject returns undef. Rather
than die when `->id` is called on this, accept this state of affairs
silently; there is nothing to be done on OCFV removal.
diff --git a/lib/RT/Action/AddNewCFValue.pm b/lib/RT/Action/AddNewCFValue.pm
index 41ebe07..291a32f 100644
--- a/lib/RT/Action/AddNewCFValue.pm
+++ b/lib/RT/Action/AddNewCFValue.pm
@@ -55,12 +55,7 @@ sub Commit {
? $txn->NewReferenceObject
: $self->NewReferenceObject($txn);
- if ( not $cf_value->Id ) {
- RT::Logger->error( "Unable to load referenced transaction object "
- . "for transaction "
- . $txn->Id );
- return 0;
- }
+ return 0 unless $cf_value and $cf_value->Id;
foreach my $value (@current_values) {
commit 72a7cbc6ae044ffa1fc583074fce52c15889be88
Author: Alex Vandiver <alex at chmrr.net>
Date: Wed Jul 13 01:49:33 2016 -0700
Factor out custom field loading
diff --git a/lib/RT/Action/AddNewCFValue.pm b/lib/RT/Action/AddNewCFValue.pm
index 291a32f..1d86e13 100644
--- a/lib/RT/Action/AddNewCFValue.pm
+++ b/lib/RT/Action/AddNewCFValue.pm
@@ -5,6 +5,15 @@ use warnings;
use base qw(RT::Action);
+sub CustomField {
+ my $self = shift;
+ my $cf_name = $self->Argument;
+
+ my $cf = $self->TicketObj->LoadCustomFieldByIdentifier($cf_name);
+ RT::Logger->error("Unable to load custom field $cf_name") unless $cf->Id;
+ return $cf;
+}
+
sub Prepare {
return 1;
}
@@ -20,12 +29,9 @@ action when the action is installed.
=cut
sub Commit {
- my $self = shift;
- my $txn = $self->TransactionObj;
- my $cf_name = $self->Argument;
-
- my $cf = $self->TicketObj->LoadCustomFieldByIdentifier($cf_name);
- RT::Logger->error("Unable to load custom field $cf_name") unless $cf->Id;
+ my $self = shift;
+ my $txn = $self->TransactionObj;
+ my $cf = $self->CustomField;
my $values_obj = $cf->Values;
my @current_values;
@@ -37,7 +43,7 @@ sub Commit {
# Can get multiple new values from create, so check them all
my @ticket_values = split /\n/,
- $self->TicketObj->CustomFieldValuesAsString($cf_name);
+ $self->TicketObj->CustomFieldValuesAsString($cf);
foreach my $value (@ticket_values) {
commit f84f3546d4171f7c651b40266058fd9ed3f7a332
Author: Alex Vandiver <alex at chmrr.net>
Date: Wed Jul 13 01:49:42 2016 -0700
Only trigger logic when the correct CF is updated
Previously, updates to _any_ custom field (with any name, on any type
of object) would cause the value to be added to the tags CF.
Use a `Prepare` method to limit to only firing when the right ticket
CF is updated.
diff --git a/lib/RT/Action/AddNewCFValue.pm b/lib/RT/Action/AddNewCFValue.pm
index 1d86e13..bbb2fd6 100644
--- a/lib/RT/Action/AddNewCFValue.pm
+++ b/lib/RT/Action/AddNewCFValue.pm
@@ -15,7 +15,13 @@ sub CustomField {
}
sub Prepare {
- return 1;
+ my $self = shift;
+ my $txn = $self->TransactionObj;
+ my $cf = $self->CustomField;
+
+ return 1 if $txn->Type eq "Create";
+ return 1 if $txn->Type eq "CustomField" and $txn->Field == $cf->id;
+ return 0;
}
=head2 DESCRIPTION
commit d5a17d2ce02eac4ed1106020531edc18080d5b75
Author: Alex Vandiver <alex at chmrr.net>
Date: Wed Jul 13 01:54:49 2016 -0700
Remove the now-unnecessary new ScripCondition
Splitting the condition logic for this into a ScripCondition does two
things: allows reuse of the condition, and potentially allows the
action to be called with a different condition. The latter is
entirely confusing, and the former is odd and orthogonal to the
purpose of this extension.
As the new ScripAction only makes sense with that one condition, and
as of the previous commit it not encodes the entirely of its necessary
logic in `Prepare`, remove the Condition.
diff --git a/etc/initialdata b/etc/initialdata
index 5cbfe5c..5f1e4b2 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -22,29 +22,19 @@ else{
},
);
- at ScripConditions = (
- {
- Name => 'On Custom Field Change', # loc
- Description => 'When a custom field is changed', # loc
- ApplicableTransTypes => 'Create,CustomField',
- ExecModule => 'CustomFieldChanged',
- },
-);
-
@ScripActions = (
-
{
Name => 'Add New CF Value',
Description => 'Add new values to the list of available values for this custom field' ,
- ExecModule => 'AddNewCFValue',
- Argument => 'Tag'
+ ExecModule => 'AddNewCFValue',
+ Argument => 'Tag'
},
);
@Scrips = (
{
Description => 'On Custom Field Change Add New Tag Values',
- ScripCondition => 'On Custom Field Change',
+ ScripCondition => 'On Transaction',
ScripAction => 'Add New CF Value',
Template => 'Blank'
},
commit c924eb23c99ffa232c26d50df0da4d838e70be16
Author: Alex Vandiver <alex at chmrr.net>
Date: Wed Jul 13 02:34:21 2016 -0700
Use cmp_version for version comparison
diff --git a/etc/initialdata b/etc/initialdata
index 5f1e4b2..b69666c 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -1,7 +1,6 @@
my $link_value_to;
-my ($major, $minor, $sub) = split(/\./, $RT::VERSION);
-if ( $minor < 4 ){
+if ( RT::Handle::cmp_version($RT::VERSION, "4.4.0") < 0 ){
# For pre RT 4.4
$link_value_to = '__WebPath__/Search/Results.html?Query=CF.{Tag} = \'__CustomField__\' AND (Status=\'new\' OR Status = \'open\')';
}
commit ee9d3061fa3e603f4276a5ae2c794b9e851a914d
Author: Alex Vandiver <alex at chmrr.net>
Date: Wed Jul 13 02:35:42 2016 -0700
Refactor query generation, and URI escape
diff --git a/etc/initialdata b/etc/initialdata
index b69666c..065292d 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -1,14 +1,16 @@
-my $link_value_to;
+my $status;
if ( RT::Handle::cmp_version($RT::VERSION, "4.4.0") < 0 ){
# For pre RT 4.4
- $link_value_to = '__WebPath__/Search/Results.html?Query=CF.{Tag} = \'__CustomField__\' AND (Status=\'new\' OR Status = \'open\')';
-}
-else{
+ $status = "(Status = 'new' OR Status = 'open')";
+} else {
# RT 4.4 introduced __Active__
- $link_value_to = '__WebPath__/Search/Results.html?Query=CF.{Tag} = \'__CustomField__\' AND (Status=\'__Active__\')';
+ $status = "Status = '__Active__'";
}
+my $query = "CF.{Tag} = '__CustomField__' AND $status";
+RT::Interface::Web::EscapeURI(\$query);
+
@CustomFields = (
{
Name => 'Tag',
@@ -16,7 +18,7 @@ else{
LookupType => 'RT::Queue-RT::Ticket',
Disabled => 0,
Description => 'Tags for tickets',
- LinkValueTo => $link_value_to,
+ LinkValueTo => "__WebPath__/Search/Results.html?Query=$query",
MaxValues => '0',
},
);
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list