Skip to content

Commit

Permalink
Modified: api_key is now a foreign key (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
signebedi committed Mar 25, 2024
1 parent a544a69 commit b58905d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
20 changes: 16 additions & 4 deletions libreforms_fastapi/utils/document_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ def __init__(self, form_name, document_id):
message = f"The document with ID '{document_id}' collection '{form_name}' is not deleted and cannot be restored."
super().__init__(message)



class InsufficientPermissions(Exception):
"""Exception raised when attempting to access a document that user lacks permissions for."""
def __init__(self, form_name, document_id, username):
Expand Down Expand Up @@ -205,8 +203,22 @@ def get_document_database(
if use_mongodb:
if not mongodb_uri or mongodb_uri=="":
raise Exception("Please pass a value MongoDB URI")
return ManageMongoDB(form_names_callable, timezone, db_path, use_logger, env)
return ManageTinyDB(form_names_callable, timezone, db_path, use_logger, env)
return ManageMongoDB(
form_names_callable=form_names_callable,
timezone=timezone,
db_path=db_path,
use_logger=use_logger,
env=env,
mongodb_uri=mongodb_uri,
)
# Default to a TinyDB database
return ManageTinyDB(
form_names_callable=form_names_callable,
timezone=timezone,
db_path=db_path,
use_logger=use_logger,
env=env,
)


class ManageDocumentDB(ABC):
Expand Down
3 changes: 1 addition & 2 deletions libreforms_fastapi/utils/sqlalchemy_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class User(Base):
locked_until = Column(DateTime, nullable=True, default=tz_aware_datetime)
last_password_change = Column(DateTime, nullable=True, default=tz_aware_datetime)
failed_login_attempts = Column(Integer, default=0)
# api_key_id = Column(Integer, ForeignKey('signing.id'), nullable=True)
api_key = Column(String(1000), nullable=True, unique=True)
api_key = Column(String(1000), ForeignKey('signing.signature'), nullable=True, unique=True)
# This opt out, if true, will exclude this user's ID and IP from the statistics
# gathered from their usage, see https://github.com/signebedi/gita-api/issues/59.
opt_out = Column(Boolean, nullable=False, default=False)
Expand Down

0 comments on commit b58905d

Please sign in to comment.