[System] plugins can register a post install routine, for e.g. filling the database.

This commit is contained in:
Ferdinand Thiessen 2021-02-18 12:41:25 +01:00
parent 24418f5bcb
commit 251648e9a4
2 changed files with 11 additions and 1 deletions

View File

@ -50,7 +50,7 @@ def __load_plugins(app):
app.config["FG_AUTH_BACKEND"] = plugin app.config["FG_AUTH_BACKEND"] = plugin
else: else:
del plugin del plugin
else: if plugin:
app.config["FG_PLUGINS"][entry_point.name] = plugin app.config["FG_PLUGINS"][entry_point.name] = plugin
if "FG_AUTH_BACKEND" not in app.config: if "FG_AUTH_BACKEND" not in app.config:
logger.error("No authentication plugin configured or authentication plugin not found") logger.error("No authentication plugin configured or authentication plugin not found")
@ -61,14 +61,18 @@ def install_all():
db.create_all() db.create_all()
db.session.commit() db.session.commit()
installed = []
for name, plugin in current_app.config["FG_PLUGINS"].items(): for name, plugin in current_app.config["FG_PLUGINS"].items():
if not plugin: if not plugin:
logger.debug("Skip disabled plugin {}".format(name)) logger.debug("Skip disabled plugin {}".format(name))
continue continue
logger.info("Install plugin {}".format(name)) logger.info("Install plugin {}".format(name))
plugin.install() plugin.install()
installed.append(plugin)
if plugin.permissions: if plugin.permissions:
roleController.create_permissions(plugin.permissions) roleController.create_permissions(plugin.permissions)
for plugin in installed:
plugin.post_install()
def create_app(test_config=None): def create_app(test_config=None):

View File

@ -44,6 +44,12 @@ class Plugin:
""" """
pass pass
def post_install(self):
"""Fill database or do other stuff
Called after all plugins are installed
"""
pass
def serialize(self): def serialize(self):
"""Serialize a plugin into a dict """Serialize a plugin into a dict