Files
TimeTracker/tests
Dries Peeters 350d7105a2 feat: Add comprehensive audit trail/history tracking system
Implement a complete audit logging system to track all changes made to
tracked entities, providing full compliance and accountability capabilities.

Features:
- Automatic tracking of create, update, and delete operations on 25+ models
- Detailed field-level change tracking with old/new value comparison
- User attribution with IP address, user agent, and request path logging
- Web UI for viewing and filtering audit logs with pagination
- REST API endpoints for programmatic access
- Entity-specific history views
- Comprehensive test coverage (unit, model, route, and smoke tests)

Core Components:
- AuditLog model with JSON-encoded value storage and decoding helpers
- SQLAlchemy event listeners for automatic change detection
- Audit utility module with defensive programming for table existence checks
- Blueprint routes for audit log viewing and API access
- Jinja2 templates for audit log list, detail, and entity history views
- Database migration (044) creating audit_logs table with proper indexes

Technical Implementation:
- Uses SQLAlchemy 'after_flush' event listener to capture changes
- Tracks 25+ models including Projects, Tasks, TimeEntries, Invoices, Clients, Users, etc.
- Excludes sensitive fields (passwords) and system fields (id, timestamps)
- Implements lazy import pattern to avoid circular dependencies
- Graceful error handling to prevent audit logging from breaking core functionality
- Transaction-safe logging that integrates with main application transactions

Fixes:
- Resolved login errors caused by premature transaction commits
- Fixed circular import issues with lazy model loading
- Added table existence checks to prevent errors before migrations
- Improved error handling with debug-level logging for non-critical failures

UI/UX:
- Added "Audit Logs" link to admin dropdown menu
- Organized admin menu into logical sections for better usability
- Filterable audit log views by entity type, user, action, and date range
- Color-coded action badges and side-by-side old/new value display
- Pagination support for large audit log datasets

Documentation:
- Added comprehensive feature documentation
- Included troubleshooting guide and data examples
- Created diagnostic scripts for verifying audit log setup

Testing:
- Unit tests for AuditLog model and value encoding/decoding
- Route tests for all audit log endpoints
- Integration tests for audit logging functionality
- Smoke tests for end-to-end audit trail verification

This implementation provides a robust foundation for compliance tracking
and change accountability without impacting application performance or
requiring code changes in existing routes/models.
2025-11-13 08:08:48 +01:00
..
2025-10-31 17:26:32 +01:00
2025-10-31 17:26:32 +01:00
2025-10-27 17:46:50 +01:00
2025-10-27 17:46:50 +01:00
2025-11-01 08:44:02 +01:00
2025-11-01 09:04:06 +01:00
2025-10-31 19:24:47 +01:00
2025-10-20 21:25:13 +02:00
2025-10-27 17:46:50 +01:00
2025-10-20 21:25:13 +02:00
2025-11-05 13:58:38 +01:00
2025-10-22 11:25:10 +02:00
2025-11-01 10:26:45 +01:00
2025-10-31 19:24:47 +01:00
2025-10-25 08:38:53 +02:00
2025-10-25 08:38:53 +02:00
2025-10-29 18:42:10 +01:00
2025-11-05 13:58:38 +01:00
2025-10-27 17:46:50 +01:00
2025-10-27 17:46:50 +01:00
2025-10-24 15:14:39 +02:00
2025-10-23 14:00:53 +02:00
2025-10-24 18:16:15 +02:00
2025-10-24 18:16:15 +02:00
2025-10-31 19:24:47 +01:00
2025-10-31 14:13:16 +01:00
2025-10-24 15:03:34 +02:00
2025-11-12 09:36:44 +01:00
2025-10-24 15:14:39 +02:00