Skip to content

Commit 2090421

Browse files
committed
Further eliminate UserDefinedProcesses.get_for_user usage
for Open-EO/openeo-aggregator#125 and related to #377
1 parent beaea85 commit 2090421

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

openeo_driver/backend.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ def prepare_for_json(self) -> dict:
638638

639639
def to_api_dict(self, full=True, user: User = None) -> dict:
640640
"""API-version-aware conversion of UDP metadata to jsonable dict"""
641+
# TODO: avoid coupling with user object through argument: make it a property of the UDP object, or generalize to namespace
641642
d = self.prepare_for_json()
642643
if not full:
643644
# API recommends to limit response size by omitting larger/optional fields
@@ -666,12 +667,13 @@ class UserDefinedProcessesListing:
666667
def __init__(self, udps: List[UserDefinedProcessMetadata]):
667668
self._udps = udps
668669

669-
def to_response_dict(self) -> dict:
670+
def to_response_dict(self, *, full: bool = False, target_version: Optional[str] = None, user: User = None) -> dict:
670671
"""
671672
Produce `GET /process_graphs` response data, to be JSONified.
672673
"""
673674
return {
674-
"processes": [udp.to_api_dict(full=False) for udp in self._udps],
675+
"version": target_version,
676+
"processes": [udp.to_api_dict(full=full, user=user) for udp in self._udps],
675677
"links": [],
676678
}
677679

@@ -701,9 +703,12 @@ def list_for_user(
701703
self,
702704
user_id: str,
703705
pagination: Optional[PaginationRequest] = None,
706+
public_only: bool = False,
704707
) -> UserDefinedProcessesListing:
705708
# TODO: remove this adapter implementation once `get_for_user` is removed
706709
udps = self.get_for_user(user_id=user_id)
710+
if public_only:
711+
udps = [udp for udp in udps if udp.public]
707712
return UserDefinedProcessesListing(udps=udps)
708713

709714
def save(self, user_id: str, process_id: str, spec: dict) -> None:

openeo_driver/views.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -755,14 +755,18 @@ def processes():
755755
def processes_from_namespace(namespace):
756756
# TODO: this endpoint is in draft at the moment
757757
# see https://github.com/Open-EO/openeo-api/issues/310, https://github.com/Open-EO/openeo-api/pull/348
758-
# TODO: convention for user namespace? use '@' instead of "u:"
759758
# TODO: unify with `/processes` endpoint?
759+
# TODO #377 pagination?
760+
_log.warning(f"Usage of non-standard endpoint `/processes/{namespace}`")
760761
full = smart_bool(request.args.get("full", False))
761762
target_version = None
763+
# TODO: convention for user namespace? use '@' instead of "u:"
762764
if namespace.startswith("u:") and backend_implementation.user_defined_processes:
763765
user_id = namespace.partition("u:")[-1]
764-
user_udps = [p for p in backend_implementation.user_defined_processes.get_for_user(user_id) if p.public]
765-
processes = [udp.to_api_dict(full=full, user=User(user_id=user_id)) for udp in user_udps]
766+
udp_listing = backend_implementation.user_defined_processes.list_for_user(user_id, public_only=True)
767+
response = udp_listing.to_response_dict(
768+
full=full, target_version=target_version, user=User(user_id=user_id)
769+
)
766770
elif ":" not in namespace:
767771
process_registry = backend_implementation.processing.get_process_registry(
768772
api_version=requested_api_version()
@@ -777,7 +781,6 @@ def processes_from_namespace(namespace):
777781
]
778782
else:
779783
raise OpenEOApiException("Could not handle namespace {n!r}".format(n=namespace))
780-
# TODO: pagination links?
781784
return jsonify(
782785
{
783786
"version": target_version,
@@ -1766,7 +1769,7 @@ def udp_get(process_graph_id: str, user: User):
17661769
def udp_list_for_user(user: User):
17671770
pagination = PaginationRequest.from_request(request=flask.request)
17681771
udps = backend_implementation.user_defined_processes.list_for_user(user_id=user.user_id, pagination=pagination)
1769-
return jsonify(udps.to_response_dict())
1772+
return jsonify(udps.to_response_dict(full=False, user=user))
17701773

17711774
@api_endpoint
17721775
@blueprint.route('/process_graphs/<process_graph_id>', methods=['DELETE'])

0 commit comments

Comments
 (0)