Skip to content

Commit c48c0d9

Browse files
committed
Add _copy_hdca_to_library_folder_single method.
This will create and use a LDCA in the library instead of `extracting` all the datasets in the library. IMPORTANT: permissions are not managed yet.
1 parent 9beb340 commit c48c0d9

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

lib/galaxy/webapps/base/controller.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
ExtendedMetadata,
3232
ExtendedMetadataIndex,
3333
HistoryDatasetAssociation,
34+
HistoryDatasetCollectionAssociation,
3435
LibraryDatasetDatasetAssociation,
3536
tags,
3637
)
@@ -518,6 +519,30 @@ def _copy_hdca_to_library_folder(self, trans, hda_manager, from_hdca_id, folder_
518519
ldda_message=ldda_message,
519520
element_identifier=element_identifier) for (element_identifier, hda_id) in hdas]
520521

522+
def _copy_hdca_to_library_folder_single(self, trans, hdca_manager, from_hdca_id, folder_id):
523+
"""
524+
Copies hdca ``from_hcda_id`` to library folder ``folder_id``.
525+
"""
526+
# PRECONDITION: folder_id has already been altered to remove the folder prefix ('F')
527+
528+
hdca = hdca_manager.get_owned(from_hdca_id, trans.user, current_history=trans.history)
529+
folder = self.get_library_folder(trans, folder_id, check_accessible=True)
530+
531+
if folder.parent_library.deleted:
532+
raise exceptions.ObjectAttributeInvalidException('You cannot add datasets into deleted library. Undelete it first.')
533+
if not self.can_current_user_add_to_library_item(trans, folder):
534+
raise exceptions.InsufficientPermissionsException('You do not have proper permissions to add a dataset to this folder,')
535+
536+
ldca = self.copy_hdca_to_library_folder(trans, hdca, folder)
537+
# TODO? ldca.visible = True
538+
# TODO ldca.update_parent_folder_update_times()
539+
trans.sa_session.flush()
540+
ldda_dict = ldca.to_dict()
541+
rval = trans.security.encode_dict_ids(ldda_dict)
542+
# update_time = ldca.update_time.strftime("%Y-%m-%d %I:%M %p")
543+
# rval['update_time'] = update_time
544+
return rval
545+
521546
def _copy_hda_to_library_folder(self, trans, hda_manager, from_hda_id, folder_id, ldda_message='', element_identifier=None):
522547
"""
523548
Copies hda ``from_hda_id`` to library folder ``folder_id``, optionally
@@ -557,7 +582,7 @@ def _copy_hda_to_library_folder(self, trans, hda_manager, from_hda_id, folder_id
557582
rval['update_time'] = update_time
558583
return rval
559584

560-
def copy_hda_to_library_folder(self, trans, hda, library_folder, roles=None, ldda_message='', element_identifier=None):
585+
def copy_hda_to_library_folder(self, trans, hda: HistoryDatasetAssociation, library_folder, roles=None, ldda_message='', element_identifier=None):
561586
# PRECONDITION: permissions for this action on hda and library_folder have been checked
562587
roles = roles or []
563588

@@ -575,6 +600,13 @@ def copy_hda_to_library_folder(self, trans, hda, library_folder, roles=None, ldd
575600
# then finally, re-applies hda -> ldda for missing actions in _apply_hda_permissions_to_ldda??
576601
return ldda
577602

603+
def copy_hdca_to_library_folder(self, trans, hdca: HistoryDatasetCollectionAssociation, library_folder):
604+
# PRECONDITION: permissions for this action on hda and library_folder have been checked
605+
ldca = hdca.to_library_dataset_collection_association(trans, target_folder=library_folder)
606+
# self._apply_library_folder_permissions_to_ldca(trans, library_folder, ldca)
607+
# self._apply_hdca_permissions_to_ldca(trans, hdca, ldca)
608+
return ldca
609+
578610
def _apply_library_folder_permissions_to_ldda(self, trans, library_folder, ldda):
579611
"""
580612
Copy actions/roles from library folder to an ldda (and its library_dataset).

0 commit comments

Comments
 (0)