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

Issue #532: Implement get_path helper API #559

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

Conversation

ujsquared
Copy link
Contributor

@ujsquared ujsquared commented Feb 15, 2025

Fixes Issue #532

  • Uses Zope's inbuilt getPhysicalPath internally.
  • optional parameter relative_to_portal to fetch patch relative to Plone portal
  • throws InvalidParameterError when used to fetch an object outside of Plone portal with relative_to_portal parameter set to True

📚 Documentation preview 📚: https://ploneapi--559.org.readthedocs.build/

@mister-roboto
Copy link

@ujsquared thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

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!

Copy link
Contributor

@stevepiercy stevepiercy left a comment

Choose a reason for hiding this comment

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

Some reStructuredText syntax and English grammar docs and change log fixes. Otherwise the docs and change log look good to me.

Links to rendered docs to review.

Still needs a technical review. It looks pretty good from what I can understand.

Copy link
Member

@gforcada gforcada left a comment

Choose a reason for hiding this comment

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

Mostly opinions, let's see if others agree on them

Copy link
Contributor

@stevepiercy stevepiercy left a comment

Choose a reason for hiding this comment

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

Docs LGTM! Technical review still needed.

Copy link
Member

@ale-rt ale-rt left a comment

Choose a reason for hiding this comment

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

IMO it is disorienting that a relative path starts with "/".

I find it awkward but acceptable that absolute_url(relative=True) returns an initial "/" (the method has absolute in its name), but get_path(obj, realtive=True) returning something with a leading slash feels inconsistent.

@ujsquared
Copy link
Contributor Author

okay, will fix this.

@davisagli
Copy link
Member

@ale-rt @ujsquared I was going back and forth about whether I like removing the slash from the portal-relative path, but it has a nice benefit that you can do portal.unrestrictedTraverse(path) with the result.

@ale-rt
Copy link
Member

ale-rt commented Feb 18, 2025

@ale-rt @ujsquared I was going back and forth about whether I like removing the slash from the portal-relative path, but it has a nice benefit that you can do portal.unrestrictedTraverse(path) with the result.

You mean that it is better without the slash:

>>> portal.restrictedTraverse("/acl_users")
<PluggableAuthService at /acl_users>
>>> portal.restrictedTraverse("acl_users")
<PluggableAuthService at /Plone/acl_users>

Note that you do not need to pass a string to resolve a path:

>>> portal.restrictedTraverse(["acl_users", "source_users"])
<UserManager at /Plone/acl_users/source_users>

@ujsquared
Copy link
Contributor Author

@ale-rt @ujsquared I was going back and forth about whether I like removing the slash from the portal-relative path, but it has a nice benefit that you can do portal.unrestrictedTraverse(path) with the result.

You mean that it is better without the slash:

>>> portal.restrictedTraverse("/acl_users")
<PluggableAuthService at /acl_users>
>>> portal.restrictedTraverse("acl_users")
<PluggableAuthService at /Plone/acl_users>

Note that you do not need to pass a string to resolve a path:

>>> portal.restrictedTraverse(["acl_users", "source_users"])
<UserManager at /Plone/acl_users/source_users>

Currently, the repo has more instances of using getPhysicalPath() without a starting slash.

@mauritsvanrees
Copy link
Member

I would say:

  • relative=True should give no slash in front
  • relative=False should give a slash in front

So:

content.get_path(app.plone.folder.page) == "/plone/folder/page"
content.get_path(app.plone.folder.page, relative=True) == "folder/page"

So for the absolute case this would be: return "/".join(obj.getPhysicalPath())

@ale-rt
Copy link
Member

ale-rt commented Feb 19, 2025

I would say:

  • relative=True should give no slash in front
  • relative=False should give a slash in front

So:

content.get_path(app.plone.folder.page) == "/plone/folder/page"
content.get_path(app.plone.folder.page, relative=True) == "folder/page"

So for the absolute case this would be: return "/".join(obj.getPhysicalPath())

Excatly:

  • absolute => "/foo/bar"
  • relative => "foo/bar"

Copy link
Contributor

@stevepiercy stevepiercy left a comment

Choose a reason for hiding this comment

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

Copy link
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

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

I would still much prefer that we call the parameter relative_to_portal instead of relative. I think it makes it clearer what it does. Never mind, I looked again at Gil's reason of making it match absolute_url, and I think that makes sense.

@davisagli
Copy link
Member

@jenkins-plone-org please run jobs

Copy link
Contributor

@stevepiercy stevepiercy left a comment

Choose a reason for hiding this comment

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

Docs look good to me. Thank you! Are there any unresolved matters to address?

Copy link
Member

@ale-rt ale-rt left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

7 participants