[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:
parent
6ad8cd1728
commit
aa8f8f6e64
|
@ -41,9 +41,14 @@ def load_plugins(app: Flask):
|
||||||
for plugin in pluginController.get_enabled_plugins():
|
for plugin in pluginController.get_enabled_plugins():
|
||||||
logger.debug(f"Searching for enabled plugin {plugin.name}")
|
logger.debug(f"Searching for enabled plugin {plugin.name}")
|
||||||
try:
|
try:
|
||||||
|
# Load class
|
||||||
cls = plugin.entry_point.load()
|
cls = plugin.entry_point.load()
|
||||||
if hasattr(cls, "blueprint") and cls.blueprint is not None:
|
plugin = cls.query.get(plugin.id) if plugin.id is not None else plugin
|
||||||
app.register_blueprint(cls.blueprint)
|
# Custom loading tasks
|
||||||
|
plugin.load()
|
||||||
|
# Register blueprint
|
||||||
|
if hasattr(plugin, "blueprint") and plugin.blueprint is not None:
|
||||||
|
app.register_blueprint(plugin.blueprint)
|
||||||
except:
|
except:
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Plugin {plugin.name} was enabled, but could not be loaded due to an 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
|
continue
|
||||||
logger.info(f"Loaded plugin: {plugin.name}")
|
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] = plugin
|
||||||
app.config["FG_PLUGINS"][plugin.name].load()
|
|
||||||
|
|
||||||
|
|
||||||
def create_app(test_config=None, cli=False):
|
def create_app(test_config=None, cli=False):
|
||||||
app = Flask("flaschengeist")
|
app = Flask("flaschengeist")
|
||||||
|
|
|
@ -226,7 +226,7 @@ class AuthPlugin(Plugin):
|
||||||
password: string
|
password: string
|
||||||
|
|
||||||
"""
|
"""
|
||||||
raise MethodNotAllowed
|
raise NotImplementedError
|
||||||
|
|
||||||
def delete_user(self, user):
|
def delete_user(self, user):
|
||||||
"""If backend is using (writeable) external data, then delete the user from external database.
|
"""If backend is using (writeable) external data, then delete the user from external database.
|
||||||
|
@ -235,7 +235,7 @@ class AuthPlugin(Plugin):
|
||||||
user: User object
|
user: User object
|
||||||
|
|
||||||
"""
|
"""
|
||||||
raise MethodNotAllowed
|
raise NotImplementedError
|
||||||
|
|
||||||
def get_avatar(self, user) -> _Avatar:
|
def get_avatar(self, user) -> _Avatar:
|
||||||
"""Retrieve avatar for given user (if supported by auth backend)
|
"""Retrieve avatar for given user (if supported by auth backend)
|
||||||
|
|
Loading…
Reference in New Issue