mirror of
https://github.com/ZTatman/myst.git
synced 2026-11-22 04:47:58 +00:00
style(web): apply ruff formatting and tidy cruft
This commit is contained in:
parent
2123b434d9
commit
9431a5c1b4
8 changed files with 27 additions and 15 deletions
|
|
@ -29,10 +29,7 @@ def encrypt_optional(fernet: Fernet | None, raw_token: str | None) -> str | None
|
||||||
if raw_token is None:
|
if raw_token is None:
|
||||||
return None
|
return None
|
||||||
if fernet is None:
|
if fernet is None:
|
||||||
msg = (
|
msg = "Token encryption is not configured. Set TOKEN_ENCRYPTION_KEY in your .env file or deployment environment."
|
||||||
"Token encryption is not configured. "
|
|
||||||
"Set TOKEN_ENCRYPTION_KEY in your .env file or deployment environment."
|
|
||||||
)
|
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
return encrypt_token(fernet, raw_token)
|
return encrypt_token(fernet, raw_token)
|
||||||
|
|
||||||
|
|
@ -51,9 +48,6 @@ def decrypt_optional(fernet: Fernet | None, encrypted_token: str | None) -> str
|
||||||
if encrypted_token is None:
|
if encrypted_token is None:
|
||||||
return None
|
return None
|
||||||
if fernet is None:
|
if fernet is None:
|
||||||
msg = (
|
msg = "Token encryption is not configured. Set TOKEN_ENCRYPTION_KEY in your .env file or deployment environment."
|
||||||
"Token encryption is not configured. "
|
|
||||||
"Set TOKEN_ENCRYPTION_KEY in your .env file or deployment environment."
|
|
||||||
)
|
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
return decrypt_token(fernet, encrypted_token)
|
return decrypt_token(fernet, encrypted_token)
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ async def revoke_session(
|
||||||
if not firebreak_session:
|
if not firebreak_session:
|
||||||
return
|
return
|
||||||
token_hash = hashlib.sha256(firebreak_session.encode()).hexdigest()
|
token_hash = hashlib.sha256(firebreak_session.encode()).hexdigest()
|
||||||
result = await db.execute(
|
await db.execute(
|
||||||
update(Session)
|
update(Session)
|
||||||
.where(Session.token_hash == token_hash, Session.revoked_at.is_(None))
|
.where(Session.token_hash == token_hash, Session.revoked_at.is_(None))
|
||||||
.values(revoked_at=datetime.now(UTC))
|
.values(revoked_at=datetime.now(UTC))
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ from fastapi import Request
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
|
||||||
async def get_db(request: Request) -> AsyncGenerator[AsyncSession, None]:
|
async def get_db(request: Request) -> AsyncGenerator[AsyncSession]:
|
||||||
"""Yield a request-scoped async database session."""
|
"""Yield a request-scoped async database session."""
|
||||||
|
|
||||||
async with request.app.state.db_session() as session:
|
async with request.app.state.db_session() as session:
|
||||||
yield session
|
yield session
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ class SetupRequiredMiddleware(BaseHTTPMiddleware):
|
||||||
|
|
||||||
async def dispatch(self, request: Request, call_next) -> Response:
|
async def dispatch(self, request: Request, call_next) -> Response:
|
||||||
path = request.url.path
|
path = request.url.path
|
||||||
if path.startswith("/setup") or path.startswith("/static") or path == "/favicon.ico":
|
if path.startswith(("/setup", "/static")) or path == "/favicon.ico":
|
||||||
return await call_next(request)
|
return await call_next(request)
|
||||||
|
|
||||||
if request.app.state.app_settings is None:
|
if request.app.state.app_settings is None:
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,12 @@ class AppSettings(Base):
|
||||||
id: Mapped[int] = mapped_column(primary_key=True, default=1)
|
id: Mapped[int] = mapped_column(primary_key=True, default=1)
|
||||||
forgejo_base_url: Mapped[str] = mapped_column(String, nullable=False)
|
forgejo_base_url: Mapped[str] = mapped_column(String, nullable=False)
|
||||||
forgejo_oauth_client_id: Mapped[str] = mapped_column(String, nullable=False)
|
forgejo_oauth_client_id: Mapped[str] = mapped_column(String, nullable=False)
|
||||||
forgejo_oauth_client_secret_encrypted: Mapped[str] = mapped_column(Text, nullable=False)
|
forgejo_oauth_client_secret_encrypted: Mapped[str] = mapped_column(
|
||||||
firebreak_public_base_url: Mapped[str] = mapped_column(String, nullable=False, default="")
|
Text, nullable=False
|
||||||
|
)
|
||||||
|
firebreak_public_base_url: Mapped[str] = mapped_column(
|
||||||
|
String, nullable=False, default=""
|
||||||
|
)
|
||||||
setup_completed_at: Mapped[datetime.datetime] = mapped_column(
|
setup_completed_at: Mapped[datetime.datetime] = mapped_column(
|
||||||
DateTime(timezone=True), server_default=func.now()
|
DateTime(timezone=True), server_default=func.now()
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,9 @@ class Grant(Base):
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
server_default=func.gen_random_uuid(),
|
server_default=func.gen_random_uuid(),
|
||||||
)
|
)
|
||||||
token_hash: Mapped[str] = mapped_column(String, unique=True, nullable=False, index=True)
|
token_hash: Mapped[str] = mapped_column(
|
||||||
|
String, unique=True, nullable=False, index=True
|
||||||
|
)
|
||||||
user_id: Mapped[uuid.UUID] = mapped_column(
|
user_id: Mapped[uuid.UUID] = mapped_column(
|
||||||
Uuid, ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
Uuid, ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,9 @@ class Session(Base):
|
||||||
user_id: Mapped[uuid.UUID] = mapped_column(
|
user_id: Mapped[uuid.UUID] = mapped_column(
|
||||||
Uuid, ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
Uuid, ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
||||||
)
|
)
|
||||||
token_hash: Mapped[str] = mapped_column(String(64), unique=True, nullable=False, index=True)
|
token_hash: Mapped[str] = mapped_column(
|
||||||
|
String(64), unique=True, nullable=False, index=True
|
||||||
|
)
|
||||||
created_at: Mapped[datetime] = mapped_column(server_default=func.now())
|
created_at: Mapped[datetime] = mapped_column(server_default=func.now())
|
||||||
expires_at: Mapped[datetime] = mapped_column(nullable=False, index=True)
|
expires_at: Mapped[datetime] = mapped_column(nullable=False, index=True)
|
||||||
last_seen_at: Mapped[datetime | None] = mapped_column(nullable=True)
|
last_seen_at: Mapped[datetime | None] = mapped_column(nullable=True)
|
||||||
|
|
|
||||||
|
|
@ -30,15 +30,24 @@ class User(Base):
|
||||||
def has_pat(self) -> bool:
|
def has_pat(self) -> bool:
|
||||||
return self.pat_encrypted is not None
|
return self.pat_encrypted is not None
|
||||||
|
|
||||||
|
# One-to-many relationship with LinkedIdentity: A user could have multiple identitiy providers
|
||||||
|
# LinkedIdentity is a table that stores all the identities of the user
|
||||||
|
# for example, GitHub, GitLab, etc.
|
||||||
identities: Mapped[list[LinkedIdentity]] = relationship(
|
identities: Mapped[list[LinkedIdentity]] = relationship(
|
||||||
back_populates="user",
|
back_populates="user",
|
||||||
cascade="all, delete-orphan",
|
cascade="all, delete-orphan",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# One-to-many relationship with Session: A user could have multiple cross-browser sessions
|
||||||
|
# Session is a table that stores all the possible browser sessions of the user
|
||||||
sessions: Mapped[list[Session]] = relationship(
|
sessions: Mapped[list[Session]] = relationship(
|
||||||
"Session",
|
"Session",
|
||||||
back_populates="user",
|
back_populates="user",
|
||||||
cascade="all, delete-orphan",
|
cascade="all, delete-orphan",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# One-to-many relationship with Grant
|
||||||
|
# Grant is a table that stores all the share links a user creates
|
||||||
grants: Mapped[list[Grant]] = relationship(
|
grants: Mapped[list[Grant]] = relationship(
|
||||||
"Grant",
|
"Grant",
|
||||||
back_populates="user",
|
back_populates="user",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue