Skip to content

Commit

Permalink
move _create_response function to services
Browse files Browse the repository at this point in the history
  • Loading branch information
arash77 committed Sep 26, 2024
1 parent c55e214 commit 73c6ddc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
22 changes: 4 additions & 18 deletions lib/galaxy/actions/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
safe_relpath,
unsafe_walk,
)
from galaxy.webapps.base.controller import UsesExtendedMetadataMixin

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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.
Expand Down
27 changes: 21 additions & 6 deletions lib/galaxy/webapps/galaxy/services/library_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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.
"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 73c6ddc

Please sign in to comment.