Skip to content

Access logging#6

Draft
fallow64 wants to merge 9 commits intoactive_fieldfrom
access-logging
Draft

Access logging#6
fallow64 wants to merge 9 commits intoactive_fieldfrom
access-logging

Conversation

@fallow64
Copy link

@fallow64 fallow64 commented Mar 9, 2026

Adds access logging to POST/PUT/PATCH/DELETE endpoints

Full list of changes:

  • Modifies the access table to include payload, method, query_string and status
    • If payload is non-JSON, it will be stored as {"raw_body": "utf-8 string"}
    • Note: even non-users who attempt to perform an action are logged. This is easily changeable?
  • Adds a /access_logs route and schema to access logs
  • Removes commit_db_session middleware (FastAPI automatically commits when destroying async_session_maker, lead to funkiness with interacting with the session from a different middleware)
  • Modifies the query parser to handle unix timestamps

Also the target of this PR is active_field just to display the changes made on top of that branch.

Resolves CHTC/chtc-user-ui#43

fallow64 added 3 commits March 6, 2026 14:44
- Remove commit_db_session
- Add status code
- Add /api/access_logs route and schema
- Add datetime-aware logic in query parser
@fallow64 fallow64 changed the base branch from main to active_field March 9, 2026 20:35
@fallow64
Copy link
Author

fallow64 commented Mar 9, 2026

Out of curiosity I'm gonna give copilot a review (note to self: don't ping it or else it will do work...)

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds server-side access logging for state-changing HTTP requests and exposes an admin-only endpoint to query those logs, alongside a schema/migration update to persist richer request metadata and support unix-timestamp filtering.

Changes:

  • Add HTTP middleware to log POST/PUT/PATCH/DELETE requests (method, route, query string, payload, status) into the access table.
  • Introduce /access_logs admin route + AccessGet schema and add tests for access logging behavior.
  • Update query parsing to cast datetime filters from unix timestamps; migrate access.payload to JSONB and add new columns.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
userapp/main.py Adds access-logging middleware that inserts Access rows after request handling.
userapp/core/models/tables.py Expands Access model (method/query_string/status) and changes payload to JSONB.
alembic/versions/a095c68f3ad3_move_access_table_to_use_jsonb_for_.py Migrates access table schema to match new logging fields.
userapp/api/routes/access.py Adds /access_logs admin-only listing endpoint.
userapp/core/schemas/access.py Adds response schema for access-log entries.
userapp/api/routes/init.py Registers the new access router.
userapp/api/routes/security.py Stores auth token data on request.state for middleware access.
userapp/query_parser.py Adds unix-timestamp → datetime casting for filters.
userapp/api/tests/test_access_log.py Adds tests validating logging behavior and access controls.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants