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

Register IObjectPrimaryFieldTarget for Link objects #1847

Merged
merged 4 commits into from
Nov 26, 2024

Conversation

cekk
Copy link
Member

@cekk cekk commented Nov 26, 2024

This could be useful for example when you link a Link in slate.
Anonymous users automatically have resolved url in text link without redirects.

I choose to do it for anonymous users because otherwise this could change stored value in the slate data: for example if an editor of the current page can't edit the linked Link, he could override slate link data with the resolved url and not with the resolveuid link to Link object.

btw for this kind of use-cases probably could solve our problems a flag "is in edit-mode" or "is in view mode" that Volto sends to the backend and let us do different things in serializer based on that flag.


📚 Documentation preview 📚: https://plonerestapi--1847.org.readthedocs.build/

@mister-roboto
Copy link

@cekk 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!

@cekk cekk requested a review from davisagli November 26, 2024 10:27
@cekk
Copy link
Member Author

cekk commented Nov 26, 2024

@jenkins-plone-org please run jobs

@davisagli
Copy link
Member

This could be useful for example when you link a Link in slate.

@cekk Can you remind me where/how does that end up using the IObjectPrimaryFieldTarget adapter?

@cekk
Copy link
Member Author

cekk commented Nov 26, 2024

https://github.com/plone/plone.restapi/blob/main/src/plone/restapi/serializer/dxcontent.py#L137
and
https://github.com/plone/plone.restapi/blob/main/src/plone/restapi/serializer/utils.py#L34

The first one add an attribute to the serialized json.
The second one is called evertime a block need to convert an internal link with resolveuid into a resolved url.

In my usecase when you refers to a Link object and call resolve_uid with its UID, i'd like to return:

  • the Link absolute_url if the use is authenticated, because can potentially edit it
  • the remoteUrl value of the Link object if the user is anonymous, to avoid an intermediate redirect (when the anon goes to the Link path and then will be redirected to its remoteUrl address)

@davisagli
Copy link
Member

@cekk Thanks. I agree with the use case; it matches how we handle Links in other situations. I just needed the reminder that the resolveuid code uses this.

@davisagli davisagli merged commit 447a87c into main Nov 26, 2024
21 of 25 checks passed
@davisagli davisagli deleted the cekk_link_primary_field branch November 26, 2024 14:29
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.

3 participants