[Bps-public-commit] rt-extension-rest2 branch, add-validation-hook-for-status-updates, created. 1.09-6-g5da34d5

Dianne Skoll dianne at bestpractical.com
Wed Dec 9 09:42:34 EST 2020


The branch, add-validation-hook-for-status-updates has been created
        at  5da34d5f16f6f9ebb362bf02447d129bd2ecf879 (commit)

- Log -----------------------------------------------------------------
commit 5da34d5f16f6f9ebb362bf02447d129bd2ecf879
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Tue Dec 8 15:49:35 2020 -0500

    Stub out validation hooks for ticket creation and ticket update.

diff --git a/lib/RT/Extension/REST2/Resource/Message.pm b/lib/RT/Extension/REST2/Resource/Message.pm
index 9b05b00..38de40c 100644
--- a/lib/RT/Extension/REST2/Resource/Message.pm
+++ b/lib/RT/Extension/REST2/Resource/Message.pm
@@ -148,6 +148,14 @@ sub add_message {
             \400, $msg || "Message failed for unknown reason");
     }
 
+    # This hook will only really matter once the
+    # allow-update-of-ticket-status-on-correspond branch is merged
+    # in, at which point we can delete this comment
+    my ($http_code, $errmsg) = RT::Extension::REST2::Resource::Ticket->validate_hook_before_update(\%args, $self->record);
+    if ($http_code != 200) {
+        return(\$http_code, $errmsg);
+    }
+
     push @results, $msg;
     push @results, update_custom_fields($self->record, $args{CustomFields});
     push @results, $self->_update_txn_custom_fields( $TransObj, $args{TxnCustomFields} || $args{TransactionCustomFields} );
diff --git a/lib/RT/Extension/REST2/Resource/Ticket.pm b/lib/RT/Extension/REST2/Resource/Ticket.pm
index f8cf37a..4fde4c6 100644
--- a/lib/RT/Extension/REST2/Resource/Ticket.pm
+++ b/lib/RT/Extension/REST2/Resource/Ticket.pm
@@ -12,7 +12,8 @@ with (
         => { -alias => { hypermedia_links => '_default_hypermedia_links' } },
     'RT::Extension::REST2::Resource::Record::Deletable',
     'RT::Extension::REST2::Resource::Record::Writable'
-        => { -alias => { create_record => '_create_record' } },
+        => { -alias => { create_record => '_create_record',
+                         update_record => '_update_record'} },
 );
 
 sub dispatch_rules {
@@ -52,10 +53,54 @@ sub create_record {
         );
     }
 
+    my ($retcode, $mesg) = $self->validate_hook_before_create($data, $queue);
+    if ($retcode != 200) {
+        return (\$retcode, $mesg);
+    }
+
     my ($ok, $txn, $msg) = $self->_create_record($data);
     return ($ok, $msg);
 }
 
+sub update_record
+{
+    my ($self, $data) = @_;
+
+    my ($retcode, $msg) = $self->validate_hook_before_update($data, $self->record);
+    if ($retcode != 200) {
+        return (\$retcode, $msg);
+    }
+    return $self->_update_record($data);
+}
+
+# This function is called just before ticket creation; it is passed
+# the REST data and the queue in which the ticket should be created.
+# It should return (200, '') if all is OK, or (4xx, $msg) if something
+# is wrong and the creation should be aborted.
+#
+# This is just a stub.  Extensions are expected to replace this
+# implementation with their own.
+sub validate_hook_before_create
+{
+    my ($self, $data, $queue) = @_;
+
+    return (200, '');
+}
+
+# This function is called just before ticket update; it is passed the
+# REST data and the ticket being updated.  It should return (200, '')
+# if all is OK, or (4xx, $msg) if something is wrong and the creation
+# should be aborted.
+#
+# This is just a stub.  Extensions are expected to replace this
+# implementation with their own.
+sub validate_hook_before_update
+{
+    my ($self, $data, $ticket) = @_;
+
+    return (200, '');
+}
+
 sub forbidden {
     my $self = shift;
     return 0 unless $self->record->id;

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


More information about the Bps-public-commit mailing list