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

1letter/fix#671 #675

Merged
merged 11 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/671.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix link_redirect_view, respect vhm vs none-vhm url schemes @1letter
9 changes: 8 additions & 1 deletion plone/app/contenttypes/browser/link_redirect_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from urllib.parse import urlparse
from zope.component import getMultiAdapter
from zope.component import getUtility


Expand Down Expand Up @@ -111,10 +112,16 @@ def absolute_target_url(self):
if "resolveuid" in url:
uid = url.split("/")[-1]
obj = uuidToObject(uid)

portal_state = getMultiAdapter(
(self.context, self.request), name="plone_portal_state"
)
portal_url = portal_state.portal_url()

if obj:
url = "/".join(obj.getPhysicalPath()[2:])
Copy link
Member

Choose a reason for hiding this comment

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

I might be wrong, but if this [:2] is to remove something like "/app/Plone", then it is not valid...
You can have Plone site inside other objects, e.g. a Folder.
e.g. the path might be /app/folder/Plone or /app/folder/subfolder/Plone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ale-rt right, i will refactor this

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider also VHM rules, and the use of _vh_ (for example:

    location /zope {
        proxy_pass http://localhost:8080/VirtualHostBase/https/site.com/VirtualHostRoot/_vh_zope;
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

using absolute_url() will do it.

if not url.startswith("/"):
url = "/" + url
url = f"{portal_url}/{url}"
if not url.startswith(("http://", "https://")):
url = self.request["SERVER_URL"] + url

Expand Down
8 changes: 7 additions & 1 deletion plone/app/contenttypes/tests/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,10 @@ def test_resolve_uid_to_absolute_target(self):
doc1 = self.portal["doc1"]
uid = IUUID(doc1)
self.link.remoteUrl = f"${{portal_url}}/resolveuid/{uid}"
self.assertEqual(view.absolute_target_url(), "http://nohost/doc1")

portal_state = getMultiAdapter(
(self.link, self.request), name="plone_portal_state"
)
portal_url = portal_state.portal_url()

self.assertEqual(view.absolute_target_url(), f"{portal_url}/doc1")