signebedi / libreforms-fastapi

FastAPI implementation of the libreForms spec
GNU Affero General Public License v3.0
1 stars 1 forks source link

Add support for custom plugins and yaml constructors #278

Open signebedi opened 3 months ago

signebedi commented 3 months ago

We should implement a plugin abstract base class that end users can use to create their own logic. Something like (and I'm making this up right now):

from abc import ABC, abstractmethod

class Plugin(ABC):

    def __init__(self):
        pass

    @abstractmethod
    def setup(self):
        """
        Setup the plugin.
        """
        pass

    @abstractmethod
    def execute(self, data):
        """
        Execute plugin functionality.
        """
        pass

That we store in libreforms_fastapi/utils/plugins.py, and then an app config PLUGIN_PATH that, when set, imports the custom plugin library using sys. We need to think through this a little more.

Originally posted by @signebedi in https://github.com/signebedi/libreforms-fastapi/issues/150#issuecomment-2185255206

signebedi commented 3 months ago

The primary objective here is that end users should be able to pass, first and foremost, additional yaml constructors for the form config. But, it potentially goes beyond that by introducing an abstract interface for more powerful custom logic. If done right, this could also be the basis for visualizations, see #247, unless we prefer to handle those eg. as part of the relational database model, or in their own config file.