Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Titouan Soulard
erp5
Commits
2b887aea
Commit
2b887aea
authored
Nov 27, 2023
by
Titouan Soulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_action_information_api: move API content to script
parent
e306930e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
40 deletions
+46
-40
bt5/erp5_action_information_api/DocumentTemplateItem/portal_components/document.erp5.ActionInformationAPI.py
...m/portal_components/document.erp5.ActionInformationAPI.py
+11
-36
bt5/erp5_action_information_api/SkinTemplateItem/portal_skins/erp5_action_information_api/ActionInformationAPI_api_slap.py
...5_action_information_api/ActionInformationAPI_api_slap.py
+35
-4
No files found.
bt5/erp5_action_information_api/DocumentTemplateItem/portal_components/document.erp5.ActionInformationAPI.py
View file @
2b887aea
...
...
@@ -119,49 +119,24 @@ class ActionInformationAPI(XMLObject):
def
handleRequest
(
self
,
request
):
portal
=
self
.
getPortalObject
()
(
hyperdocument
,
actions
)
=
self
.
getTypeInfo
().
getDefaultViewFor
(
self
,
view
=
self
.
getApiTypeReference
())(
self
,
portal
,
request
)
response
=
request
.
RESPONSE
view_ref
=
self
.
getApiTypeReference
()
request_content_type
=
request
.
getHeader
(
"content-type"
)
if
view_ref
is
None
:
raise
NotImplementedError
(
"Cannot find matching view"
)
if
request_content_type
and
request_content_type
!=
"application/json"
:
raise
NotImplementedError
(
"Cannot serve Content-Type {}"
.
format
(
request_content_type
))
response
.
setHeader
(
"Content-Type"
,
"application/json"
)
if
request
.
get
(
"method"
).
lower
()
!=
"post"
:
return
hyperdocument
request_json
=
request
.
get
(
"BODY"
)
if
not
request_json
:
return
hyperdocument
request_body
=
json
.
loads
(
request_json
)
request_schema
=
request_body
.
get
(
"$schemaDocument"
)
request_object_ref
=
request_body
.
get
(
"reference"
)
if
not
request_schema
or
not
request_object_ref
:
return
hyperdocument
found_action
=
""
for
schema_url
in
actions
:
if
schema_url
in
request_schema
:
found_action
=
actions
[
schema_url
]
break
if
not
found_action
:
raise
NotFound
(
"Schema {} unavailable"
.
format
(
request_schema
))
portal_type
=
found_action
.
getParentValue
().
getId
()
request_object
=
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
portal_type
,
id
=
request_object_ref
)
if
not
request_object
:
raise
NotFound
(
"Object {} not found"
.
format
(
request_object_ref
))
action_output
=
request_object
.
getTypeInfo
().
getDefaultViewFor
(
request_object
,
view
=
found_action
.
getProperty
(
"reference"
))(
request_body
)
action_output
[
"status"
]
=
200
return
json
.
dumps
(
action_output
,
indent
=
2
).
encode
()
request
.
RESPONSE
.
setHeader
(
"Content-Type"
,
"application/json"
)
raw_reponse
=
self
.
getTypeInfo
().
getDefaultViewFor
(
self
,
view
=
view_ref
)(
self
,
portal
,
request
)
return
json
.
dumps
(
raw_reponse
,
indent
=
2
).
encode
()
def
publishTraverse
(
self
,
request
,
name
):
if
request
.
method
.
upper
()
in
(
'PUT'
,
'DELETE'
):
# PUT and DELETE methods, because they are handled as WebDAV before custom hooks are called
return
ActionInformationAPIPublisher
(
self
,
request
)
adapter
=
DefaultPublishTraverse
(
self
,
request
)
try
:
obj
=
adapter
.
publishTraverse
(
request
,
name
)
...
...
bt5/erp5_action_information_api/SkinTemplateItem/portal_skins/erp5_action_information_api/ActionInformationAPI_api_slap.py
View file @
2b887aea
import
json
from
zExceptions
import
NotFound
url
=
request
.
getURL
()
base_url_absolute
=
portal
.
portal_callables
.
absolute_url
().
strip
()
...
...
@@ -11,7 +12,7 @@ raw_action_list = portal.portal_catalog(
)
links
=
[]
action
_dict
=
{}
action
s
=
{}
for
item
in
raw_action_list
:
# XXX: for now, expects reference to be the same as action URL
...
...
@@ -24,8 +25,38 @@ for item in raw_action_list:
"url"
:
url
})
action
_dict
[
base_url_relative
+
action_url
+
"/getInputJSONSchema"
]
=
item
action
s
[
base_url_relative
+
action_url
+
"/getInputJSONSchema"
]
=
item
hyperdocument
=
json
.
dumps
({
"links"
:
links
},
indent
=
2
).
encode
()
hyperdocument
=
{
"links"
:
links
}
return
(
hyperdocument
,
action_dict
)
if
request
.
get
(
"method"
).
lower
()
!=
"post"
:
return
hyperdocument
request_json
=
request
.
get
(
"BODY"
)
if
not
request_json
:
return
hyperdocument
request_body
=
json
.
loads
(
request_json
)
request_schema
=
request_body
.
get
(
"$schemaDocument"
)
request_object_ref
=
request_body
.
get
(
"reference"
)
if
not
request_schema
or
not
request_object_ref
:
return
hyperdocument
found_action
=
""
for
schema_url
in
actions
:
if
schema_url
in
request_schema
:
found_action
=
actions
[
schema_url
]
break
if
not
found_action
:
raise
NotFound
(
"Schema {} unavailable"
.
format
(
request_schema
))
portal_type
=
found_action
.
getParentValue
().
getId
()
request_object
=
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
portal_type
,
id
=
request_object_ref
)
if
not
request_object
:
raise
NotFound
(
"Object {} not found"
.
format
(
request_object_ref
))
action_output
=
request_object
.
getTypeInfo
().
getDefaultViewFor
(
request_object
,
view
=
found_action
.
getProperty
(
"reference"
))(
request_body
)
action_output
[
"status"
]
=
200
return
action_output
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment