C1a: code only, no comments, no Markdown
Remove 64 Python docstrings and 39 comments, and trim prose from three noqa pragmas. The submodule had zero tracked Markdown files. Move published route descriptions into decorator arguments and the Correction schema description into ConfigDict. Drop internal docstrings, including the OAuth callback excluded from OpenAPI. Published route descriptions are unchanged in the before-and-after comparison of the nine application routers. The full application OpenAPI check requires fastapi-users, which is missing from the shared environment.
This commit is contained in:
+3
-17
@@ -1,12 +1,3 @@
|
||||
"""Sign-in for the web app (fastapi-users): users, the domains each may see, and a session
|
||||
cookie. It decides only what the web app shows; no API route requires a session, so
|
||||
pipelines, the FHIR door and scripts answer as before.
|
||||
|
||||
Users live in the platform database (`config.users`). The first administrator comes from
|
||||
AUTH_ADMIN_EMAIL and AUTH_ADMIN_PASSWORD at startup; AUTH_SECRET signs the sessions (without
|
||||
it, one is made and kept in the data folder).
|
||||
"""
|
||||
|
||||
import os
|
||||
import secrets
|
||||
import uuid
|
||||
@@ -38,7 +29,6 @@ class User(SQLAlchemyBaseUserTableUUID, Base):
|
||||
__tablename__ = "users"
|
||||
__table_args__ = {"schema": SCHEMA}
|
||||
name: Mapped[str] = mapped_column(String(120), default="")
|
||||
# the domains the web app shows this user (an administrator sees every one)
|
||||
domains: Mapped[list[str]] = mapped_column(JSON, default=list)
|
||||
|
||||
|
||||
@@ -54,7 +44,6 @@ class UserCreate(schemas.BaseUserCreate):
|
||||
|
||||
@cache
|
||||
def _engine():
|
||||
"""The platform database, opened asynchronously (SQLite: its `config` file attached)."""
|
||||
url = make_url(platform_url())
|
||||
if url.drivername.startswith("sqlite"):
|
||||
engine = create_async_engine(url.set(drivername="sqlite+aiosqlite"))
|
||||
@@ -108,7 +97,7 @@ backend = AuthenticationBackend(
|
||||
transport=CookieTransport(
|
||||
cookie_name="isssteleon_session",
|
||||
cookie_max_age=SESSION_HOURS * 3600,
|
||||
cookie_secure=os.environ.get("AUTH_COOKIE_SECURE", "") == "1", # behind HTTPS
|
||||
cookie_secure=os.environ.get("AUTH_COOKIE_SECURE", "") == "1",
|
||||
cookie_samesite="lax",
|
||||
),
|
||||
get_strategy=lambda: JWTStrategy(secret=_secret(), lifetime_seconds=SESSION_HOURS * 3600),
|
||||
@@ -123,7 +112,7 @@ user_routes.routes[:] = [
|
||||
]
|
||||
router.include_router(user_routes, prefix="/users", tags=["users"])
|
||||
admins_only = [Depends(users.current_user(active=True, superuser=True))]
|
||||
router.include_router( # an administrator adds users
|
||||
router.include_router(
|
||||
users.get_register_router(UserRead, UserCreate),
|
||||
prefix="/users",
|
||||
tags=["users"],
|
||||
@@ -132,9 +121,8 @@ router.include_router( # an administrator adds users
|
||||
|
||||
|
||||
async def first_admin() -> None:
|
||||
"""The users table, and the administrator AUTH_ADMIN_EMAIL names (once)."""
|
||||
async with _engine().begin() as connection:
|
||||
if connection.dialect.name != "sqlite": # SQLite: the attached file is the schema
|
||||
if connection.dialect.name != "sqlite":
|
||||
await connection.execute(text(f"create schema if not exists {SCHEMA}"))
|
||||
await connection.run_sync(Base.metadata.create_all)
|
||||
email, password = os.environ.get("AUTH_ADMIN_EMAIL"), os.environ.get("AUTH_ADMIN_PASSWORD")
|
||||
@@ -152,8 +140,6 @@ async def first_admin() -> None:
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_app: FastAPI) -> AsyncIterator[None]:
|
||||
"""Each API worker starts here; one at a time (a lock in the data folder), so the
|
||||
users table, the first administrator and the session secret are made once."""
|
||||
import fcntl
|
||||
|
||||
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user