[Bps-public-commit] rt-extension-rest2 branch, master, updated. 1.01-4-g8e34b33

Jim Brandt jbrandt at bestpractical.com
Thu Mar 15 16:32:51 EDT 2018


The branch, master has been updated
       via  8e34b33fe3e1c6ad45f6ad4ef4442f82df09d787 (commit)
       via  bf81b12c5e3e1a4ae27f302c12d00b83c487dbc2 (commit)
       via  804df0ddf1d3e79aeca17a5243bcc363ae0c3b8e (commit)
      from  b37be8a811a8f1637e1e276408dd30f93b2a8acf (commit)

Summary of changes:
 Changes                                              |  3 +++
 META.yml                                             |  2 +-
 lib/RT/Extension/REST2.pm                            |  2 +-
 lib/RT/Extension/REST2/Resource/Record/Hypermedia.pm | 12 ++++++++++--
 lib/RT/Extension/REST2/Util.pm                       | 10 ++++++++++
 t/ticket-links.t                                     | 11 ++++++++++-
 6 files changed, 35 insertions(+), 5 deletions(-)

- Log -----------------------------------------------------------------
commit 804df0ddf1d3e79aeca17a5243bcc363ae0c3b8e
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Dec 22 13:03:38 2017 -0500

    Add test for returning external links on tickets

diff --git a/t/ticket-links.t b/t/ticket-links.t
index e820d63..396c494 100644
--- a/t/ticket-links.t
+++ b/t/ticket-links.t
@@ -25,6 +25,9 @@ my $child_id = $child->Id;
 ($ok, $msg) = $child->AddLink(Type => 'MemberOf', Target => $parent->id);
 ok($ok, $msg);
 
+($ok, $msg) = $child->AddLink(Type => 'RefersTo', Target => 'https://bestpractical.com');
+ok($ok, $msg);
+
 $user->PrincipalObj->GrantRight( Right => 'ShowTicket' );
 
 # Inspect existing ticket links (parent)
@@ -72,7 +75,6 @@ $user->PrincipalObj->GrantRight( Right => 'ShowTicket' );
     cmp_deeply($links{'depends-on'}, undef, 'no depends-on links');
     cmp_deeply($links{'depended-on-by'}, undef, 'no depended-on-by links');
     cmp_deeply($links{'child'}, undef, 'no child links');
-    cmp_deeply($links{'refers-to'}, undef, 'no refers-to links');
     cmp_deeply($links{'referred-to-by'}, undef, 'no referred-to-by links');
 
     cmp_deeply($links{'parent'}, [{
@@ -81,7 +83,14 @@ $user->PrincipalObj->GrantRight( Right => 'ShowTicket' );
         id   => $parent->Id,
         _url => re(qr{$rest_base_path/ticket/$parent_id$}),
     }], 'one child link');
+
+    cmp_deeply($links{'refers-to'}, [{
+        ref  => 'refers-to',
+        type => 'external',
+        _url => re(qr{https\:\/\/bestpractical\.com}),
+    }], 'one external refers-to link');
 }
 
+
 done_testing;
 

commit bf81b12c5e3e1a4ae27f302c12d00b83c487dbc2
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Dec 22 13:04:29 2017 -0500

    Add support for external ticket links

diff --git a/lib/RT/Extension/REST2/Resource/Record/Hypermedia.pm b/lib/RT/Extension/REST2/Resource/Record/Hypermedia.pm
index 9c6dfdc..93e6d85 100644
--- a/lib/RT/Extension/REST2/Resource/Record/Hypermedia.pm
+++ b/lib/RT/Extension/REST2/Resource/Record/Hypermedia.pm
@@ -4,7 +4,7 @@ use warnings;
 
 use Moose::Role;
 use namespace::autoclean;
-use RT::Extension::REST2::Util qw(expand_uid custom_fields_for);
+use RT::Extension::REST2::Util qw(expand_uid expand_uri custom_fields_for);
 use JSON qw(to_json);
 
 sub hypermedia_links {
@@ -61,7 +61,15 @@ sub _rtlink_links {
         my $links = $record->$relation;
 
         while (my $link = $links->Next) {
-            my $entry = expand_uid($link->$method->UID);
+            my $entry;
+            if ( $link->LocalTarget and $link->LocalBase ){
+                # Internal links
+                $entry = expand_uid($link->$method->UID);
+            }
+            else {
+                # Links to external URLs
+                $entry = expand_uri($link->$mode);
+            }
             push @links, {
                 %$entry,
                 ref => $ref,
diff --git a/lib/RT/Extension/REST2/Util.pm b/lib/RT/Extension/REST2/Util.pm
index 1a03364..9b52319 100644
--- a/lib/RT/Extension/REST2/Util.pm
+++ b/lib/RT/Extension/REST2/Util.pm
@@ -9,6 +9,7 @@ use Sub::Exporter -setup => {
     exports => [qw[
         looks_like_uid
         expand_uid
+        expand_uri
         serialize_record
         deserialize_record
         error_as_json
@@ -48,6 +49,15 @@ sub expand_uid {
     };
 }
 
+sub expand_uri {
+    my $uri = shift;
+
+    return {
+        type    => 'external',
+        _url    => $uri,
+    };
+}
+
 sub format_datetime {
     my $sql  = shift;
     my $date = RT::Date->new( RT->SystemUser );

commit 8e34b33fe3e1c6ad45f6ad4ef4442f82df09d787
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Dec 22 13:06:21 2017 -0500

    Prep for 1.02

diff --git a/Changes b/Changes
index 58f0ca6..6261e93 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for RT-Extension-REST2
 
+1.02 2017-12-22
+ - Add support for external links on tickets
+
 1.01 2017-11-20
  - Relocate REST2 DB connect to occur after PSGI forks
  - Add cleanup method to resolve DBIx::SearchBuilder processing at request end
diff --git a/META.yml b/META.yml
index 6e364f4..08d9896 100644
--- a/META.yml
+++ b/META.yml
@@ -43,6 +43,6 @@ requires:
   perl: 5.10.1
 resources:
   license: http://opensource.org/licenses/gpl-license.php
-version: '1.01'
+version: '1.02'
 x_module_install_rtx_version: '0.39'
 x_requires_rt: 4.2.4
diff --git a/lib/RT/Extension/REST2.pm b/lib/RT/Extension/REST2.pm
index b7e2a7b..11eae18 100644
--- a/lib/RT/Extension/REST2.pm
+++ b/lib/RT/Extension/REST2.pm
@@ -4,7 +4,7 @@ use 5.010001;
 
 package RT::Extension::REST2;
 
-our $VERSION = '1.01';
+our $VERSION = '1.02';
 our $REST_PATH = '/REST/2.0';
 
 use Plack::Builder;

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


More information about the Bps-public-commit mailing list