"""
API operations on annotations.
"""
import logging
from typing import (
Generic,
Optional,
TypeVar,
)
from galaxy import (
managers,
model,
web,
)
from galaxy.webapps.base.controller import (
UsesExtendedMetadataMixin,
UsesLibraryMixinItems,
UsesStoredWorkflowMixin,
)
from . import (
BaseGalaxyAPIController,
depends,
)
log = logging.getLogger(__name__)
T = TypeVar("T")
[docs]class LibraryDatasetExtendMetadataController(BaseExtendedMetadataController[model.LibraryDatasetDatasetAssociation]):
controller_name = "library_dataset_extended_metadata"
exmeta_item_id = "library_content_id"
def _get_item_from_id(self, trans, idstr, check_writable=True) -> Optional[model.LibraryDatasetDatasetAssociation]:
if check_writable:
item = self.get_library_dataset_dataset_association(trans, idstr)
if trans.app.security_agent.can_modify_library_item(trans.get_current_user_roles(), item):
return item
else:
item = self.get_library_dataset_dataset_association(trans, idstr)
if trans.app.security_agent.can_access_library_item(trans.get_current_user_roles(), item, trans.user):
return item
return None
[docs]class HistoryDatasetExtendMetadataController(BaseExtendedMetadataController[model.HistoryDatasetAssociation]):
controller_name = "history_dataset_extended_metadata"
exmeta_item_id = "history_content_id"
hda_manager: managers.hdas.HDAManager = depends(managers.hdas.HDAManager)
def _get_item_from_id(self, trans, idstr, check_writable=True) -> Optional[model.HistoryDatasetAssociation]:
decoded_idstr = self.decode_id(idstr)
if check_writable:
return self.hda_manager.get_owned(decoded_idstr, trans.user, current_history=trans.history)
else:
hda = self.hda_manager.get_accessible(decoded_idstr, trans.user)
return self.hda_manager.error_if_uploading(hda)