[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 <rpm@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2022-08-25 17:05:04 +02:00
parent 6ad8cd1728
commit aa8f8f6e64
2 changed files with 10 additions and 7 deletions

View File

@ -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")

View File

@ -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)