[Bps-public-commit] rt-extension-rest2 branch, allow-updating-of-ticket-links, created. 1.07-14-gf987d42
Craig Kaiser
craig at bestpractical.com
Fri May 1 18:46:43 EDT 2020
The branch, allow-updating-of-ticket-links has been created
at f987d42037b0c836b9531372a8294d6dfab19ac0 (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 f987d42037b0c836b9531372a8294d6dfab19ac0
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/Link.pm b/lib/RT/Extension/REST2/Resource/Link.pm
new file mode 100644
index 0000000..4742e32
--- /dev/null
+++ b/lib/RT/Extension/REST2/Resource/Link.pm
@@ -0,0 +1,26 @@
+package RT::Extension::REST2::Resource::Link;
+use strict;
+use warnings;
+
+use Moose;
+use namespace::autoclean;
+
+extends 'RT::Extension::REST2::Resource::Record';
+with 'RT::Extension::REST2::Resource::Record::Readable',
+ 'RT::Extension::REST2::Resource::Record::Hypermedia';
+
+sub dispatch_rules {
+ Path::Dispatcher::Rule::Regex->new(
+ regex => qr{^(Add|Delete)Link$},
+ block => sub { { record_class => 'RT::Link' } },
+ ),
+ Path::Dispatcher::Rule::Regex->new(
+ regex => qr{^(Add|Delete)Link$},
+ block => sub { { record_class => 'RT::Link', record_id => shift->pos(1) } },
+ )
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
diff --git a/lib/RT/Extension/REST2/Resource/Links.pm b/lib/RT/Extension/REST2/Resource/Links.pm
new file mode 100644
index 0000000..2d20c5a
--- /dev/null
+++ b/lib/RT/Extension/REST2/Resource/Links.pm
@@ -0,0 +1,21 @@
+package RT::Extension::REST2::Resource::Links;
+use strict;
+use warnings;
+
+use Moose;
+use namespace::autoclean;
+
+extends 'RT::Extension::REST2::Resource::Collection';
+with 'RT::Extension::REST2::Resource::Collection::QueryByJSON';
+
+sub dispatch_rules {
+ Path::Dispatcher::Rule::Regex->new(
+ regex => qr{^(Add|Delete)Link$},
+ block => sub { { collection_class => 'RT::Links' } },
+ ),
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
diff --git a/lib/RT/Extension/REST2/Util.pm b/lib/RT/Extension/REST2/Util.pm
index b312e73..b175704 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 =~ /^(Add|Delete)Link$/ ) ) {
+ 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