From aa8f8f6e64ab05bd47fba7788a5b986263bac277 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 25 Aug 2022 17:05:04 +0200 Subject: [PATCH] [core][plugin] Allow blueprints to be set on instance level This ensures blueprints are read from the plugin instance instead of the class, allowing custom routes to be added within the `load()` function. Signed-off-by: Ferdinand Thiessen --- flaschengeist/app.py | 13 ++++++++----- flaschengeist/plugins/__init__.py | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/flaschengeist/app.py b/flaschengeist/app.py index d490965..be7d6fd 100644 --- a/flaschengeist/app.py +++ b/flaschengeist/app.py @@ -41,9 +41,14 @@ def load_plugins(app: Flask): for plugin in pluginController.get_enabled_plugins(): logger.debug(f"Searching for enabled plugin {plugin.name}") try: + # Load class cls = plugin.entry_point.load() - if hasattr(cls, "blueprint") and cls.blueprint is not None: - app.register_blueprint(cls.blueprint) + plugin = cls.query.get(plugin.id) if plugin.id is not None else plugin + # Custom loading tasks + plugin.load() + # Register blueprint + if hasattr(plugin, "blueprint") and plugin.blueprint is not None: + app.register_blueprint(plugin.blueprint) except: logger.error( f"Plugin {plugin.name} was enabled, but could not be loaded due to an error.", @@ -51,9 +56,7 @@ def load_plugins(app: Flask): ) continue logger.info(f"Loaded plugin: {plugin.name}") - app.config["FG_PLUGINS"][plugin.name] = cls.query.get(plugin.id) if plugin.id is not None else plugin - app.config["FG_PLUGINS"][plugin.name].load() - + app.config["FG_PLUGINS"][plugin.name] = plugin def create_app(test_config=None, cli=False): app = Flask("flaschengeist") diff --git a/flaschengeist/plugins/__init__.py b/flaschengeist/plugins/__init__.py index ff53f86..0c38c38 100644 --- a/flaschengeist/plugins/__init__.py +++ b/flaschengeist/plugins/__init__.py @@ -226,7 +226,7 @@ class AuthPlugin(Plugin): password: string """ - raise MethodNotAllowed + raise NotImplementedError def delete_user(self, user): """If backend is using (writeable) external data, then delete the user from external database. @@ -235,7 +235,7 @@ class AuthPlugin(Plugin): user: User object """ - raise MethodNotAllowed + raise NotImplementedError def get_avatar(self, user) -> _Avatar: """Retrieve avatar for given user (if supported by auth backend)