diff --git a/lib/galaxy/tours/__init__.py b/lib/galaxy/tours/__init__.py index a59537d794bf..478c0fb05ce5 100644 --- a/lib/galaxy/tours/__init__.py +++ b/lib/galaxy/tours/__init__.py @@ -8,10 +8,8 @@ from pydantic import parse_obj_as from galaxy import util -from galaxy.tours.schema import ( - TourDetails, - TourList, -) +from galaxy.tours import abc +from galaxy.tours.schema import TourList log = logging.getLogger(__name__) @@ -31,12 +29,13 @@ def load_steps(contents_dict): step['title'] = title_default +@abc.ToursRegistry.register class ToursRegistry: def __init__(self, tour_directories): self.tour_directories = util.config_directories_from_setting(tour_directories) self.load_tours() - def tours_by_id_with_description(self) -> TourList: + def tours_by_id_with_description(self): tours = [] for k in self.tours.keys(): tourdata = { @@ -70,7 +69,7 @@ def reload_tour(self, path): if self._is_yaml(filename): self._load_tour_from_path(path) - def tour_contents(self, tour_id) -> TourDetails: + def tour_contents(self, tour_id): # Extra format translation could happen here (like the previous intro_to_tour) # For now just return the loaded contents. return self.tours.get(tour_id, None) diff --git a/lib/galaxy/tours/abc/__init__.py b/lib/galaxy/tours/abc/__init__.py new file mode 100644 index 000000000000..ba0b1f06c5d1 --- /dev/null +++ b/lib/galaxy/tours/abc/__init__.py @@ -0,0 +1,21 @@ +from abc import ABC, abstractmethod + +from galaxy.tours.schema import ( + TourDetails, + TourList, +) + + +class ToursRegistry(ABC): + + @abstractmethod + def tours_by_id_with_description(self) -> TourList: + """Return list of tours.""" + + @abstractmethod + def tour_contents(self, tour_id: str) -> TourDetails: + """Return tour details.""" + + @abstractmethod + def load_tour(self, tour_id: str) -> TourDetails: + """Reload tour and return tour details.""" diff --git a/lib/galaxy/webapps/galaxy/api/__init__.py b/lib/galaxy/webapps/galaxy/api/__init__.py index 4665a075b707..9f0dd36b6d76 100644 --- a/lib/galaxy/webapps/galaxy/api/__init__.py +++ b/lib/galaxy/webapps/galaxy/api/__init__.py @@ -24,6 +24,7 @@ from galaxy.managers.session import GalaxySessionManager from galaxy.managers.users import UserManager from galaxy.model import User +from galaxy.tours.abc import ToursRegistry from galaxy.web.framework.decorators import require_admin_message from galaxy.work.context import SessionRequestContext @@ -85,3 +86,7 @@ def get_admin_user(trans: SessionRequestContext = Depends(get_trans)): if not trans.user_is_admin: raise AdminRequiredException(require_admin_message(trans.app.config, trans.user)) return trans.user + + +def get_tours_registry(app: UniverseApplication = Depends(get_app)) -> ToursRegistry: + return app.tour_registry diff --git a/lib/galaxy/webapps/galaxy/api/tours.py b/lib/galaxy/webapps/galaxy/api/tours.py index f8e9f97228d6..dddcca3a3640 100644 --- a/lib/galaxy/webapps/galaxy/api/tours.py +++ b/lib/galaxy/webapps/galaxy/api/tours.py @@ -7,7 +7,7 @@ from fastapi_utils.cbv import cbv from fastapi_utils.inferring_router import InferringRouter as APIRouter -from galaxy.app import UniverseApplication +from galaxy.tours.abc import ToursRegistry from galaxy.tours.schema import ( TourDetails, TourList, @@ -20,7 +20,7 @@ from galaxy.webapps.base.controller import BaseAPIController from . import ( get_admin_user, - get_app, + get_tours_registry, ) log = logging.getLogger(__name__) @@ -31,22 +31,22 @@ @cbv(router) class FastAPITours: - app: UniverseApplication = Depends(get_app) + registry: ToursRegistry = Depends(get_tours_registry) @router.get('/api/tours') def index(self) -> TourList: """Return list of available tours.""" - return self.app.tour_registry.tours_by_id_with_description() + return self.registry.tours_by_id_with_description() @router.get('/api/tours/{tour_id}') def show(self, tour_id: str) -> TourDetails: """Return a tour definition.""" - return self.app.tour_registry.tour_contents(tour_id) + return self.registry.tour_contents(tour_id) @router.post('/api/tours/{tour_id}', dependencies=[Depends(get_admin_user)]) def update_tour(self, tour_id: str) -> TourDetails: """Return a tour definition.""" - return self.app.tour_registry.load_tour(tour_id) + return self.registry.load_tour(tour_id) class ToursController(BaseAPIController):