Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#663 canonical url fix #1344

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rsonth
Copy link

@rsonth rsonth commented Jan 15, 2021

Q                       A
Fixed Issues? ` Canonical url fix
Patch: Bug Fix? #663
Minor: New Feature? Yes
Major: Breaking Change? No
Tests Added + Pass? Yes
Documentation Provided Yes
Any Dependency Changes? No
License Apache License, Version 2.0

@codecov
Copy link

codecov bot commented Jan 15, 2021

Codecov Report

Merging #1344 (e72cd82) into development (4c8d80e) will decrease coverage by 0.01%.
The diff coverage is 77.77%.

Impacted file tree graph

@@                Coverage Diff                @@
##             development    #1344      +/-   ##
=================================================
- Coverage          84.92%   84.90%   -0.02%     
- Complexity          1802     1805       +3     
=================================================
  Files                169      169              
  Lines               5080     5089       +9     
  Branches             801      803       +2     
=================================================
+ Hits                4314     4321       +7     
  Misses               304      304              
- Partials             462      464       +2     
Impacted Files Coverage Δ Complexity Δ
...m/core/components/internal/models/v2/PageImpl.java 82.43% <75.00%> (-0.91%) 34.00 <2.00> (+2.00) ⬇️
.../com/adobe/cq/wcm/core/components/models/Page.java 100.00% <100.00%> (ø) 22.00 <1.00> (+1.00)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b26a0e7...4c2ef0a. Read the comment docs.

Copy link
Member

@vladbailescu vladbailescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a property that should be inherited and not authored on each page. I'm wondering if we shouldn't use a context-aware configuration for storing it. @gabrielwalt , WDYT?

jcr:primaryType="nt:unstructured"
cq-msm-lockable="sling:alias"/>
</alias>
<canonical
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of copy-pasting the entire tab we could just append the field (using ResourceMerger)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes has been taken care as suggested using resource merge. Please review the same

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladbailescu Did you get a chance to review the changes? These changes taken care upon your review comments?

if (currentPage != null) {
String authoredCanonicalURL = pageProperties.get(CANONICAL_URL, String.class);
PageManager pageManager = currentPage.getPageManager();
if (pageManager != null && pageManager.getPage(authoredCanonicalURL)!=null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add proper spacing on this line and the line bellow

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been taken care

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladbailescu Did you get a chance to review the changes? These changes taken care upon your review comments?

@@ -148,6 +150,8 @@
private String[] clientLibCategoriesJsHead;

private List<HtmlPageItem> htmlPageItems;

public static final String CANONICAL_URL = "canonical";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants should be defined in the model interface and follow the name convention there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been taken care

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladbailescu Did you get a chance to review the changes? These changes taken care upon your review comments?

if (currentPage != null) {
String authoredCanonicalURL = pageProperties.get(CANONICAL_URL, String.class);
PageManager pageManager = currentPage.getPageManager();
if (pageManager != null && pageManager.getPage(authoredCanonicalURL)!=null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure Page#getPageManager() cannot return null,
Also, the canonical page is resolved twice via PageManager#getPage().
Once to assert the page exists and perform the null check, a second time to actually use it to craft the URL.

Although we can be pretty certain that the second call won't return null, there is no guarantee.

An alternative would be something like

    @Override
	public String getCanonicalURL() {
        if (currentPage != null) {
            String authoredCanonicalURL = pageProperties.get(CANONICAL_URL, String.class)
            PageManager pageManager = currentPage.getPageManager();
            return Optional.ofNullable(authoredCanonicalURL)
                .map(pageManager::getPage)
                .map(p -> Utils.getURL(request, pageManager, p))
                .orElse(authoredCanonicalURL);
        }
        return null
    }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made changes as suggested.

Copy link
Author

@rsonth rsonth Jan 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladbailescu @ky940819 Did you get a chance to review the changes? These changes taken care upon your review comments?

@@ -161,4 +161,18 @@ void testHtmlPageItemsConfig() {
assertNotNull(page.getHtmlPageItems());
assertEquals(3, page.getHtmlPageItems().size(), "Unexpected number of HTML page items");
}

@Test
void testgetCanonicalURL_External() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The not null assertion isn't enough to validate that it is functioning properly.
Need to ensure that the value returned is the value expected.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required changes have been taken care.

Copy link
Author

@rsonth rsonth Jan 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladbailescu @ky940819 Did you get a chance to review the changes? These changes taken care upon your review comments?

@sonarcloud
Copy link

sonarcloud bot commented Jan 20, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
2.3% 2.3% Duplication

Copy link
Author

@rsonth rsonth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladbailescu @ky940819 Did you get a chance to review the changes?

@gabrielwalt gabrielwalt added this to the 2.15.0 milestone Feb 3, 2021
@vladbailescu vladbailescu modified the milestones: 2.15.0, 2.16.0 Feb 23, 2021
@vladbailescu vladbailescu modified the milestones: 2.16.0, Minor Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants