From b79aa11180f58fd608269f7869186462dc24e261 Mon Sep 17 00:00:00 2001 From: signebedi Date: Sat, 23 Mar 2024 15:26:15 -0500 Subject: [PATCH] Added: placeholder groups table (#22) --- libreforms_fastapi/utils/pydantic_models.py | 2 +- libreforms_fastapi/utils/sqlalchemy_models.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libreforms_fastapi/utils/pydantic_models.py b/libreforms_fastapi/utils/pydantic_models.py index 5f53198..73a7621 100644 --- a/libreforms_fastapi/utils/pydantic_models.py +++ b/libreforms_fastapi/utils/pydantic_models.py @@ -296,7 +296,7 @@ def get_form_names(config_path=config.FORM_CONFIG_PATH): return form_config.keys() def get_form_config(form_name, config_path=config.FORM_CONFIG_PATH): - """Yields a single config dict for the form name passed""" + """Yields a single config dict for the form name passed, following a factory pattern approach""" # Try to open config_path and if not existent or empty, use example config form_config = example_form_config # Default to example_form_config diff --git a/libreforms_fastapi/utils/sqlalchemy_models.py b/libreforms_fastapi/utils/sqlalchemy_models.py index 9b45664..594fedc 100644 --- a/libreforms_fastapi/utils/sqlalchemy_models.py +++ b/libreforms_fastapi/utils/sqlalchemy_models.py @@ -56,8 +56,18 @@ class TransactionLog(Base): # date = Column(Date, nullable=False, default=lambda: datetime.utcnow().date()) endpoint = Column(String(1000)) remote_addr = Column(String(50), nullable=True) - query_params = Column(String(2000), nullable=True) # Can we find a way to make this a JSON string or similar format? + query_params = Column(String(2000), nullable=True) # Can we find a way to make this a JSON string or similar format? user = relationship("User", back_populates="transaction_log") +# Allow admins to define custom groups, see +# https://github.com/signebedi/libreforms-fastapi/issues/22 +class Group(Base): + __tablename__ = 'group' + id = Column(Integer, primary_key=True) + name = Column(String(1000), unique=True) + permissions = Column(JSON) + + +# Create a custom Signing class from sqlalchemy_signing Signing = create_signing_class(Base, tz_aware_datetime) \ No newline at end of file