[MGNLREST-264] JcrReferenceResolver should check for WebContext when resolving links Created: 07/Aug/20  Updated: 20/Oct/20  Resolved: 06/Oct/20

Status: Closed
Project: Magnolia REST Framework
Component/s: delivery
Affects Version/s: 2.2.1
Fix Version/s: 2.2.3

Type: Bug Priority: Neutral
Reporter: Richard Gange Assignee: Sang Ngo Huu
Resolution: Fixed Votes: 0
Labels: maintenance
Remaining Estimate: 0d
Time Spent: 2d 3h
Original Estimate: Not Specified

Issue Links:
relation
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Epic Link: Support
Sprint: Maintenance 27
Story Points: 2

 Description   

It was pointed out that JcrReferenceResolver always creates absolute links when it could create internal links if we checked for a WebContext. This is similar to what is done in AssetReferenceResolver. The proposal is to wrap the link creation with a conditional statement to check the type of context.

Context currentContext = MgnlContext.getInstance();
            
if (currentContext instanceof SystemContext) {
    Context originalContext = ((SystemContext) currentContext).getOriginalContext();
     if (originalContext instanceof WebContext) {
         MgnlContext.setInstance(originalContext);
    }
}

String link = LinkUtil.createLink(node); 

if (!currentContext.equals(MgnlContext.getInstance())) {
    MgnlContext.setInstance(currentContext);
}


 Comments   
Comment by Richard Gange [ 17/Aug/20 ]

See comment

Two distinct cases to keep in mind for testing & QA: depending on endpoint config, the bypassWorkspaceAcls flag in particular, the context may or may not be wrapped behind the SystemContext, or may be the user's WebContext already.
Therefore my understanding is that setting it to false should generate relative links already.

Comment by Richard Gange [ 17/Aug/20 ]

This is in fact the case:

  • bypassWorkspaceAcls: true
    • The links are generated in absolute form.
  • bypassWorkspaceAcls: false
    • The link are generated in relative form.
Generated at Mon Feb 12 06:58:12 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.