diff --git a/lib/galaxy/actions/library.py b/lib/galaxy/actions/library.py index bad496686aba..a10098da9400 100644 --- a/lib/galaxy/actions/library.py +++ b/lib/galaxy/actions/library.py @@ -25,7 +25,6 @@ safe_relpath, unsafe_walk, ) -from galaxy.webapps.base.controller import UsesExtendedMetadataMixin log = logging.getLogger(__name__) @@ -296,7 +295,7 @@ def _make_library_uploaded_dataset(self, trans, params, name, path, type, librar trans.sa_session.commit() return uploaded_dataset - def _upload_library_dataset(self, trans, payload, library_id): + def _upload_library_dataset(self, trans, payload): is_admin = trans.user_is_admin current_user_roles = trans.get_current_user_roles() folder = trans.sa_session.get(LibraryFolder, payload.folder_id) @@ -314,9 +313,9 @@ def _upload_library_dataset(self, trans, payload, library_id): if error: raise exceptions.RequestParameterInvalidException(message) created_outputs_dict = self._upload_dataset(trans, folder.id, payload) - return self._create_response(trans, payload, created_outputs_dict, library_id) + return created_outputs_dict - def _create_folder(self, trans, payload, library_id): + def _create_folder(self, trans, payload): is_admin = trans.user_is_admin current_user_roles = trans.get_current_user_roles() parent_folder = trans.sa_session.get(LibraryFolder, payload.folder_id) @@ -338,20 +337,7 @@ def _create_folder(self, trans, payload, library_id): # New folders default to having the same permissions as their parent folder trans.app.security_agent.copy_library_permissions(trans, parent_folder, new_folder) new_folder_dict = dict(created=new_folder) - return self._create_response(trans, payload, new_folder_dict, library_id) - - def _create_response(self, trans, payload, output, library_id): - rval = [] - for v in output.values(): - if payload.extended_metadata is not None: - # If there is extended metadata, store it, attach it to the dataset, and index it - extended_metadata = UsesExtendedMetadataMixin - extended_metadata.create_extended_metadata(trans, payload.extended_metadata) - if isinstance(v, trans.app.model.LibraryDatasetDatasetAssociation): - v = v.library_dataset - url = self._url_for(trans, library_id, v.id, payload.create_type) - rval.append(dict(id=v.id, name=v.name, url=url)) - return rval + return new_folder_dict def _create_collection(self, trans, payload, parent): # Not delegating to library_common, so need to check access to parent folder here. diff --git a/lib/galaxy/webapps/galaxy/services/library_contents.py b/lib/galaxy/webapps/galaxy/services/library_contents.py index 4bc2ddc521da..01f421d15b0a 100644 --- a/lib/galaxy/webapps/galaxy/services/library_contents.py +++ b/lib/galaxy/webapps/galaxy/services/library_contents.py @@ -43,7 +43,10 @@ LibraryContentsUpdatePayload, ) from galaxy.security.idencoding import IdEncodingHelper -from galaxy.webapps.base.controller import UsesLibraryMixinItems +from galaxy.webapps.base.controller import ( + UsesExtendedMetadataMixin, + UsesLibraryMixinItems, +) from galaxy.webapps.galaxy.services.base import ServiceBase log = logging.getLogger(__name__) @@ -59,7 +62,7 @@ ] -class LibraryContentsService(ServiceBase, LibraryActions, UsesLibraryMixinItems): +class LibraryContentsService(ServiceBase, LibraryActions, UsesLibraryMixinItems, UsesExtendedMetadataMixin): """ Interface/service shared by controllers for interacting with the contents of a library contents. """ @@ -159,11 +162,11 @@ def create( # Now create the desired content object, either file or folder. if payload.create_type == "file": - rval = self._upload_library_dataset(trans, payload, library_id) - return LibraryContentsCreateFileListResponse(root=rval) + rval = self._upload_library_dataset(trans, payload) + return LibraryContentsCreateFileListResponse(root=self._create_response(trans, payload, rval, library_id)) elif payload.create_type == "folder": - rval = self._create_folder(trans, payload, library_id) - return LibraryContentsCreateFolderListResponse(root=rval) + rval = self._create_folder(trans, payload) + return LibraryContentsCreateFolderListResponse(root=self._create_response(trans, payload, rval, library_id)) elif payload.create_type == "collection": rval = self._create_collection(trans, payload, parent) return LibraryContentsCreateDatasetCollectionResponse(root=rval) @@ -283,3 +286,15 @@ def _traverse(self, trans: ProvidesUserContext, folder, current_user_roles): ld.api_type = "file" rval.append(ld) return rval + + def _create_response(self, trans, payload, output, library_id): + rval = [] + for v in output.values(): + if payload.extended_metadata is not None: + # If there is extended metadata, store it, attach it to the dataset, and index it + self.create_extended_metadata(trans, payload.extended_metadata) + if isinstance(v, trans.app.model.LibraryDatasetDatasetAssociation): + v = v.library_dataset + url = self._url_for(trans, library_id, v.id, payload.create_type) + rval.append(dict(id=v.id, name=v.name, url=url)) + return rval