[Bps-public-commit] RT-Extension-MandatoryOnTransition branch, master, updated. 0.13-5-gcdef157
Dustin Graves
dustin at bestpractical.com
Tue Sep 20 13:01:53 EDT 2016
The branch, master has been updated
via cdef1578aab9e6a58514f5faaee2160a0967a66a (commit)
via 4a9e8030cf8716158387dfd128c17420ccb4575f (commit)
from 465c04528f2d2944d5c746b22223c2bfc524a07a (commit)
Summary of changes:
README | 23 +++-
lib/RT/Extension/MandatoryOnTransition.pm | 195 ++++++++++++++++++++++++++----
2 files changed, 189 insertions(+), 29 deletions(-)
- Log -----------------------------------------------------------------
commit 4a9e8030cf8716158387dfd128c17420ccb4575f
Author: Dustin Graves <dustin at bestpractical.com>
Date: Fri Sep 2 18:49:06 2016 +0000
add functionality for queue transitions
diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index ab0337f..c3694ca 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -309,6 +309,65 @@ sub RequiredFields {
return (\@core, \@cfs, \%cf_must_values);
}
+sub QueueRequiredFields {
+ my $self = shift;
+ my %args = (
+ Ticket => undef,
+ To => undef,
+ @_,
+ );
+
+ my ($from, $to);
+ $from = $args{Ticket}->QueueObj->Name;
+
+ my $to_obj = RT::Queue->new( $args{Ticket}->CurrentUser );
+ $to_obj->Load( $args{To} );
+ return ([], []) unless $to_obj->id;
+ $to = $to_obj->Name;
+
+ return ([], []) unless $from and $to;
+
+ my %config = $self->QueueConfig;
+ return ([], []) unless %config;
+
+ # No transition.
+ return ([], []) if $from eq $to;
+
+ my $required = $config{"$from -> $to"}
+ || $config{"* -> $to"}
+ || $config{"$from -> *"}
+ || [];
+
+ my %core_supported = map { $_ => 1 } @CORE_SUPPORTED;
+
+ my @core = grep { !/^CF\./i && $core_supported{$_} } @$required;
+ my @cfs = map { /^CF\.(.+)$/i; $1; }
+ grep { /^CF\./i } @$required;
+
+ # Pull out any must_be or must_not_be rules
+ my %cf_must_values = ();
+ foreach my $cf (@cfs){
+ if ( $config{"CF.$cf"} ){
+ my $transition = $config{"CF.$cf"}->{'transition'};
+ unless ( $transition ){
+ RT->Logger->error("No transition defined in must_be or must_not_be rules for $cf");
+ next;
+ }
+
+ if ( $transition eq "$from -> $to"
+ || $transition eq "* -> $to"
+ || $transition eq "$from -> *" ) {
+
+ $cf_must_values{$cf} = $config{"CF.$cf"};
+ }
+ }
+ }
+
+ return (\@core, \@cfs, \%cf_must_values);
+}
+
+
+
=head3 CheckMandatoryFields
Pulls core and custom mandatory fields from the configuration and
@@ -341,7 +400,86 @@ sub CheckMandatoryFields {
To => undef,
@_,
);
- my $ARGSRef = $args{'ARGSRef'};
+
+ my $ARGSRef = $args{ARGSRef};
+
+ my @errors;
+ my $CurrentUser;
+
+ unless ( $args{Ticket} || $args{Queue} ) {
+ $RT::Logger->error("CheckMandatoryFields requires a Ticket object or a Queue object");
+ return \@errors;
+ }
+
+ $CurrentUser = $args{Ticket} ? $args{Ticket}->CurrentUser : $args{Queue}->CurrentUser;
+
+ # Check queue change fields if changing queue
+ my $new_queue = $ARGSRef->{Queue};
+ if ( $new_queue && $args{Ticket} && $args{Ticket}->Queue != $new_queue ) {
+ my ($core, $cfs, $must_values) = $self->QueueRequiredFields(
+ Ticket => $args{'Ticket'},
+ To => $args{ARGSRef}->{Queue},
+ );
+
+ if ( @$core && @$cfs ) {
+ my $new_queue_obj = RT::Queue->new( $CurrentUser );
+ $new_queue_obj->Load( $new_queue );
+ push @errors, @{ $self->_CheckMandatoryFields(
+ %args,
+ TransitionType => $CurrentUser->loc('Queue'),
+ NewValue => $new_queue_obj->Name,
+ CoreFields => $core,
+ CustomFields => $cfs,
+ MustValues => $must_values,
+ ) };
+ }
+ }
+
+ # Check standard status change fields
+ my ($core, $cfs, $must_values) = $self->RequiredFields(
+ Ticket => $args{'Ticket'},
+ Queue => $args{'Queue'} ? $args{'Queue'}->Name : undef,
+ From => $args{'From'},
+ To => $args{'To'},
+ );
+
+ if ( @$core && @$cfs ) {
+ push @errors, @{ $self->_CheckMandatoryFields(
+ %args,
+ TransitionType => $CurrentUser->loc('Status'),
+ NewValue => $CurrentUser->loc($ARGSRef->{Status}),
+ CoreFields => $core,
+ CustomFields => $cfs,
+ MustValues => $must_values,
+ ) };
+ }
+
+ return \@errors;
+}
+
+sub _CheckMandatoryFields {
+ my $self = shift;
+
+ my %args = (
+ TransitionType => undef,
+ NewValue => undef,
+ CoreFields => undef,
+ CustomFields => undef,
+ MustValues => undef,
+ @_,
+ );
+
+ my $ARGSRef = $args{ARGSRef};
+
+ # Convenience varialbes
+ my ( $type, $new_value, $core, $cfs, $must_values ) = (
+ $args{TransitionType},
+ $args{NewValue},
+ $args{CoreFields},
+ $args{CustomFields},
+ $args{MustValues},
+ );
+
my @errors;
# Some convenience variables set depending on what gets passed
@@ -359,15 +497,6 @@ sub CheckMandatoryFields {
return \@errors;
}
- my ($core, $cfs, $must_values) = $self->RequiredFields(
- Ticket => $args{'Ticket'},
- Queue => $args{'Queue'} ? $args{'Queue'}->Name : undef,
- From => $args{'From'},
- To => $args{'To'},
- );
-
- return \@errors unless @$core or @$cfs;
-
# Check core fields, after canonicalization for update
for my $field (@$core) {
@@ -385,8 +514,8 @@ sub CheckMandatoryFields {
(my $label = $field) =~ s/(?<=[a-z])(?=[A-Z])/ /g; # /
push @errors,
- $CurrentUser->loc("[_1] is required when changing Status to [_2]",
- $label, $CurrentUser->loc($ARGSRef->{Status}));
+ $CurrentUser->loc("[_1] is required when changing [_2] to [_3]",
+ $label, $CurrentUser->loc($type), $new_value);
}
return \@errors unless @$cfs;
@@ -452,13 +581,13 @@ sub CheckMandatoryFields {
my $valid_values = join ", ", @must_be;
if ( @must_be > 1 ){
push @errors,
- $CurrentUser->loc("[_1] must be one of: [_3] when changing Status to [_2]",
- $cf->Name, $CurrentUser->loc($ARGSRef->{Status}), $valid_values);
+ $CurrentUser->loc("[_1] must be one of: [_2] when changing [_3] to [_4]",
+ $cf->Name, $valid_values, $type, $new_value);
}
else{
push @errors,
- $CurrentUser->loc("[_1] must be [_3] when changing Status to [_2]",
- $cf->Name, $CurrentUser->loc($ARGSRef->{Status}), $valid_values);
+ $CurrentUser->loc("[_1] must be [_2] when changing [_3] to [_4]",
+ $cf->Name, $valid_values, $type, $new_value);
}
next;
}
@@ -471,13 +600,13 @@ sub CheckMandatoryFields {
my $valid_values = join ", ", @must_not_be;
if ( @must_not_be > 1 ){
push @errors,
- $CurrentUser->loc("[_1] must not be one of: [_3] when changing Status to [_2]",
- $cf->Name, $CurrentUser->loc($ARGSRef->{Status}), $valid_values);
+ $CurrentUser->loc("[_1] must not be one of: [_2] when changing [_3] to [_4]",
+ $cf->Name, $valid_values, $type, $new_value);
}
else{
push @errors,
- $CurrentUser->loc("[_1] must not be [_3] when changing Status to [_2]",
- $cf->Name, $CurrentUser->loc($ARGSRef->{Status}), $valid_values);
+ $CurrentUser->loc("[_1] must not be [_2] when changing [_3] to [_4]",
+ $cf->Name, $valid_values, $type, $new_value);
}
next;
}
@@ -491,8 +620,8 @@ sub CheckMandatoryFields {
next if $args{'Ticket'} && $cf->ValuesForObject($args{'Ticket'})->Count;
push @errors,
- $CurrentUser->loc("[_1] is required when changing Status to [_2]",
- $cf->Name, $CurrentUser->loc($ARGSRef->{Status}));
+ $CurrentUser->loc("[_1] is required when changing [_2] to [_3]",
+ $cf->Name, $type, $new_value);
}
return \@errors;
@@ -517,6 +646,12 @@ sub Config {
return;
}
+sub QueueConfig {
+ my $self = shift;
+ my %config = RT->Config->Get('MandatoryOnQueueTransition');
+ return %config;
+}
+
=head1 TODO
=over 4
commit cdef1578aab9e6a58514f5faaee2160a0967a66a
Author: Dustin Graves <dustin at bestpractical.com>
Date: Mon Sep 12 23:47:10 2016 +0000
update documentation for queue transitions
diff --git a/README b/README
index 1e47690..1ffcace 100644
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
NAME
RT-Extension-MandatoryOnTransition - Require core fields and ticket
- custom fields on status transitions
+ custom fields on status and/or queue transitions
RT VERSION
Works with RT 4.0, 4.2, 4.4
@@ -9,10 +9,11 @@ RT VERSION
DESCRIPTION
This RT extension enforces that certain fields have values before
- tickets are explicitly moved to or from specified statuses. If you list
- custom fields which must have a value before a ticket is resolved, those
- custom fields will automatically show up on the "Resolve" page. The
- reply/comment won't be allowed until a value is provided.
+ tickets are explicitly moved to or from specified statuses and/or
+ queues. If you list custom fields which must have a value before a
+ ticket is resolved, those custom fields will automatically show up on
+ the "Resolve" page. The reply/comment won't be allowed until a value is
+ provided.
See the configuration example under "INSTALLATION".
@@ -97,6 +98,18 @@ CONFIGURATION
The fallback for queues without specific rules is specified with '*'
where the queue name would normally be.
+ To define mandatory fields for queues is quite similar, however you
+ don't need settings per queue as above. To do this you use the
+ %MandatoryOnQueueTransition config option. This ends up looking like:
+
+ Set( %MandatoryOnQueueTransition,
+ 'from -> to' => [ 'BasicField', 'CF.MyField', ],
+ );
+
+ In this case, from and to are expected to be valid queue names. As
+ above, from may also be *. All following must_be and must_not_be
+ features work with queues as well.
+
Requiring Any Value
Below is an example which requires 1) time worked and filling in a
custom field named Resolution before resolving tickets in the Helpdesk
diff --git a/lib/RT/Extension/MandatoryOnTransition.pm b/lib/RT/Extension/MandatoryOnTransition.pm
index c3694ca..4a2ecac 100644
--- a/lib/RT/Extension/MandatoryOnTransition.pm
+++ b/lib/RT/Extension/MandatoryOnTransition.pm
@@ -6,7 +6,7 @@ our $VERSION = '0.13';
=head1 NAME
-RT-Extension-MandatoryOnTransition - Require core fields and ticket custom fields on status transitions
+RT-Extension-MandatoryOnTransition - Require core fields and ticket custom fields on status and/or queue transitions
=head1 RT VERSION
@@ -17,7 +17,7 @@ See below for some restrictions on RT 4.0.
=head1 DESCRIPTION
This RT extension enforces that certain fields have values before tickets are
-explicitly moved to or from specified statuses. If you list custom fields
+explicitly moved to or from specified statuses and/or queues. If you list custom fields
which must have a value before a ticket is resolved, those custom fields will
automatically show up on the "Resolve" page. The reply/comment won't be
allowed until a value is provided.
@@ -125,6 +125,18 @@ status C<to>.
The fallback for queues without specific rules is specified with C<'*'> where
the queue name would normally be.
+To define mandatory fields for queues is quite similar, however you don't need
+settings per queue as above. To do this you use the
+C<%MandatoryOnQueueTransition> config option. This ends up looking like:
+
+ Set( %MandatoryOnQueueTransition,
+ 'from -> to' => [ 'BasicField', 'CF.MyField', ],
+ );
+
+In this case, C<from> and C<to> are expected to be valid queue names. As
+above, C<from> may also be C<*>. All following must_be and must_not_be features
+work with queues as well.
+
=head2 Requiring Any Value
Below is an example which requires 1) time worked and filling in a custom field
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list