Skip to content

Commit eb7a7e2

Browse files
committed
Add pydantic model for CreateLibraryItemPayload
1 parent aa23303 commit eb7a7e2

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

lib/galaxy/webapps/galaxy/api/folder_contents.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
from typing import (
66
List,
7+
Optional,
78
Tuple,
89
Union,
910
)
@@ -230,6 +231,27 @@ class FolderContainer(BaseModel):
230231
)
231232

232233

234+
class CreateLibraryItemPayload(BaseModel):
235+
from_hda_id: Optional[EncodedDatabaseIdField] = Field(
236+
None,
237+
title="HDA Encoded ID",
238+
description="The encoded identifier of the History Dataset Association instance to add to the library.",
239+
)
240+
ldda_message: Optional[str] = Field(
241+
None,
242+
title="LDDA Message",
243+
description=(
244+
"The new message attribute of the Library Dataset Dataset Association created. "
245+
"Only applies when specifying `from_hda_id`."
246+
),
247+
)
248+
from_hdca_id: Optional[EncodedDatabaseIdField] = Field(
249+
None,
250+
title="HDCA Encoded ID",
251+
description="The encoded identifier of the History Dataset Collection Association instance to add to the library.",
252+
)
253+
254+
233255
# TODO: refactor and remove UsesLibraryMixinItems then move this class to lib/galaxy/managers/folder_contents.py
234256
class FolderContentsService(UsesLibraryMixinItems):
235257
"""Common interface/service logic for interactions with library folder contents in the context of the API.
@@ -250,7 +272,7 @@ def get_object(self, trans, id, class_name, check_ownership=False, check_accessi
250272
"""
251273
return managers_base.get_object(trans, id, class_name, check_ownership=check_ownership, check_accessible=check_accessible, deleted=deleted)
252274

253-
def index(self, trans, folder_id, limit=None, offset=None, search_text=None, include_deleted=False) -> FolderContainer:
275+
def index(self, trans, folder_id: EncodedDatabaseIdField, limit=None, offset=None, search_text=None, include_deleted=False) -> FolderContainer:
254276
"""
255277
Displays a collection (list) of a folder's contents (files and folders). Encoded folder ID is prepended
256278
with 'F' if it is a folder as opposed to a data set which does not have it. Full path is provided in
@@ -395,9 +417,9 @@ def index(self, trans, folder_id, limit=None, offset=None, search_text=None, inc
395417
folder_container = dict(metadata=metadata, folder_contents=folder_contents)
396418
return FolderContainer.parse_obj(folder_container)
397419

398-
def create(self, trans, encoded_folder_id, payload, **kwd):
420+
def create(self, trans, encoded_folder_id: EncodedDatabaseIdField, payload: CreateLibraryItemPayload):
399421
"""
400-
Create a new library file from an HDA.
422+
Create a new library file from an HDA or HDCA.
401423
402424
:param encoded_folder_id: the encoded id of the folder to import dataset(s) to
403425
:type encoded_folder_id: an encoded id string
@@ -408,8 +430,6 @@ def create(self, trans, encoded_folder_id, payload, **kwd):
408430
:type from_hdca_id: encoded id
409431
:param ldda_message: (optional) the new message attribute of the LDDA created
410432
:type ldda_message: str
411-
:param extended_metadata: (optional) dub-dictionary containing any extended metadata to associate with the item
412-
:type extended_metadata: dict
413433
:type payload: dict
414434
415435
:returns: a dictionary describing the new item if ``from_hda_id`` is supplied or a list of
@@ -421,9 +441,9 @@ def create(self, trans, encoded_folder_id, payload, **kwd):
421441
InternalServerError
422442
"""
423443
encoded_folder_id_16 = self.__decode_library_content_id(trans, encoded_folder_id)
424-
from_hda_id = payload.pop('from_hda_id', None)
425-
from_hdca_id = payload.pop('from_hdca_id', None)
426-
ldda_message = payload.pop('ldda_message', '')
444+
from_hda_id = payload.from_hda_id
445+
from_hdca_id = payload.from_hdca_id
446+
ldda_message = payload.ldda_message
427447
try:
428448
if from_hda_id:
429449
decoded_hda_id = self._decode_id(from_hda_id)
@@ -665,4 +685,5 @@ def create(self, trans, encoded_folder_id, payload, **kwd):
665685
InsufficientPermissionsException, ItemAccessibilityException,
666686
InternalServerError
667687
"""
668-
return self.service.create(trans, encoded_folder_id, payload)
688+
create_payload = CreateLibraryItemPayload(**payload)
689+
return self.service.create(trans, encoded_folder_id, create_payload)

0 commit comments

Comments
 (0)