-
Notifications
You must be signed in to change notification settings - Fork 48
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
1letter/fix#671 #675
Conversation
@1letter thanks for creating this Pull Request and helping to improve Plone! TL;DR: Finish pushing changes, pass all other checks, then paste a comment:
To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically. Happy hacking! |
@jenkins-plone-org please run jobs |
(self.context, self.request), name="plone_portal_state" | ||
) | ||
portal_url = portal_state.portal_url() | ||
|
||
if obj: | ||
url = "/".join(obj.getPhysicalPath()[2:]) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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.
Stupid question: Why not simply use |
The uid will resolve to a catalog path. There's already a call in Zope to resolve from a catalog path to the object: so I think we just simply need to use this Zope function. Looking better, I was wrong. The uid is resolved to the object itself, so you're plain right. |
url = "/".join(obj.getPhysicalPath()[2:]) | ||
if not url.startswith("/"): | ||
url = "/" + url | ||
url = obj.absolute_url() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd check for obj
first (keep the if
from line 114) ... it might be that the uuid is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also uid = url.split("/")[-1] above is fragile ("/resolveuid/" vs "resolveuid/" vs "/a/relativepath/resolveuid"). Generally, you should find the index of 'resolveuid' in the path, and get the next one if it exists. It should be something like this (uid = getuid(path)):
def get_uid(path):
paths = path.split('/')
uid = None
if 'resolveuid' in paths:
ri = paths.index('resolveuid')
if ri + 1 != len(paths):
uid = paths[ri + 1]
if uid == '':
uid = None
return uid
>>> get_uid('gfdgdf')
>>> get_uid('')
>>> get_uid('/resolveuid/')
>>> get_uid('/resolveuidgfdgd/')
>>> get_uid('/resolveuid/4342432')
'4342432'
>>> get_uid('/resolveuid/4342432/')
'4342432'
>>> get_uid('fdsfd/fdf/resolveuid/4342432/')
'4342432'
>>> get_uid('/fdsfd/fdf/resolveuid/4342432/')
'4342432'
>>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also /resolveuid/fb91bddde7eb46efbed20e9c10fb4929#autotoc-item-autotoc-1
should still work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is resolve[uU]id
still a thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petschki maybe, but i'm not sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least plone.outputfilters
still takes it into account: https://github.com/plone/plone.outputfilters/blob/master/plone/outputfilters/filters/resolveuid_and_caption.py#L31
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_uid(path):
paths = path.split('/')
uid = None
if 'resolveuid' in paths:
ri = paths.index('resolveuid')
if ri + 1 != len(paths):
uid = paths[ri + 1]
if '#' in uid:
uid = uid.split('#')[0]
if uid == '':
uid = None
return uid
>>> get_uid('gfdgdf')
>>> get_uid('')
>>> get_uid('/resolveuid/')
>>> get_uid('/resolveuidgfdgd/')
>>> get_uid('/resolveuid/4342432')
'4342432'
>>> get_uid('/resolveuid/4342432/')
'4342432'
>>> get_uid('fdsfd/fdf/resolveuid/4342432/')
'4342432'
>>> get_uid('/fdsfd/fdf/resolveuid/4342432/')
'4342432'
>>> get_uid('/resolveuid/fb91bddde7eb46efbed20e9c10fb4929#autotoc-item-autotoc-1')
'fb91bddde7eb46efbed20e9c10fb4929'
>>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@1letter solution to use urlparse
is very good! Question: uid's are all lowercase? What if an UID has uppercase letters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yurj i use a copy of the list with lowercase values https://github.com/plone/plone.app.contenttypes/pull/675/files#diff-c9937c907b85ad438b19cb4ce7abe10606d94a443dc66bef1661a216690f3547R44
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least
plone.outputfilters
still takes it into account: https://github.com/plone/plone.outputfilters/blob/master/plone/outputfilters/filters/resolveuid_and_caption.py#L31
here is what plone.output filter does. It uses the re above to get all parts of the url. If there's an uid, find the object, translate it to the absolute_url, add the other parts.
If we want to do this the same way outputfilter does, we should use this code. This code also check IResolveUidsEnabler. Maybe this last part is not important (if a site disable uids and use resolveuid as a folder name...).
Generally, resoulveuid and catalog path resolution should be done in one place, I think in plone.api. I don't know about circular dipendencies...
Anyway, the actual code is ok, should works as expected and it is a real improvement.
BTW, absolute_url() uses physicalPathToVirtualPath: https://github.com/zopefoundation/Zope/blob/29e088e04db9feb9f5d3bc6bea8950d98f8283a1/src/OFS/Traversable.py#L51 (absolute_url() -> self.virtual_url_path()) |
- tests for get_uid_from_path
- Make resolution of uid more robust - calculate a fragment of anchor if available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least
plone.outputfilters
still takes it into account: https://github.com/plone/plone.outputfilters/blob/master/plone/outputfilters/filters/resolveuid_and_caption.py#L31
here is what plone.output filter does. It uses the re above to get all parts of the url. If there's an uid, find the object, translate it to the absolute_url, add the other parts.
If we want to do this the same way outputfilter does, we should use this code. This code also check IResolveUidsEnabler. Maybe this last part is not important (if a site disable uids and use resolveuid as a folder name...).
Generally, resoulveuid and catalog path resolution should be done in one place, I think in plone.api. I don't know about circular dipendencies...
Anyway, the actual code is ok, should works as expected and it is a real improvement.
url = "/".join(obj.getPhysicalPath()[2:]) | ||
if not url.startswith("/"): | ||
url = "/" + url | ||
url = obj.absolute_url() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least
plone.outputfilters
still takes it into account: https://github.com/plone/plone.outputfilters/blob/master/plone/outputfilters/filters/resolveuid_and_caption.py#L31
here is what plone.output filter does. It uses the re above to get all parts of the url. If there's an uid, find the object, translate it to the absolute_url, add the other parts.
If we want to do this the same way outputfilter does, we should use this code. This code also check IResolveUidsEnabler. Maybe this last part is not important (if a site disable uids and use resolveuid as a folder name...).
Generally, resoulveuid and catalog path resolution should be done in one place, I think in plone.api. I don't know about circular dipendencies...
Anyway, the actual code is ok, should works as expected and it is a real improvement.
add empty line at the end of news file
@jenkins-plone-org please run jobs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Fix for #671
better constructing of the url, use explicit the portal url