feat(audit): add system-wide audit log - #73
Merged
Merged
Conversation
Only per-ticket ticket_activities existed; admin, configuration, security, and user actions outside a ticket were not recorded. Port the Laravel reference AuditLog into the plugin's table-based convention: - add the escalated_audit_logs table (Activator + dbDelta) with actor, action, polymorphic auditable, JSON old/new snapshots, IP + user agent - add the AuditLog model with a single reusable record() helper - add an admin list/filter REST endpoint (GET /admin/audit-logs) gated by the existing audit.view capability - record entries at key mutation sites: settings + webhooks, role grant/revoke, API token create/revoke, 2FA enable/disable, and knowledge base article/category CRUD - bump plugin version to 1.4.0 so maybe_upgrade() creates the table on existing installs No new capabilities are introduced; the Activator capability count is unchanged. Adds WP_UnitTestCase coverage proving each site writes a row and that the admin list returns and filters entries.
mpge
added a commit
that referenced
this pull request
Aug 2, 2026
Only per-ticket ticket_activities existed; admin, configuration, security, and user actions outside a ticket were not recorded. Port the Laravel reference AuditLog into the plugin's table-based convention: - add the escalated_audit_logs table (Activator + dbDelta) with actor, action, polymorphic auditable, JSON old/new snapshots, IP + user agent - add the AuditLog model with a single reusable record() helper - add an admin list/filter REST endpoint (GET /admin/audit-logs) gated by the existing audit.view capability - record entries at key mutation sites: settings + webhooks, role grant/revoke, API token create/revoke, 2FA enable/disable, and knowledge base article/category CRUD - bump plugin version to 1.4.0 so maybe_upgrade() creates the table on existing installs No new capabilities are introduced; the Activator capability count is unchanged. Adds WP_UnitTestCase coverage proving each site writes a row and that the admin list returns and filters entries. Co-authored-by: Matt Gros <mpge@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a system-wide audit log, porting the Laravel reference into this plugin's table-based convention. Previously only per-ticket
ticket_activitiesexisted; admin / configuration / security / user actions outside a ticket were not recorded.Changes
escalated_audit_logstable added toActivator::create_tables()(dbDelta), mirroring the Laravelaudit_logsschema:user_id,action,auditable_type/auditable_id(nullable, for non-model system events), JSONold_values/new_values,ip_address,user_agent,created_at, plus indexes. Plugin version bumped1.3.0→1.4.0somaybe_upgrade()creates the table on existing installs.Escalated\Models\AuditLogfollows the static$wpdbhelper pattern (likeApiToken/TwoFactor), exposing a single reusablerecord()helper reused at every mutation site, plusall()/count()/distinct_actions()/distinct_types()for the admin surface.Audit_Log_Controller(GET /escalated/v1/admin/audit-logs) registered inApi_Bootstrap, gated by the existingescalated_audit_viewcapability. Supports filtering byuser_id,action,auditable_type, and adate_from/date_torange, with pagination.settings.updated(+ webhooks, secrets redacted),user.role_granted/user.role_revoked,api_token.created/api_token.deleted,two_factor.enabled/two_factor.disabled, andkb_article.*/kb_category.*CRUD.Admin_Settingswas refactored to extract a testablepersist()method.Notes
audit.viewslug; the Activator capability-count assertion (54) is unchanged.get_current_user_id()is 0 under token auth.Tests
New
Test_Audit_Log(18 tests) proves each mutation site writes a row and that the admin list returns and filters entries (auth gating, action/user/type/date filters).Test_Activatorupdated to assert the new table. Full suite green on a fresh DB: 409 tests, 0 failures (4 pre-existing skips).