StockManager maintains a persistent audit trail of every significant action performed through the API. Each record captures who performed the action, what entity was affected, the before and after state of that entity, the client IP address, and whether the action succeeded or failed. The audit system is fully automatic — routes opt in by applying theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/InnoDev69/StockManager/llms.txt
Use this file to discover all available pages before exploring further.
@audit_action decorator, and the log is never written directly by business logic.
The @audit_action Decorator
The audit_action decorator from tools/audit_decorator.py wraps a Flask route handler and logs the action both before and after the function executes. For update and delete operations it fetches the entity’s current state before the handler runs, then compares snapshots to produce a human-readable change description.
| Parameter | Type | Description |
|---|---|---|
entity_type | string | The kind of entity being acted on ("user", "product", "sale", "application") |
action_name | string | The action label stored in the log. Defaults to the HTTP method name if omitted. |
id_param | string | Name of the URL keyword argument that holds the entity’s ID (e.g., "user_id"). Used to retrieve before/after snapshots. |
Real Usage Examples
error-status audit entry before re-raising, so failures are captured too.
Logged Entities and Actions
product
product
| Action | Trigger |
|---|---|
create | New product added via POST /api/products |
update | Product fields changed via PUT /api/products/<id> |
delete | Product removed via DELETE /api/products/<id> |
activate | Soft-deleted product re-enabled |
sale
sale
| Action | Trigger |
|---|---|
create | New sale recorded via POST /api/sales |
update | Sale record modified via PUT /api/sales/<id> |
user
user
| Action | Trigger |
|---|---|
create | Admin creates an account via POST /api/users |
update | Account fields changed via PUT /api/users/<id> |
delete | Account disabled (soft delete) via DELETE /api/users/<id> |
login | User authenticates via POST /api/login |
register | User self-registers via POST /api/register |
reset_password | Password-reset code requested |
change_password | Password changed after code verification |
application
application
| Action | Trigger |
|---|---|
approve | Admin approves a pending registration |
reject | Admin rejects a pending registration |
Audit Endpoints
User History
root user can query any user ID.
Query parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
action | string | — | Filter by action name (e.g., login, update) |
from | string | — | ISO 8601 start date/time (inclusive) |
to | string | — | ISO 8601 end date/time (inclusive) |
limit | integer | 50 | Maximum records to return |
offset | integer | 0 | Pagination offset |
Full Audit Log
This endpoint is restricted to
root only. Any other authenticated role receives 403 Forbidden.action, from, to, limit, offset).
Entity Change Trail
old_value and new_value snapshots for each event, making it easy to reconstruct the state of an entity at any point in time. Requires admin or root role.
Response:
Example: Querying Product Changes
The following example retrieves all audit events for product ID 14 and filters forupdate actions only:
Audit Record Fields
Every record in theaudit_log table and every API response includes these fields:
| Field | Description |
|---|---|
id | Auto-incremented log entry ID |
user_id | ID of the user who performed the action (actor_id) |
username | Username of the actor (joined from users) |
action | Action label: create, update, delete, login, etc. |
entity_type | Type of entity affected: user, product, sale, application |
entity_id | Primary key of the affected entity (nullable for session actions) |
description | Human-readable summary of what changed |
timestamp | ISO 8601 datetime of the action |
status | success or error |
old_value and new_value JSON snapshots are stored in the database but only returned by the entity trail endpoint.