From cb098cb13913209910611d45570c72894e4d2512 Mon Sep 17 00:00:00 2001 From: Niklas Meinzer Date: Sat, 14 Mar 2026 14:55:30 +0100 Subject: [PATCH] Add Readme --- README.md | 27 +++++++++++++++++++ pyproject.toml | 2 +- .../api/dependencies.py | 19 +++++++------ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e69de29..bc14302 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,27 @@ +# Allmende Payment System + +A FastAPI-based payment system for the communal living projects and similar groups. + +## Prerequisites +- [uv](https://docs.astral.sh/uv/) (package and dependency manager) + +## Getting Started + +### 1. Install uv +Ensure `uv` is installed. If not, follow the [official installation guide](https://docs.astral.sh/uv/getting-started/installation/). + +### 2. Initialize the database + +```bash +make reset_db +``` +Resets the database and initializes it with some mock data. + +### 3. Run the Development Server +```bash +uv run fastapi dev src/allmende_payment_system/app.py +``` +A demo user will be created automatically. + +## License +This project is licensed under the [European Union Public Licence (EUPL)](https://joinup.ec.europa.eu/collection/eupl). diff --git a/pyproject.toml b/pyproject.toml index f047b8b..5041f22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ dependencies = [ ] [project.scripts] -allmende-payment-system = "allmende_payment_system:main" +aps = "allmende_payment_system.cli:main" [build-system] requires = ["uv_build>=0.9.2,<0.10.0"] diff --git a/src/allmende_payment_system/api/dependencies.py b/src/allmende_payment_system/api/dependencies.py index 6dac5ee..5362bff 100644 --- a/src/allmende_payment_system/api/dependencies.py +++ b/src/allmende_payment_system/api/dependencies.py @@ -22,18 +22,21 @@ SessionDep = Annotated[Session, Depends(get_session)] async def get_user(request: Request) -> dict: - if username := os.environ.get("APS_username", None): + if "ynh_user" in request.headers: + # if the ynh_user header is present, we assume we're running in YunoHost and use the header values + return { + "username": request.headers["ynh_user"], + "display_name": request.headers["ynh_user_fullname"], + } + + if not "APS_PRODUCTION_MODE" in os.environ: + username = os.environ.get("APS_username", "demo_user") return { "username": username, - "display_name": os.environ.get("APS_display_name", "Missing Display Name"), + "display_name": username, } - if "ynh_user" not in request.headers: - raise HTTPException(status_code=401, detail="Missing ynh_user header") - return { - "username": request.headers["ynh_user"], - "display_name": request.headers["ynh_user_fullname"], - } + raise HTTPException(status_code=401, detail="Missing ynh_user header") async def get_user_object(request: Request, session: SessionDep) -> User: