StatusChangeWithDependents: Initial condition.

This commit is contained in:
Brett Smith 2018-04-19 09:50:38 -04:00
parent 83243abf2c
commit 3f58ff316d
3 changed files with 69 additions and 1 deletions

28
etc/upgrade/0.3/content Normal file
View file

@ -0,0 +1,28 @@
#!/usr/bin/env perl
@ScripConditions = (
{ Name => 'On Close With Dependents',
Description => 'Whenever a ticket is closed and other tickets depend on it',
ApplicableTransTypes => 'Status',
ExecModule => 'StatusChangeWithDependents',
Argument => 'dependents > 0; old: initial, active; new: inactive',
},
{ Name => 'On Close Without Dependents',
Description => 'Whenever a ticket is closed and no other tickets depend on it',
ApplicableTransTypes => 'Status',
ExecModule => 'StatusChangeWithDependents',
Argument => 'dependents == 0; old: initial, active; new: inactive',
},
{ Name => 'On Approved With Dependents',
Description => 'Whenever a ticket is an approval and other tickets depend on it',
ApplicableTransTypes => 'Status',
ExecModule => 'StatusChangeWithDependents',
Argument => 'dependents > 0; new: approved',
},
{ Name => 'On Approved Without Dependents',
Description => 'Whenever a ticket is an approval and no other tickets depend on it',
ApplicableTransTypes => 'Status',
ExecModule => 'StatusChangeWithDependents',
Argument => 'dependents == 0; new: approved',
},
);

View file

@ -0,0 +1,34 @@
package RT::Condition::StatusChangeWithDependents;
use strict;
use warnings;
use base qw(RT::Condition::StatusChange);
sub Argument {
# Take the dependents setting out of the argument, so StatusChange gets
# everything else.
my $self = shift;
$self->SUPER::Argument =~ s/^\s*dependents\s*(<|>|[=!<>]=)\s*(\d+)\s*;?//r;
}
sub IsApplicable {
my $self = shift;
my $argument = $self->SUPER::Argument;
my ($op, $operand);
if ($argument =~ /^\s*dependents\s*(<|>|[=!<>]=)\s*(\d+)\s*;?/) {
$op = $1;
$operand = $2;
} else {
$RT::Logger->error("Argument '$argument' is incorrect");
return 0;
}
return 0 unless $self->SUPER::IsApplicable;
my $dep_count = $self->TicketObj->DependedOnBy->Count;
return 0 unless (eval "\$dep_count $op $operand;");
return 1;
}
RT::Base->_ImportOverlays();
1;

View file

@ -2,7 +2,7 @@ use strict;
use warnings;
package RT::Extension::Conservancy;
our $VERSION = '0.2';
our $VERSION = '0.3';
=pod
@ -18,6 +18,12 @@ A Scrip action that sends notice to the ticket owner if that's set, or queue
AdminCCs if not. Ticket AdminCCs always get the notice too, which is how
this is different from the built-in "Notify Owner or AdminCCs".
=head3 RT::Condition::StatusChangeWithDependents
A Scrip condition that extends RT::Condition::StatusChange. The affected
ticket must have a configured number of other tickets that Depend On it for
this condition to be true.
=head3 RT::Interface::Email::OneTicketPerRequestor
A mail plugin that examines incoming mail to see if it would create a new