summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorngharo <nick@ngha.ro>2017-09-14 16:50:12 -0500
committerngharo <nick@ngha.ro>2017-09-14 16:50:12 -0500
commit78e35fc3ed6575d10fa62efd059744e14bd5ed50 (patch)
tree9ca673591cdb145faf865adb380075ed776888f1
downloadRT::Condition::OnRiskThresholdMet-78e35fc3ed6575d10fa62efd059744e14bd5ed50.tar.xz
RT::Condition::OnRiskThresholdMet-78e35fc3ed6575d10fa62efd059744e14bd5ed50.zip
RT condition for performing action after risk assessmentHEADmaster
-rw-r--r--Condition/OnRiskThresholdMet.pm103
1 files changed, 103 insertions, 0 deletions
diff --git a/Condition/OnRiskThresholdMet.pm b/Condition/OnRiskThresholdMet.pm
new file mode 100644
index 0000000..b7ec54b
--- /dev/null
+++ b/Condition/OnRiskThresholdMet.pm
@@ -0,0 +1,103 @@
+package RT::Condition::OnRiskThresholdMet;
+
+use strict;
+use warnings;
+use base 'RT::Condition';
+
+sub getRiskValue {
+ my $cfname = shift;
+ my $cfvalue = shift;
+ my $retval = 1;
+
+ my $cfs = RT::CustomField->new(RT->SystemUser);
+ $cfs->Load($cfname);
+ my $cfvs = $cfs->Values();
+
+ $RT::Logger->info("Getting risk value for '$cfname/$cfvalue'");
+ while ( my $valuerow = $cfvs->Next ) {
+ if ($valuerow->Name eq $cfvalue && $cfvalue ne "") {
+ $retval = int($valuerow->SortOrder);
+ last;
+ }
+ }
+
+ return $retval;
+}
+
+sub IsApplicable {
+ my $self = shift;
+ my $txn = $self->TransactionObj;
+ my $type = $txn->Type;
+ my @risks = ('Risk Probability', 'Risk Severity');
+ my @names = ('Risk Probability', 'Risk Severity', 'Reportable Event');
+ my $risk = 1;
+ my $capaQueue = 22;
+
+ if ( $self->TicketObj->Queue == $capaQueue ) {
+ # Skip CAPA queue events
+ return(undef);
+
+ } elsif ( $type eq 'Create' ) {
+ return(undef) unless $self->TicketObj->FirstCustomFieldValue('Reportable Event') eq 'No';
+
+ } elsif ( $self->TicketObj->DependsOn and ( $type eq 'Create' or $type eq 'CustomField' ) ) {
+ # Check if ticket already has a dependant CAPA ticket
+ while ( my $dependant = $self->TicketObj->DependsOn->Next ) {
+ my $depTicket = new RT::Ticket($RT::SystemUser);
+ $depTicket->Load($dependant->LocalTarget);
+ if( $depTicket->Subject =~ /CAPA Assessment/ ) {
+ # $RT::Logger->info("CAPA Assessment ticket already created, aborting");
+ return(undef);
+ }
+ }
+
+ } elsif ( $type eq 'CustomField' ) {
+ # This condition is set when any custom field is changed
+ my $cf = RT::CustomField->new( $self->CurrentUser );
+ $cf->Load( $txn->Field );
+
+ # Bail out if the transaction didn't affect any of our target custom fields
+ return(undef) unless $cf->Name eq 'Risk Probability' or
+ $cf->Name eq 'Risk Severity' or
+ $cf->Name eq 'Reportable Event';
+
+ # $RT::Logger->info("txn: " . $cf->Name . ", " . $txn->OldValue . " -> " . $txn->NewValue);
+
+ # Return true immediately if reportable event set to Yes
+ return(1) if $cf->Name eq 'Reportable Event' and $txn->NewValue eq 'Yes';
+
+ } else {
+ $RT::Logger->info("Not a valid transaction type for this condition");
+ return(undef);
+ }
+
+ $RT::Logger->info("Condition 'On Risk Threshold Met' triggered "
+ ."for ticket #". $self->TicketObj->id
+ ." transaction #". $txn->id
+ );
+
+ # Now iterate through our targets and calculate risk
+ foreach my $riskname (@risks) {
+ my $cfvalue = $self->TicketObj->FirstCustomFieldValue($riskname);
+ my $riskval = 1;
+ if(! $cfvalue || $cfvalue eq '') {
+ # Check if risks are filled out, bail if one is empty
+ $RT::Logger->info($riskname . " is empty");
+ return(undef);
+ } else {
+ # Calc Risk
+ $risk = $risk * getRiskValue($riskname, $cfvalue);
+ }
+ }
+
+ $RT::Logger->info("Calculated risk is: " . $risk);
+ if ($risk >= 3) {
+ return(1);
+ } else {
+ return(undef);
+ }
+
+ return(undef);
+}
+
+1;