Commit 71f18881 authored by davelopez's avatar davelopez
Browse files

Use TagCollection model in TagsManager

parent 5d1ea11d
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
from enum import Enum
from typing import (
    List,
    Optional,
)

@@ -13,6 +12,7 @@ from galaxy.managers.context import ProvidesUserContext
from galaxy.model import ItemTagAssociation
from galaxy.model.tags import GalaxyTagHandlerSession
from galaxy.schema.fields import EncodedDatabaseIdField
from galaxy.schema.schema import TagCollection

taggable_item_names = {item: item for item in ItemTagAssociation.associated_item_names}
# This Enum is generated dynamically and mypy can not statically infer it's real type
@@ -31,7 +31,7 @@ class ItemTagsPayload(BaseModel):
        title="Item class",
        description="The name of the class of the item that will be tagged.",
    )
    item_tags: Optional[List[str]] = Field(
    item_tags: Optional[TagCollection] = Field(
        default=None,
        title="Item tags",
        description="The list of tags that will replace the current tags associated with the item.",
@@ -48,8 +48,8 @@ class TagsManager:
        """Apply a new set of tags to an item; previous tags are deleted."""
        tag_handler = GalaxyTagHandlerSession(trans.sa_session)
        new_tags: Optional[str] = None
        if payload.item_tags and len(payload.item_tags) > 0:
            new_tags = ",".join(payload.item_tags)
        if payload.item_tags and len(payload.item_tags.__root__) > 0:
            new_tags = ",".join(payload.item_tags.__root__)
        item = self._get_item(trans, payload)
        user = trans.user
        tag_handler.delete_item_tags(user, item)