[Bps-public-commit] rt-extension-rest2 branch, add-validation-hook-for-status-updates-2, repushed

Dianne Skoll dianne at bestpractical.com
Fri Jan 15 17:07:17 EST 2021


The branch add-validation-hook-for-status-updates-2 was deleted and repushed:
       was 29ecabe2d0d977766086b45cdb9a5ad0dbb75059
       now ba9e20908d0f5d1003006c6f3b5e2e91be0b1ed4

1:  6c20264 ! 1:  884acf2 Add system for maintaining validation hooks to RT::Extension::REST2
    @@ -19,8 +19,9 @@
     +my $ValidationHookObjects = { 'RT::Ticket' => 1 };
     +
     +# Register a validation hook for the given update type and object type
    -+# Returns a true value on successful registration; false otherwise.
    -+# TODO: Should probably carp if we cannot create the hook
    ++# Returns ($ok, $msg).  On success, $ok will be 1 and $msg irrelevant;
    ++# on failure, $ok will be 0 and $msg will indicate the nature of
    ++# the error.
     +sub add_validation_hook
     +{
     +    my ($class, $type, $object, $coderef) = @_;
    @@ -28,11 +29,15 @@
     +    # Allow caller to pass in an object or a name like RT::Ticket;
     +    $object = ref($object) if ref($object);
     +
    -+    return undef unless exists($ValidationHookTypes->{$type});
    -+    return undef unless exists($ValidationHookObjects->{$object});
    ++    unless (exists($ValidationHookTypes->{$type})) {
    ++        return(0, "$type is not a valid validation-hook type");
    ++    }
    ++    unless (exists($ValidationHookObjects->{$object})) {
    ++        return (0, "$object is not a valid validation-hook object");
    ++    }
     +
     +    push(@{$ValidationHooks->{$type}->{$object}}, $coderef);
    -+    return 1;
    ++    return (1, '');
     +}
     +
     +# Call all of the validation hooks for the given update type
2:  25f56e6 ! 2:  e0aad84 Add validation hooks for ticket update/create/correspond
    @@ -1,6 +1,6 @@
     Author: Dianne Skoll <dianne at bestpractical.com>
     
    -    Add validation hooks for ticket update/create/correspond.
    +    Add validation hooks for ticket update/create/correspond
     
     diff --git a/lib/RT/Extension/REST2/Resource/Message.pm b/lib/RT/Extension/REST2/Resource/Message.pm
     --- a/lib/RT/Extension/REST2/Resource/Message.pm
    @@ -27,8 +27,8 @@
          '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'} },
    ++        => { -alias => { create_record => '_create_record',
    ++                         update_record => '_update_record'} },
      );
      
      sub dispatch_rules {
3:  29ecabe ! 3:  25b4ca9 Add unit test to exercise ticket update/create validation hooks
    @@ -1,6 +1,6 @@
     Author: Dianne Skoll <dianne at bestpractical.com>
     
    -    Add unit test to exercise ticket update/create validation hooks.
    +    Add unit test to exercise ticket update/create validation hooks
     
     diff --git a/xt/ticket_validate.t b/xt/ticket_validate.t
     new file mode 100644
    @@ -36,12 +36,19 @@
     +    return (1, '');
     +}
     +
    -+ok(RT::Extension::REST2->add_validation_hook('create', 'RT::Ticket', sub { return my_create_validator(@_); }), 'Successfully added ticket-create validation hook');
    -+ok(RT::Extension::REST2->add_validation_hook('update', 'RT::Ticket', sub { return my_update_validator(@_); }), 'Successfully added ticket-update validation hook');
    ++my ($ok, $msg);
    ++($ok, $msg) = RT::Extension::REST2->add_validation_hook('create', 'RT::Ticket', sub { return my_create_validator(@_); });
    ++ok($ok, 'Successfully added ticket-create validation hook');
    ++($ok, $msg) = RT::Extension::REST2->add_validation_hook('update', 'RT::Ticket', sub { return my_update_validator(@_); });
    ++ok($ok, 'Successfully added ticket-update validation hook');
     +
    -+ok(!RT::Extension::REST2->add_validation_hook('update', 'RT::NOPE', sub { return my_update_validator(@_); }), 'Correctly failed to add validation hook for unknown object type');
    ++($ok, $msg) = RT::Extension::REST2->add_validation_hook('update', 'RT::NOPE', sub { return my_update_validator(@_); });
    ++ok(!$ok, 'Correctly failed to add validation hook for unknown object type');
    ++is($msg, 'RT::NOPE is not a valid validation-hook object', '... and failed with the expected error message');
     +
    -+ok(!RT::Extension::REST2->add_validation_hook('migrate', 'RT::Ticket', sub { return my_update_validator(@_); }), 'Correctly failed to add validation hook for unknown modification type');
    ++($ok, $msg) = RT::Extension::REST2->add_validation_hook('migrate', 'RT::Ticket', sub { return my_update_validator(@_); });
    ++ok(!$ok, 'Correctly failed to add validation hook for unknown modification type');
    ++is($msg, 'migrate is not a valid validation-hook type', '... and failed with the expected error message');
     +
     +diag 'Check validation on create';
     +my ($ticket_url, $ticket_id);
    @@ -104,3 +111,4 @@
     +
     +
     +done_testing;
    +
-:  ------- > 4:  ba9e209 Document the validation hook machinery



More information about the Bps-public-commit mailing list