-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Do not expose private metadata via relationfield serializer. #1635
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Do not expose private metadata via relationfield serializer. | ||
[maethu] |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,4 @@ | ||||||||||||||||
from plone import api | ||||||||||||||||
from plone.dexterity.interfaces import IDexterityContent | ||||||||||||||||
from plone.restapi.interfaces import IFieldSerializer | ||||||||||||||||
from plone.restapi.interfaces import IJsonCompatible | ||||||||||||||||
|
@@ -17,7 +18,12 @@ | |||||||||||||||
@adapter(IRelationValue) | ||||||||||||||||
@implementer(IJsonCompatible) | ||||||||||||||||
def relationvalue_converter(value): | ||||||||||||||||
if value.to_object: | ||||||||||||||||
has_permission = api.user.has_permission( | ||||||||||||||||
"Access Contents Information", | ||||||||||||||||
obj=value.__parent__ | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not get why we now check on parent? This is is probably a misunderstanding and wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably another miss-understanding on my end. I used the parent, since @davisagli wrote in the issue #1634 I'm happy to change this! |
||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
if value.to_object and has_permission: | ||||||||||||||||
request = getRequest() | ||||||||||||||||
request.form["metadata_fields"] = ["UID"] | ||||||||||||||||
summary = getMultiAdapter((value.to_object, request), ISerializeToJsonSummary)() | ||||||||||||||||
|
@@ -33,4 +39,9 @@ class RelationChoiceFieldSerializer(DefaultFieldSerializer): | |||||||||||||||
@adapter(IRelationList, IDexterityContent, Interface) | ||||||||||||||||
@implementer(IFieldSerializer) | ||||||||||||||||
class RelationListFieldSerializer(DefaultFieldSerializer): | ||||||||||||||||
pass | ||||||||||||||||
def __call__(self): | ||||||||||||||||
value = self.get_value() | ||||||||||||||||
if value: | ||||||||||||||||
return [item for item in json_compatible(value) if item] | ||||||||||||||||
else: | ||||||||||||||||
return super().__call__() | ||||||||||||||||
Comment on lines
+44
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the sake of readability: No |
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.
@plone/restapi-team In a comment above @erral wrote
plone.api
usage is allowed in this package in tests only and asked if this is right. May one you confirm 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.
We agreed that we can use plone.api in tests. Though, if I am not mistaken we also decided lately that plone.restapi can use plone.api everywhere, correct? Sorry for the late reply here. Just want to get this straight.