[Rt-commit] rtir branch 5.0/callbacks-for-mandatory-on-transition created. 5.0.1-21-g2ce895bc

BPS Git Server git at git.bestpractical.com
Tue Nov 2 14:59:21 UTC 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rtir".

The branch, 5.0/callbacks-for-mandatory-on-transition has been created
        at  2ce895bcf003556a962bdbc16c4f83cf6c908431 (commit)

- Log -----------------------------------------------------------------
commit 2ce895bcf003556a962bdbc16c4f83cf6c908431
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Oct 29 01:37:51 2021 +0800

    Add necessary callbacks for MandatoryOnTransition

diff --git a/html/RTIR/Display.html b/html/RTIR/Display.html
index ad4b7a26..e09bfb32 100644
--- a/html/RTIR/Display.html
+++ b/html/RTIR/Display.html
@@ -379,55 +379,66 @@ RT::Interface::Web::Redirect(RT::IR->HREFTo("$Type/Display.html?".$m->comp('/Ele
 }
 
 my @results;
+my $SkipProcessing;
+
 if ( $id eq 'new' ) {
     unless ($QueueObj->CurrentUserHasRight('CreateTicket')) {
         Abort('You have no permission to create tickets in that queue.');
     }
     ($Ticket, @results) = CreateTicket( %ARGS );
 } elsif( $id ) {
-    
     $m->callback(
-        CallbackName => 'ProcessArguments', 
-        Ticket => $Ticket,
-        ARGSRef => \%ARGS,  
-        Actions => \@results,
+        CallbackName   => 'BeforeProcessArguments',
+        CallbackPage   => '/Ticket/Display.html',
+        TicketObj      => $Ticket,
+        ActionsRef     => \@results,
+        ARGSRef        => \%ARGS,
+        SkipProcessing => \$SkipProcessing,
     );
-
-    if ( $ARGS{'Action'} && $ARGS{'Action'} =~ /^(Steal|Kill|Take|SetTold)$/ ) {
-        my $action = $1;
-        my ($status, $msg) = $Ticket->$action();
-        push @results, $msg;
-        # If they succeeded in taking the ticket, they should also get a lock
-        if ($status && $action =~  /^(?:Take|Steal)$/) {
-            $m->callback(CallbackName => 'TicketTakeOrSteal', %ARGS, Ticket => $Ticket, Type => $Type, Results => \@results);
+    if ( !$SkipProcessing) {
+        $m->callback(
+            CallbackName => 'ProcessArguments',
+            Ticket => $Ticket,
+            ARGSRef => \%ARGS,
+            Actions => \@results,
+        );
+
+        if ( $ARGS{'Action'} && $ARGS{'Action'} =~ /^(Steal|Kill|Take|SetTold)$/ ) {
+            my $action = $1;
+            my ($status, $msg) = $Ticket->$action();
+            push @results, $msg;
+            # If they succeeded in taking the ticket, they should also get a lock
+            if ($status && $action =~  /^(?:Take|Steal)$/) {
+                $m->callback(CallbackName => 'TicketTakeOrSteal', %ARGS, Ticket => $Ticket, Type => $Type, Results => \@results);
+            }
         }
-    }
 
-    if ( $ARGS{'TakeOrStealFirst'} and $Ticket->Owner != $Ticket->CurrentUser->Id) {
-        my ($status, $msg) = $Ticket->SetOwner($Ticket->CurrentUser->Id, 'Force');
-        push @results, $msg if $msg;
-        
-        # If they succeeded in taking the ticket, they should also get a lock
-        ## Should they? This should only happen when a ticket is rejected, do we want to lock it?
-        if ($status) { 
-            $m->callback(CallbackName => 'TicketTakeOrSteal', %ARGS, Ticket => $Ticket, Type => $Type, Results => \@results); 
+        if ( $ARGS{'TakeOrStealFirst'} and $Ticket->Owner != $Ticket->CurrentUser->Id) {
+            my ($status, $msg) = $Ticket->SetOwner($Ticket->CurrentUser->Id, 'Force');
+            push @results, $msg if $msg;
+
+            # If they succeeded in taking the ticket, they should also get a lock
+            ## Should they? This should only happen when a ticket is rejected, do we want to lock it?
+            if ($status) {
+                $m->callback(CallbackName => 'TicketTakeOrSteal', %ARGS, Ticket => $Ticket, Type => $Type, Results => \@results); 
+            }
         }
-    }
 
-    push @results, ProcessUpdateMessage( TicketObj => $Ticket, ARGSRef => \%ARGS, Actions => \@results );
+        push @results, ProcessUpdateMessage( TicketObj => $Ticket, ARGSRef => \%ARGS, Actions => \@results );
 
-    push @results, ProcessTicketBasics(  TicketObj => $Ticket, ARGSRef => \%ARGS );
-    push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $Ticket );
-    push @results, ProcessTicketWatchers( ARGSRef => \%ARGS, TicketObj => $Ticket );
+        push @results, ProcessTicketBasics(  TicketObj => $Ticket, ARGSRef => \%ARGS );
+        push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $Ticket );
+        push @results, ProcessTicketWatchers( ARGSRef => \%ARGS, TicketObj => $Ticket );
 
-    my $strict_acl = RT->Config->Set( StrictLinkACL => 0 );
-    push @results, ProcessTicketLinks(   TicketObj => $Ticket, ARGSRef => \%ARGS );
-    RT->Config->Set( StrictLinkACL => $strict_acl );
+        my $strict_acl = RT->Config->Set( StrictLinkACL => 0 );
+        push @results, ProcessTicketLinks(   TicketObj => $Ticket, ARGSRef => \%ARGS );
+        RT->Config->Set( StrictLinkACL => $strict_acl );
 
-    push @results, ProcessTicketDates(   TicketObj => $Ticket, ARGSRef => \%ARGS );
+        push @results, ProcessTicketDates(   TicketObj => $Ticket, ARGSRef => \%ARGS );
+    }
 }
 
-if ( $ARGS{'BulkArticles'} && @SelectedTickets ) {
+if ( !$SkipProcessing && !$ARGS{'BulkArticles'} && @SelectedTickets ) {
     my $ref = join " ", map "a:$_", @SelectedTickets;
     push @results, ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => {$Ticket->Id."-RefersTo" => $ref} );
 }
diff --git a/html/RTIR/Edit.html b/html/RTIR/Edit.html
index 0f7d1e0a..4c8e5324 100644
--- a/html/RTIR/Edit.html
+++ b/html/RTIR/Edit.html
@@ -223,6 +223,17 @@ RT::Interface::Web::Redirect(RT::IR->HREFTo("$Type/Edit.html?"
 my @results;
 my $checks_failure = 0;
 
+my $skip_update = 0;
+my $CustomFields = $Ticket->CustomFields;
+$m->callback(
+    CallbackPage => '/Ticket/Modify.html',
+    TicketObj    => $Ticket,
+    CustomFields => $CustomFields,
+    ARGSRef      => \%ARGS,
+    skip_update  => \$skip_update,
+    results      => \@results,
+);
+
 if ( $SaveChanges ) {
     my $status = $m->comp('/Elements/ValidateCustomFields',
         CustomFields => $Ticket->QueueObj->TicketCustomFields,
@@ -244,7 +255,7 @@ if ( $SaveChanges ) {
 }
 
 # XXX: process even if checks failed as EditPeople doesn't preserve state
-if ( $SaveChanges && !$OnlySearchForPeople ) {
+if ( $SaveChanges && !$skip_update && !$OnlySearchForPeople ) {
 
     # XXX: ProcessTicketWatchers doesn't like WatcherTypeEmailX with
     # empty WatcherAddressEmailX
@@ -256,7 +267,7 @@ if ( $SaveChanges && !$OnlySearchForPeople ) {
     push @results, ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
 }
 
-if ( $SaveChanges && !$checks_failure && !$OnlySearchForPeople ) {
+if ( $SaveChanges && !$skip_update && !$checks_failure && !$OnlySearchForPeople ) {
     my $strict_acl = RT->Config->Set( StrictLinkACL => 0 );
     push @results, ProcessTicketLinks(    TicketObj => $Ticket, ARGSRef => \%ARGS );
     RT->Config->Set( StrictLinkACL => $strict_acl );
diff --git a/html/RTIR/Incident/Create.html b/html/RTIR/Incident/Create.html
index b2962466..6e961f0e 100644
--- a/html/RTIR/Incident/Create.html
+++ b/html/RTIR/Incident/Create.html
@@ -517,7 +517,17 @@ if ( $CreateWithInvestigation && !$InvestigationRequestors ) {
 $m->callback( CallbackName => 'BeforeCreateRedirect', ARGSRef => \%ARGS,
     Child => $ChildObj, results => \@results, checks_failure => \$checks_failure );
 
-if ( !$checks_failure && $CreateIncident ) {
+my $skip_create;
+$m->callback(
+    CallbackName   => 'BeforeCreate',
+    CallbackPage   => '/Ticket/Create.html',
+    ARGSRef        => \%ARGS,
+    results        => \@results,
+    skip_create    => \$skip_create,
+    checks_failure => $checks_failure,
+);
+
+if ( !$skip_create && !$checks_failure && $CreateIncident ) {
     my ($inc_obj, @tmp) = $m->comp(
         '/RTIR/Investigation/Elements/Create:Process',
         %ARGS,
diff --git a/html/RTIR/Incident/Display.html b/html/RTIR/Incident/Display.html
index 6e192d6c..481967fc 100644
--- a/html/RTIR/Incident/Display.html
+++ b/html/RTIR/Incident/Display.html
@@ -403,6 +403,7 @@ my $DoLinks = sub {
 };
 
 my @results;
+my $SkipProcessing;
 
 my $TicketObj;
 my $new_ticket = 0;
@@ -416,6 +417,14 @@ if ( $id eq 'new' ) {
     $new_ticket = 1;
 } else {
     $TicketObj = LoadTicket( $id );
+    $m->callback(
+        CallbackName   => 'BeforeProcessArguments',
+        CallbackPage   => '/Ticket/Display.html',
+        TicketObj      => $TicketObj,
+        ActionsRef     => \@results,
+        ARGSRef        => \%ARGS,
+        SkipProcessing => \$SkipProcessing,
+    );
 }
 
 my $edit_label   = $m->interp->apply_escapes( loc("Edit"), 'h' );
@@ -438,7 +447,7 @@ unless( RT::IR->IsIncidentQueue($TicketObj->QueueObj) ) {
 }
 $ARGS{'id'} = $id = $TicketObj->Id;
 
-if ( $ARGS{'Action'} && $ARGS{'Action'} =~ /^(Steal|Kill|Take|SetTold)$/ )
+if ( !$SkipProcessing && $ARGS{'Action'} && $ARGS{'Action'} =~ /^(Steal|Kill|Take|SetTold)$/ )
 {   
     my $action = $1;
     my ($res, $msg) = $TicketObj->$action();
@@ -450,13 +459,13 @@ if ( $ARGS{'Action'} && $ARGS{'Action'} =~ /^(Steal|Kill|Take|SetTold)$/ )
 
 
 
-unless( $new_ticket ) {
+unless( $new_ticket || $SkipProcessing ) {
     push @results, ProcessTicketBasics( ARGSRef => \%ARGS, TicketObj => $TicketObj );
     push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS, Object => $TicketObj );
     push @results, ProcessTicketDates( ARGSRef => \%ARGS, TicketObj => $TicketObj );
 }
 
-if ( $ARGS{'BulkLink'} || $Child ) {
+if ( !$SkipProcessing && ( $ARGS{'BulkLink'} || $Child ) ) {
     my @link;
     push @link, @SelectedTickets if $ARGS{'BulkLink'};
     push @link, $Child if $Child;
@@ -476,7 +485,7 @@ if ( $deleted_links && !RT::IR->IncidentChildren( $TicketObj )->Count ) {
     push @results, loc("WARNING: Incident [_1] has no children.", $id);
 }
 
-if ( $ARGS{'BulkArticles'} && @SelectedTickets ) {
+if ( !$SkipProcessing && $ARGS{'BulkArticles'} && @SelectedTickets ) {
     my $ref = join " ", map "a:$_", @SelectedTickets;
     push @results, ProcessTicketLinks(
         TicketObj => $TicketObj,
@@ -484,7 +493,7 @@ if ( $ARGS{'BulkArticles'} && @SelectedTickets ) {
     );
 }
 
-unless( $new_ticket ) {
+unless( $new_ticket || $SkipProcessing ) {
     push @results, ProcessUpdateMessage( ARGSRef => \%ARGS, TicketObj => $TicketObj, Actions => \@results );
 }
 
diff --git a/html/RTIR/Incident/Elements/ReplyForm b/html/RTIR/Incident/Elements/ReplyForm
index 109139f5..6f98a136 100644
--- a/html/RTIR/Incident/Elements/ReplyForm
+++ b/html/RTIR/Incident/Elements/ReplyForm
@@ -113,6 +113,8 @@
   </div>
 </div>
 
+% $m->callback( %ARGS, CallbackName => 'AfterWorked', Ticket => $TicketObj );
+
 <& /RTIR/Elements/UpdateData, %ARGS, Ticket => $TicketObj, QueueObj => $QueueObj, Action => $Action &>
 
 </&>
diff --git a/html/RTIR/Incident/Reply/index.html b/html/RTIR/Incident/Reply/index.html
index fe1288cc..8edfd11c 100644
--- a/html/RTIR/Incident/Reply/index.html
+++ b/html/RTIR/Incident/Reply/index.html
@@ -164,6 +164,18 @@ $m->callback(
     Ticket         => $IncidentObj
 );
 
+# RTIR passes Status instead of DefaultStatus, so it's probably better to
+# not simply reuse the callback in /Ticket/Update.html.
+my $skip_update = 0;
+$m->callback(
+    CallbackName   => 'BeforeUpdate',
+    ARGSRef        => \%ARGS,
+    skip_update    => \$skip_update,
+    checks_failure => $checks_failure,
+    results        => \@results,
+    TicketObj      => $IncidentObj,
+);
+
 my $gnupg_widget = $m->comp('/Elements/Crypt/SignEncryptWidget:new', Arguments => \%ARGS );
 $m->comp( '/Elements/Crypt/SignEncryptWidget:Process',
     self => $gnupg_widget,
@@ -191,7 +203,7 @@ if ( $SubmitTicket && $gnupg_widget ) {
     }
 }
 
-if ( $SubmitTicket && !$checks_failure ) {
+if ( $SubmitTicket && !$skip_update && !$checks_failure ) {
 
     my $incident_cycle = $IncidentObj->QueueObj->LifecycleObj;
     foreach my $Ticket ( @selected_children ) {
diff --git a/html/RTIR/Update.html b/html/RTIR/Update.html
index 5e2a399e..0f403af5 100644
--- a/html/RTIR/Update.html
+++ b/html/RTIR/Update.html
@@ -118,6 +118,7 @@
 &>
 
 % $m->callback( %ARGS, CallbackName => 'AfterWorked', Ticket => $Ticket );
+% $m->callback( %ARGS, CallbackName => 'AfterWorked', Ticket => $Ticket, CallbackPage => '/Ticket/Update.html' );
 
 <& /Ticket/Elements/EditTransactionCustomFields,
     %ARGS, TicketObj => $Ticket, InTable => 1,
@@ -255,7 +256,19 @@ if ( !$checks_failure && $SubmitTicket ) {
     $ARGS{'SquelchMailTo'} = \@squelchlist if @squelchlist;
 }
 
-if ( !$checks_failure && $SubmitTicket ) {
+# RTIR passes Status instead of DefaultStatus, so it's probably better to
+# not simply reuse the callback in /Ticket/Update.html.
+my $skip_update = 0;
+$m->callback(
+    CallbackName   => 'BeforeUpdate',
+    ARGSRef        => \%ARGS,
+    skip_update    => \$skip_update,
+    checks_failure => $checks_failure,
+    results        => \@results,
+    TicketObj      => $Ticket,
+);
+
+if ( !$skip_update && !$checks_failure && $SubmitTicket ) {
     $m->callback(CallbackName => 'BeforeDisplay', ARGSRef => \%ARGS, Ticket => $Ticket);
 
     # Use the custom display page for this type if it exists

-----------------------------------------------------------------------


hooks/post-receive
-- 
rtir


More information about the rt-commit mailing list