[Bps-public-commit] rt-extension-rest2 branch, fix-linked-asset-and-article-urls-in-hyperlinks, created. 1.09-23-ga6241fc

? sunnavy sunnavy at bestpractical.com
Wed Apr 14 16:35:49 EDT 2021


The branch, fix-linked-asset-and-article-urls-in-hyperlinks has been created
        at  a6241fcdc092e741e1ca76412a9afec8d9c4b95d (commit)

- Log -----------------------------------------------------------------
commit c210539567d0842eb07be85cc87fa5197f3222df
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Apr 15 04:18:14 2021 +0800

    Fix the logic of determining if a link is local or not for assets/articles
    
    We can't use LocalBase/LocalTarget here as they are not set even for
    local assets/articles.

diff --git a/lib/RT/Extension/REST2/Resource/Record/Hypermedia.pm b/lib/RT/Extension/REST2/Resource/Record/Hypermedia.pm
index 2f27431..d6a0feb 100644
--- a/lib/RT/Extension/REST2/Resource/Record/Hypermedia.pm
+++ b/lib/RT/Extension/REST2/Resource/Record/Hypermedia.pm
@@ -57,12 +57,13 @@ sub _rtlink_links {
         my $mode = $RT::Link::TYPEMAP{$relation}{Mode};
         my $type = $RT::Link::TYPEMAP{$relation}{Type};
         my $method = $mode . "Obj";
+        my $mode_uri = $mode . 'URI';
 
         my $links = $record->$relation;
 
         while (my $link = $links->Next) {
             my $entry;
-            if ( $link->LocalTarget and $link->LocalBase ){
+            if ( $link->$mode_uri->IsLocal ) {
                 # Internal links
                 $entry = expand_uid($link->$method->UID);
             }

commit a6241fcdc092e741e1ca76412a9afec8d9c4b95d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Apr 15 04:33:04 2021 +0800

    Test article link in ticket hyperlinks

diff --git a/xt/ticket-links.t b/xt/ticket-links.t
index 8aab3c6..1c7e0f7 100644
--- a/xt/ticket-links.t
+++ b/xt/ticket-links.t
@@ -27,6 +27,14 @@ ok($ok, $msg);
 ($ok, $msg) = $child->AddLink(Type => 'RefersTo', Target => 'https://bestpractical.com');
 ok($ok, $msg);
 
+my $article = RT::Article->new(RT->SystemUser);
+($ok, $msg) = $article->Create(Class => 'General', Name => 'article foo');
+ok($ok, $msg);
+my $article_id = $article->Id;
+
+($ok, $msg) = $article->AddLink(Type => 'RefersTo', Target => $parent->URI);
+ok($ok, $msg);
+
 $user->PrincipalObj->GrantRight( Right => 'ShowTicket' );
 
 # Inspect existing ticket links (parent)
@@ -47,7 +55,12 @@ $user->PrincipalObj->GrantRight( Right => 'ShowTicket' );
     cmp_deeply($links{'depended-on-by'}, undef, 'no depended-on-by links');
     cmp_deeply($links{'parent'}, undef, 'no parent 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{'referred-to-by'}, [{
+        ref  => 'referred-to-by',
+        type => 'article',
+        id   => $article_id,
+        _url => re(qr{$rest_base_path/article/$article_id$}),
+    }], 'one referred-to-by link');
 
     cmp_deeply($links{'child'}, [{
         ref  => 'child',

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


More information about the Bps-public-commit mailing list