[Bps-public-commit] rt-extension-rest2 branch, allow-updating-of-ticket-links, created. 1.07-14-gd70d8c1

Craig Kaiser craig at bestpractical.com
Fri May 1 18:52:04 EDT 2020


The branch, allow-updating-of-ticket-links has been created
        at  d70d8c191527e3eca384e21b5e7c52988d79aaf6 (commit)

- Log -----------------------------------------------------------------
commit 10407bd229f7a3380f95f8ef6d6961e959fa2e0e
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Tue Oct 8 09:03:36 2019 -0400

    Fix typo in asset search example

diff --git a/README b/README
index 5871ce5..2ef68e5 100644
--- a/README
+++ b/README
@@ -299,7 +299,7 @@ USAGE
         # Search Assets
         curl -X POST -H "Content-Type: application/json" -u 'root:password'
         -d '[{ "field" : "id", "operator" : ">=", "value" : 0 }]'
-        'https://myrt.com/REST/2.0/asset'
+        'https://myrt.com/REST/2.0/assets'
 
    Transactions
         GET /transactions?query=<JSON>
diff --git a/lib/RT/Extension/REST2.pm b/lib/RT/Extension/REST2.pm
index e0315c5..8fdf862 100644
--- a/lib/RT/Extension/REST2.pm
+++ b/lib/RT/Extension/REST2.pm
@@ -335,7 +335,7 @@ Below are some examples using the endpoints above.
     # Search Assets
     curl -X POST -H "Content-Type: application/json" -u 'root:password'
     -d '[{ "field" : "id", "operator" : ">=", "value" : 0 }]'
-    'https://myrt.com/REST/2.0/asset'
+    'https://myrt.com/REST/2.0/assets'
 
 =head3 Transactions
 

commit d70d8c191527e3eca384e21b5e7c52988d79aaf6
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Jun 13 14:39:05 2019 -0400

    Allow updating of ticket links
    
    Use the 'AddLink' and 'DeleteLink' keys with a link
    'type' (MemberOf DependsOn RefersTo ect) key and a
    'base' key, this can be a ticket id or a link URL.

diff --git a/lib/RT/Extension/REST2/Resource/Record/Writable.pm b/lib/RT/Extension/REST2/Resource/Record/Writable.pm
index a01b94a..4a1a8f3 100644
--- a/lib/RT/Extension/REST2/Resource/Record/Writable.pm
+++ b/lib/RT/Extension/REST2/Resource/Record/Writable.pm
@@ -52,6 +52,7 @@ sub update_record {
         AttributesRef => [ $self->record->WritableAttributes ],
     );
 
+    push @results, update_links($self->record, $data->{Links});
     push @results, update_custom_fields($self->record, $data->{CustomFields});
     push @results, $self->_update_role_members($data);
     push @results, $self->_update_disabled($data->{Disabled})
@@ -62,6 +63,32 @@ sub update_record {
     return @results;
 }
 
+sub update_links {
+    my $self = shift;
+    my $data = shift;
+
+    return unless $self->DOES('RT::Record::Role::Links');
+
+    my @results;
+
+    foreach my $new_link (@{$data}) {
+        my $skip;
+        my $action = (keys %{$new_link})[0];
+
+        my $info = $new_link->{$action};
+
+         if ( $action eq 'AddLink' ) {
+            my ($ret, $msg) = $self->AddLink( Type => $info->{'type'}, Target => $info->{'target'} );
+            push @results, $msg;
+         }
+         elsif ( $action eq 'DeleteLink' ) {
+             my ($ret, $msg) = $self->DeleteLink( Type => $info->{'type'}, Target => $info->{'target'} );
+            push @results, $msg;
+         }
+    }
+    return @results;
+}
+
 sub _update_role_members {
     my $self = shift;
     my $data = shift;
diff --git a/lib/RT/Extension/REST2/Util.pm b/lib/RT/Extension/REST2/Util.pm
index b312e73..49d25b1 100644
--- a/lib/RT/Extension/REST2/Util.pm
+++ b/lib/RT/Extension/REST2/Util.pm
@@ -152,6 +152,7 @@ sub deserialize_record {
     my $data   = shift;
 
     my $does_roles = $record->DOES("RT::Record::Role::Roles");
+    my $does_links = $record->DOES("RT::Record::Role::Links");
 
     # Sanitize input for the Perl API
     for my $field (sort keys %$data) {
@@ -174,6 +175,11 @@ sub deserialize_record {
             }
             $data->{$field} = \@members;
         }
+        elsif ( $does_links and ($field =~ /^Links$/ ) ) {
+            my @links = ref $value eq 'ARRAY'
+                ? @$value : $value;
+            $data->{$field} = \@links;
+        }
         else {
             RT->Logger->debug("Received unknown value via JSON for field $field: ".ref($value));
             delete $data->{$field};

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


More information about the Bps-public-commit mailing list