-
Notifications
You must be signed in to change notification settings - Fork 22
Make senaite.jsonapi to be portal-type-naive and allow adapter for create operation
#37
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
Conversation
ramonski
left a comment
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.
Thanks for this PR! Pretty cool to adapt the object creation as well.
However, there's one caveat we need to address, which is the location/container where the object need to be created.
Currently, this is done in a hard coded way here:
https://github.com/senaite/senaite.jsonapi/pull/37/files#diff-aa9c49f3316ea3b1a902860e227779c6R1069
Maybe it would make sense to provide that in the adapter as well?
Issues occur e.g. for the type "DynamicAnalysisSpec" which I used for testing with that payload:
{
"parent_path":"/senaite/bika_setup/dynamic_analysisspecs",
"portal_type": "DynamicAnalysisSpec",
"title": "My Spec"
}
It ended up in a renamed Setup folder:
|
Hmm, I see that it should actually be the |
Sure. Will check and revert back |
I would entirely remove this "automatic" assignment of the parent path. I believe we should be as much coherent as possible. I mean, why user needs to set the parent container (via
Adapter could be created, but if we entirely remove that auto-assignment, I feel it wouldn't provide any additional value |
Just found out what happens here... really weird. The problem is in core's api, here: .... but How this can be? Maybe The Dynamic Analysis Spec is created correctly, btw: |
While the problem was that Surname is required, I got this error
when trying to create a Client Contact:
```
File
"/buildout-cache/eggs/plone.jsonapi.core-0.6-py2.7.egg/plone/jsonapi/core/browser/decorators.py",
line 24, in decorator
return f(*args, **kwargs)
File
"/buildout-cache/eggs/plone.jsonapi.core-0.6-py2.7.egg/plone/jsonapi/core/browser/api.py",
line 60, in to_json
return self.dispatch()
File
"/buildout-cache/eggs/plone.jsonapi.core-0.6-py2.7.egg/plone/jsonapi/core/browser/api.py",
line 54, in dispatch
return router(self.context, self.request, path)
File
"/buildout-cache/eggs/plone.jsonapi.core-0.6-py2.7.egg/plone/jsonapi/core/browser/router.py",
line 138, in __call__
return self.view_functions[endpoint](context, request, **values)
File
"/zinstance/src/senaite.jsonapi/src/senaite/jsonapi/v1/routes/content.py",
line 89, in action
items = action_func(portal_type=portal_type, uid=uid)
File
"/zinstance/src/senaite.jsonapi/src/senaite/jsonapi/api.py",
line 170, in create_items
obj = create_object(container, portal_type, **record)
File
"/zinstance/src/senaite.jsonapi/src/senaite/jsonapi/api.py",
line 1408, in create_object
container.manage_delObjects(obj.id)
File
"/zinstance/src/senaite.core/bika/lims/content/client.py",
line 267, in manage_delObjects
"Do not have permissions to remove this object")
Unauthorized: Do not have permissions to remove this object
```
After this change, this is the error I get (correct):
```
APIError: {"Surname": "Surname is required, please correct."}
```
|
I think the issue with the |
Agree, we can remove that entirely. I think I added it to omit the
Yes, agree. Let's keep things simple. |
Give responsability to the developer about the container of the object to be created


Description of the issue/feature this PR addresses
This pull request makes
senaite.jsonapito be portal_type-naive. This means that by default,senaite.jsonapidelegates the responsibility of creation operation to the underlying add-on where the given portal type is registered, so it no longer checks explicitly for portal types on creation.Nevertheless,
senaite.jsonapidoes not allow the creation of objects when:senaitepath)senaite/bika_setuppath)portal_typeFor the cases above,
senaite.jsonapiwill always return a 401 response.In addition, this Pull Request also allows to easily adapt the
createoperation for any given portal type and container. Sometimes, one might want to handle the creation of a given object differently,either because:
senaite.jsonapiSENAITE.JSONAPI provides the
ICreateinterface that allows to handle thecreateoperation with more granularity. An Adapter of this interface is initialized with the container object to be created. Example:With this example,
senaite.jsonapiwill not follow the default procedure of creation, it will rather delegate the operation of theTodoobject to the functioncreate_objectof this adapter. Note the creation will only be delegated when the functionis_creation_delegatedreturns True.Also note that if the function
is_creation_allowedreturns False, the system will raise a 401 exception.Current behavior before PR
senaite.jsonapiis not portal type naive and does not allow to manually handle the creation of objects unless creating a new route.Desired behavior after PR is merged
senaite.jsonapibecomes portal type naive and allows to manually handle the creation of specific objects without the need of creating an additional route.--
I confirm I have tested the PR thoroughly and coded it according to PEP8
standards.