Skip to content

Conversation

@matiasperrone-exo
Copy link

@matiasperrone-exo matiasperrone-exo commented Dec 26, 2025

📝 Summary

This PR implements audit logging capabilities for the UserAction model by adding a dedicated formatter that generates human-readable and contextualized audit log messages.

🎯 Objective

Enable automatic audit logging for all CRUD operations on UserAction entities, providing complete traceability of user actions in the system.

🔧 Changes Made

1. New Audit Formatter

File: app/Audit/ConcreteFormatters/UserActionAuditLogFormatter.php

  • Implements IChildEntityAuditLogFormatter interface
  • Handles three audit scenarios:
    • Creation: Logs new UserAction creation with owner details, realm, and IP address
    • Update: Logs modifications to existing UserAction
    • Deletion: Logs removal with complete context

2. Audit Configuration

File: config/audit_log.php

  • Registers the UserAction model in the audit system
  • Maps the model to the UserActionAuditLogFormatter strategy

📋 Implementation Details

Key Features

  • Type-safe validation: Ensures only UserAction instances are processed
  • Complete context capture:
    • Owner's full name and ID
    • Realm information (with fallback to 'N/A')
    • Source IP address
  • Additional info support: Allows extended context parameters

Code Quality

  • ✅ Follows established codebase patterns
  • ✅ Proper namespace organization
  • ✅ Complete PHPDoc annotations
  • ✅ Consistent indentation (4 spaces)
  • ✅ Apache 2.0 license header updated (2025)

🧪 Testing

  • Unit tests: Passing successfully
  • Linting: No errors
  • Code validation: Approved

🔍 Additional Notes

This implementation follows the audit logging pattern established in the OpenStackID application, ensuring consistency with other existing entity formatters. The formatter provides detailed context for security auditing and compliance of user actions.

📦 Modified Files

  • app/Audit/ConcreteFormatters/UserActionAuditLogFormatter.php (new)
  • config/audit_log.php (updated)

✨ Output Examples

Creation:

A new UserAction which owner is "John Doe (123)", with realm "default" and IP "192.168.1.1" was created.

Update:

An UserAction with ID 456 was changed.

Deletion:

An UserAction with ID 456 which owner is "John Doe (123)", with realm "default" and IP "192.168.1.1" was removed

@matiasperrone-exo matiasperrone-exo self-assigned this Dec 26, 2025
@matiasperrone-exo matiasperrone-exo force-pushed the feat/add-formatter-for-useraction-model branch from 68a5b43 to ba1caf9 Compare December 30, 2025 21:05
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.

3 participants