@@ -761,7 +761,7 @@ def processes_from_namespace(namespace):
761
761
if namespace .startswith ("u:" ) and backend_implementation .user_defined_processes :
762
762
user_id = namespace .partition ("u:" )[- 1 ]
763
763
user_udps = [p for p in backend_implementation .user_defined_processes .get_for_user (user_id ) if p .public ]
764
- processes = [_jsonable_udp_metadata ( udp , full = full , user = User (user_id = user_id )) for udp in user_udps ]
764
+ processes = [udp . to_api_dict ( full = full , user = User (user_id = user_id )) for udp in user_udps ]
765
765
elif ":" not in namespace :
766
766
process_registry = backend_implementation .processing .get_process_registry (
767
767
api_version = requested_api_version ()
@@ -796,7 +796,7 @@ def processes_details(namespace, process_id):
796
796
udp = backend_implementation .user_defined_processes .get (user_id = user_id , process_id = process_id )
797
797
if not udp :
798
798
raise ProcessUnsupportedException (process = process_id , namespace = namespace )
799
- process = _jsonable_udp_metadata ( udp , full = True , user = User (user_id = user_id ))
799
+ process = udp . to_api_dict ( full = True , user = User (user_id = user_id ))
800
800
elif ":" not in namespace :
801
801
process_registry = backend_implementation .processing .get_process_registry (
802
802
api_version = requested_api_version ()
@@ -1754,21 +1754,17 @@ def udp_get(process_graph_id: str, user: User):
1754
1754
_check_valid_process_graph_id (process_id = process_graph_id )
1755
1755
udp = backend_implementation .user_defined_processes .get (user_id = user .user_id , process_id = process_graph_id )
1756
1756
if udp :
1757
- return _jsonable_udp_metadata ( udp , full = True , user = user )
1757
+ return udp . to_api_dict ( full = True , user = user )
1758
1758
1759
1759
raise ProcessGraphNotFoundException (process_graph_id )
1760
1760
1761
1761
@api_endpoint
1762
1762
@blueprint .route ('/process_graphs' , methods = ['GET' ])
1763
1763
@auth_handler .requires_bearer_auth
1764
1764
def udp_list_for_user (user : User ):
1765
- user_udps = backend_implementation .user_defined_processes .get_for_user (user .user_id )
1766
- return {
1767
- 'processes' : [_jsonable_udp_metadata (udp , full = False ) for udp in user_udps ],
1768
- # TODO: pagination links?
1769
- # TODO: allow backend_implementation to define links?
1770
- "links" : [],
1771
- }
1765
+ # TODO #377 pagination support
1766
+ udps = backend_implementation .user_defined_processes .list_for_user (user_id = user .user_id )
1767
+ return jsonify (udps .to_response_dict ())
1772
1768
1773
1769
@api_endpoint
1774
1770
@blueprint .route ('/process_graphs/<process_graph_id>' , methods = ['DELETE' ])
@@ -1779,27 +1775,6 @@ def udp_delete(process_graph_id: str, user: User):
1779
1775
return response_204_no_content ()
1780
1776
1781
1777
1782
- def _jsonable_udp_metadata (metadata : UserDefinedProcessMetadata , full = True , user : User = None ) -> dict :
1783
- """API-version-aware conversion of UDP metadata to jsonable dict"""
1784
- d = metadata .prepare_for_json ()
1785
- if not full :
1786
- # API recommends to limit response size by omitting larger/optional fields
1787
- d = {k : v for k , v in d .items () if k in ["id" , "summary" , "description" , "parameters" , "returns" ]}
1788
- elif metadata .public and user :
1789
- namespace = "u:" + user .user_id
1790
- d ["links" ] = (d .get ("links" ) or []) + [
1791
- {
1792
- "rel" : "canonical" ,
1793
- # TODO: use signed url?
1794
- "href" : url_for (".processes_details" , namespace = namespace , process_id = metadata .id , _external = True ),
1795
- "title" : f"Public URL for user-defined process { metadata .id !r} "
1796
- }
1797
- ]
1798
- elif "public" in d and not d ["public" ]:
1799
- # Don't include non-standard "public" field when false to stay closer to standard API
1800
- del d ["public" ]
1801
-
1802
- return dict_no_none (** d )
1803
1778
1804
1779
1805
1780
def _normalize_collection_metadata (metadata : dict , api_version : ComparableVersion , full = False ) -> dict :
0 commit comments