1. Nobody approves their own run unless a template allows it. `initiator_may_approve` is now off by default, and a run's settings override may keep or switch on the lock but never lift it (`rules.merge_settings(..., for_run=True)`, 422 `initiator_lock_fixed`). Before, anybody could lay out stages naming only themselves - on a Galena document with no more than read access - and emit `workflow.approved` / `workflow.signed_on_paper`, which Galena moves a contract card on; and a moderator's template lock was undone by the override. The console's start form shows the box off and disabled when the base locks. 2. `round_seen` joins `stage_key_seen` / `stages_seen`. An edit of the request or a rejection on the first stage brings the run back to the same stage key in a new round, so a click prepared before it approved content its author never saw (or overrode a rejection). `assert_current` answers 409 `round_changed`; the console sends the round with every action, the scan and the request edit. Checked when sent, so API clients keep working. Tests: DB-free unit tests for both rules and the API passthrough; the integration tests where the admin approved their own run now use a template that allows it, or another person; one new integration test for the stale click after an edit (Atrium#70). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 KiB
Workflow
A self-hosted management console.
Self-hosted and single-tenant, built on dredd-core — the shared substrate this app family installs as a dependency rather than copies.
What it does
Workflow is the platform's approval-workflow module: an obieg akceptacji (approval run) on a document from Galena, an uploaded file or a request (wniosek), passing through configurable stages until it is approved, signed on paper, rejected or cancelled. A run has 1-10 stages (approval, content review, paper ending), each approved by people, an approver group or — on a Galena document only — a Galena role; a rejection sends the run back to the first or the previous stage as a new round (§5.2a „Ustawienia obiegu”) instead of ending it.
Screens
| Screen | What |
|---|---|
| Pulpit | the /stats tiles: „Czeka na mnie” and „W toku” |
| Czeka na mnie / Moje | runs waiting for my decision / runs I started |
| Archiwum | finished runs I may read; filters (subject kind, request type, person, period) and CSV |
| Nowy wniosek | a request of a moderator-defined type, on the type's default template, another one or own stages |
| Nowy obieg | a run on an uploaded file, or on a Galena document when Galena is configured |
| Szczegóły obiegu | stages, timeline by round with evidence (commit / hash), actions by the can_* flags, add a stage, refresh approvers, paper scan, request edit |
| Ustawienia (moderator) | approver groups, request fields, request types, run templates with the stage editor; archived, never deleted |
| Administracja | users (standalone only) and the audit log |
API (/api/v1)
| Routes | What |
|---|---|
GET /options · POST /files · GET /files/{id} |
Galena on or off · upload a file · download (always an attachment) |
GET/POST /runs · GET /runs/{id} |
start a run (template, changed template or own stages) · detail with timeline and can_* |
POST /runs/{id}/actions · /stages · /scan |
approve / reject / back / cancel / refresh / edit_request · add a stage · paper scan |
GET /inbox · /mine · /archive · /archive.csv |
the lists, counted by the same filters as GET /stats |
GET /notifications · POST /notifications/{id}/read |
the bell |
GET /templates · GET/POST/PATCH /admin/templates |
run templates |
GET /request-types · GET/POST/PATCH /admin/request-types |
request types |
GET /request-fields · GET/POST/PATCH /admin/request-fields |
the request field pool (dredd-core custom_fields) |
GET/POST /requests · GET/PATCH /requests/{id} |
requests (multipart: JSON in data, attachments in files) |
GET/POST/PATCH /admin/groups |
approver groups |
GET /stats |
dredd-core stats_contract tiles |
Every action carries the stage, the round and the stage list it was decided on (stage_key_seen /
round_seen / stages_seen): a click on a run somebody else moved meanwhile is a 409, never a
decision on a run nobody saw - also when the run came back to the same stage in a new round. The
console always sends all three; an API client that leaves out round_seen is not checked on it.
The initiator may not approve their own run unless a template allows it (initiator_may_approve,
off by default). Only a moderator makes templates; the person starting a run may keep that lock or
switch it on, never lift it (422 initiator_lock_fixed).
Standalone, the stack is published on port 8141.
Stack
FastAPI + SQLAlchemy 2 + Alembic + PostgreSQL 16 / 17, Argon2id password hashing, server-side cookie sessions, an append-only audit log enforced by database grants, RFC 9457 Problem Details errors, opt-in OpenTelemetry, and a no-build vanilla-JS console (Open Color palette, Tabler icons, light/dark theme, two languages). Shipped with Docker Compose; the backend is its own edge (no reverse proxy). Apache-2.0, and CI refuses any GPL/AGPL/SSPL dependency.
dredd-core
Identity and sessions, authentication, the access-control resolver, the org tree, the audit
writer, the security primitives, the shared enums and error types, and the engine/session
factories all come from one installed package. backend/requirements.txt pins it by tag:
dredd-core @ git+https://github.com/Alpaq92/dredd-core@v0.24.0
The app-side files that used to hold that code (services/auth.py, models/__init__.py,
security.py, errors.py, … and, in nodes tenancy, services/authz.py) are now thin shims:
they re-export from dredd_core so every call site keeps its import path, and they hold only what
is genuinely this app's — the workflow_pat_ token prefix, the workflow_session cookie,
the settings fed into core's auth policy. Fixing shared behaviour means changing dredd-core, tagging
a release and moving the pin here — never patching a shim.
dredd-core ships models, not migrations: importing it registers its tables on the shared
metadata, and this repo owns its own 0001 (native enum types are created first, then
create_all). A core upgrade that changes the schema needs a new revision here.
It is a private repository. Local installs use your own GitHub credentials; CI authenticates
with a DREDD_CORE_TOKEN repository secret (a fine-grained PAT with read access to
Alpaq92/dredd-core), which the workflow injects before pip install. Without it, the install
step fails with an authentication error.
This app is its own deployment with its own domain data. It shares code with its siblings, not that data: locally it has its own database; in the family's shared managed database it has its own schema and roles, which no sibling's roles can reach.
Identity is the exception, and it is shared on purpose: the family's shape is one platform, one
account, one admin pane — one origin, one module per path, where you sign in once at the hub and
every module resolves the same session. Separate schemas, one roster. As scaffolded this app is
standalone: it serves at the root of its own host with its own accounts, its own sign-in and its
own Users administration, and it keeps running that way whatever the family does. Mounting it under
a path prefix of a shared origin is one setting (ROOT_PATH, empty by default) and no code change.
Joining the platform
Sharing the roster is one more setting, IDENTITY_SCHEMA, plus three steps that are not this app's
to take. Once it is set, app_user, session and module_permission live in a neutral schema the
hub owns and this app reads: there is no password here, the sign-in screen becomes a link to the
hub, creating or re-passwording an account answers 409 pointing there, and app tokens stay listable
and revocable but are minted at the hub. And module_permission is what decides who may open this
app at all — no row for this module is no entry — so the hub is where somebody is admitted to it
and where somebody is made its moderator. Standalone that table is inert: there is one application,
and having an account here is permission to use it. One origin means one cookie, so there is no handoff to
build — no signed assertion, no audience binding, nothing to exchange. A design that adds one for
this topology is over-engineering.
Both shapes are the same code, switched at runtime, and that is the property to defend: the moment they fork, the shape nobody runs locally is the shape that breaks.
The order matters, because only the last of the four steps happens in this repository:
- The platform admin provisions.
db/managed/provision.sql, re-rendered with--identity-schema dredd --identity-owner atrium_migrator(commit it, and add the same flags to CI's--check-filestep — the platform'spush.shrefuses a module whose committed file is not that rendering): the schema,USAGEfor this app's two roles, and asearch_paththat reaches it. A migrator role may do none of those. The kit also setsFRAME_ANCESTORS='self'. - The hub migrates. It owns the schema, so it creates the three tables and grants this app's
roles their tier — a column-restricted
SELECTonapp_userthat does not includepassword_hash,SELECTplus a narrowUPDATEonsession,SELECTand nothing else onmodule_permission, andINSERTon none of them. - A person imports any account this app has and the hub does not. Neither side can do it alone,
by design, so it is a platform-admin step run from a census of every schema's
app_user. alembic upgrade headhere runs0003_shared_identity: it matches this schema's accounts to the shared ones by e-mail address, rewrites every id that names a person, re-points every foreign key, and drops the local copies. Read it before running it on anything you care about. Sessions and app tokens are deliberately not carried over — everybody signs in once more, at the hub.
Two administration tiers come with it, and these are the only two words for them: an administrator is platform-wide and is made in the hub; a moderator administers this module only, is also made in the hub, and is merely read here. Standalone they are the same thing and nothing queries anything.
Quick start
cp .env.example .env # then set the three DB passwords
DREDD_CORE_TOKEN=github_pat_... docker compose up -d --build # postgres -> migrate(+seed) -> backend
Building the image needs
DREDD_CORE_TOKEN(a read-only fine-grained PAT forAlpaq92/dredd-core) in your shell — compose hands it to the build as a BuildKit secret, so it never lands in an image layer. Don't put it in.env: every container loads that file at runtime. CI'scompose-smokejob runs exactly this stack on every push.
Open http://localhost:8141 and sign in with BOOTSTRAP_ADMIN_EMAIL / BOOTSTRAP_ADMIN_PASSWORD.
Windows: write
.envwithout a BOM —[System.IO.File]::WriteAllText("$PWD\.env", (Get-Content .env.example -Raw)). PowerShell'sOut-File -Encoding utf8adds one, and pydantic-settings folds it into the first key name, which produces a baffling "field required" error at startup.
Development
cd backend
python -m venv .venv && . .venv/Scripts/activate # or: source .venv/bin/activate
pip install -r requirements-dev.txt # pulls dredd-core from GitHub — needs repo access
pytest # DB-free unit tests
alembic upgrade head --sql # inspect the DDL without a database
python scripts/license_gate.py # no GPL/AGPL/SSPL
python scripts/deploy_check.py # stack-definition coherence
node --check ../frontend/app.js # the console has no build step, so this is the check
Integration tests need a migrated and seeded Postgres: WORKFLOW_RUN_INTEGRATION=1 pytest.
The console's end-to-end test (tests/e2e/test_console.py, test_expense_happy_path: a moderator
sets up a group, a request type and a two-stage template, a user files a request, stage 1 approves,
stage 2 rejects with a note and the run is back on stage 1) drives a running standalone stack in
Chromium. It is skipped unless Playwright is installed and an address is given:
pip install playwright && playwright install chromium
WORKFLOW_E2E_BASE_URL=http://localhost:8141 pytest tests/e2e -q # + BOOTSTRAP_ADMIN_* if not the defaults
It fails on any script error or server 5xx and saves light and dark screenshots of the run
(WORKFLOW_E2E_SHOTS_DIR, else pytest's tmp_path).
The API is served under /api/v1, with OpenAPI docs at /api/v1/docs.
Deploying on a managed PostgreSQL
The Dredd family can run in one shared managed database (one PostgreSQL 16/17 database at a managed
provider), with Atrium as the hub; Workflow joins it as schema workflow with its own roles
workflow_migrator and workflow_app. The provider hosts only the database — the backend still
runs on your server, with docker compose -f docker-compose.yml -f docker-compose.managed-db.yml up -d --build. The same path works against any PostgreSQL 16/17 whose admin may create roles and schemas.
- Database-wide steps (creating the database, the provider's root CA, keeping the schemas out of
any auto-generated API, TLS enforcement, network restrictions, the connection budget, backups and
point-in-time restore): step 0 of
db/managed/README.md, and in more depth the family runbook in Atrium,deploy/README.md. - Workflow's steps (provisioning with
python -m dredd_core.managed provisionor the rendereddb/managed/provision.sql,.envwithDB_APP_ROLEand the pool knobs, migrate + seed,python -m dredd_core.managed check, restore specifics):db/managed/README.md. - Connect through the provider's pooler in session mode (never a transaction-mode port such as
6543) or directly, as
<role>— or<role>.<tenant>where the pooler wants the tenant in the user name — with?sslmode=verify-full&sslrootcert=/run/certs/db-ca.crt. Never migrate aspostgres. - The TLS rule: a database host that is not local (
"",localhost,127.0.0.1,::1,postgresor aDB_LOCAL_HOSTSentry) must carrysslmode=verify-full, or the app refuses to start.
CI's managed-db job rehearses this path on PostgreSQL 17 without a superuser: it emulates a managed
Postgres (python -m dredd_core.managed emulate), provisions the app next to a sibling, migrates, runs
the integration suite as workflow_app and runs the managed check.
Security model
Two Postgres roles do the heavy lifting. migrator owns DDL and is used only by Alembic; app
is the runtime role and holds DML only. The migration then revokes UPDATE/DELETE on
audit_log from app, which is what makes the audit log evidence rather than a convenience: a
compromised application cannot rewrite its own history, because the database will not let it.
The runtime role's name is configuration (DB_APP_ROLE, app by default): the grants migration
(0002_runtime_grants) grants to it and fails loudly — rolling back — when that role is missing,
when it runs as a superuser or the platform admin, or when a grant did not take. Migrations run as the
migrator and nothing else.
Only the backend is published to the host (:8141) — it serves the console and sets every security
header itself (backend/app/edge.py); Postgres is expose-only. There is no reverse proxy.
Access control lives in exactly one module, backend/app/services/authz.py — a re-export of
dredd_core.authz in nodes tenancy, a local admin/owner check in simple tenancy. No access
returns 404, not 403: a 403 confirms that the record the caller may not see exists.
Project layout
| Path | What |
|---|---|
backend/app/models/ |
this app's ORM entities; __init__.py re-exports dredd-core's |
backend/app/services/ |
every domain rule and all SQL; auth/audit are core shims (authz too, in nodes tenancy) |
backend/app/routers/ |
HTTP shape, validation, authz calls — no SQL |
backend/alembic/ |
0001: enum types → create_all; 0002: runtime grants for DB_APP_ROLE; 0003-0005: shared identity, module_permission, the workflow tables |
backend/tests/ |
DB-free units (always), test_integration* (opt-in), e2e/ (Playwright, opt-in) |
backend/scripts/ |
license gate, deploy pre-flight |
frontend/ |
the console: index.html + app.css + app.js, no bundler |
db/init/ |
least-privilege role creation for the local stack, run once by Postgres |
db/managed/ |
the shared managed database: rendered provision.sql + this app's runbook |
docker-compose.managed-db.yml |
override for a managed database: no local postgres, CA mounted, no migrator in the backend |
License
Apache-2.0. See CREDITS.md for dependencies and design credits.