Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
112 lines
4.9 KiB
Markdown
112 lines
4.9 KiB
Markdown
# admin-audit-log Specification
|
|
|
|
## Purpose
|
|
|
|
Record who did what in the admin portal: every admin write, chosen sensitive reads and refused attempts, with allow-listed before/after values and no personal data, kept for a configurable retention and readable on the Audit log screen by admins granted `BO_AUDIT_LOG`.
|
|
|
|
## Requirements
|
|
|
|
### Requirement: Admin writes are recorded
|
|
|
|
The system SHALL record an audit event for every state-changing admin API call made with a valid admin token, successful or not, holding the time, admin username, module, readable action code, HTTP method, path template (never the concrete path or query), target id, outcome with HTTP status, and client IP. Sign-in, sign-out, token refresh, forgot-password, own password change from the user menu, and calls without a valid admin token SHALL NOT be recorded.
|
|
|
|
#### Scenario: A user edit is recorded
|
|
|
|
- **WHEN** admin `admin` updates user 4
|
|
- **THEN** an audit event is saved with actor `admin`, module `BO_USERS`, action `USER_UPDATE`, path template `PUT /api/admin/users/{id}`, target `4`, outcome `SUCCESS`, and the client IP
|
|
|
|
#### Scenario: A failed write is recorded
|
|
|
|
- **WHEN** an admin's role update is refused with status 400
|
|
- **THEN** an audit event is saved with outcome `FAILURE` and status 400
|
|
|
|
#### Scenario: Sign-in is not recorded
|
|
|
|
- **WHEN** an admin signs in or signs out
|
|
- **THEN** no audit event is saved
|
|
|
|
#### Scenario: First-login password change is recorded
|
|
|
|
- **WHEN** a new admin sets their password at first login
|
|
- **THEN** an audit event with action `AUTH_FIRST_LOGIN` is saved
|
|
|
|
### Requirement: Refused access is recorded
|
|
|
|
The system SHALL record an audit event with outcome `FAILURE` when a valid admin token is refused by the access check (missing module, super admin required, or pending first-login change).
|
|
|
|
#### Scenario: Missing module
|
|
|
|
- **GIVEN** admin `noevents` has no `BO_EVENTS`
|
|
- **WHEN** `noevents` tries to create an event
|
|
- **THEN** the request is refused with 403
|
|
- **AND** an audit event with actor `noevents`, module `BO_EVENTS` and outcome `FAILURE` is saved
|
|
|
|
### Requirement: Sensitive reads are recorded
|
|
|
|
The system SHALL record an audit event when an admin exports leads, exports event leads, or opens a saved email. Read-only POST calls marked as such SHALL NOT be recorded.
|
|
|
|
#### Scenario: Opening an email
|
|
|
|
- **WHEN** an admin opens email 12
|
|
- **THEN** an audit event with action `EMAIL_VIEW` and target `12` is saved
|
|
|
|
#### Scenario: Lead export
|
|
|
|
- **WHEN** an admin downloads the lead export
|
|
- **THEN** an audit event with action `LEAD_EXPORT` is saved
|
|
|
|
### Requirement: Allow-listed changes
|
|
|
|
The system SHALL attach before and after values only for these fields: a user's role names and enabled flag, a role's granted module codes, and the login-security lockout settings and password rules. For lead and event-lead edits the system SHALL record only the names of the fields that changed, never their values. No audit event SHALL contain a password, token, raw request body, or lead name, phone, email or notes.
|
|
|
|
#### Scenario: Role change on a user
|
|
|
|
- **WHEN** an admin changes user 4's roles from `Sales` to `Sales, Manager`
|
|
- **THEN** the event's changes show roles before `Sales` and after `Sales, Manager`
|
|
|
|
#### Scenario: Lead edit records field names only
|
|
|
|
- **WHEN** an admin changes a lead's phone and notes
|
|
- **THEN** the event's changes list the fields `phone` and `notes`
|
|
- **AND** neither the old nor the new phone or notes appear in the event
|
|
|
|
### Requirement: Recording never blocks the action
|
|
|
|
Recording SHALL be best-effort. A failure to publish or save an audit event MUST NOT change the response of the admin call.
|
|
|
|
#### Scenario: Publish failure
|
|
|
|
- **GIVEN** the audit event cannot be published
|
|
- **WHEN** an admin updates a user
|
|
- **THEN** the update succeeds as usual
|
|
- **AND** the failure is logged
|
|
|
|
### Requirement: Retention
|
|
|
|
The system SHALL delete audit events older than the configured retention period, 730 days by default, on a schedule.
|
|
|
|
#### Scenario: Old events are purged
|
|
|
|
- **WHEN** the purge runs with a retention of 730 days
|
|
- **THEN** events older than 730 days are deleted
|
|
- **AND** newer events are kept
|
|
|
|
### Requirement: Audit log screen
|
|
|
|
The system SHALL let an admin with `BO_AUDIT_LOG` list audit events newest first, paged, filtered by actor, module, action, outcome and date range, and open one event to see its details and changes. An admin without `BO_AUDIT_LOG` SHALL be refused.
|
|
|
|
#### Scenario: Filter by actor
|
|
|
|
- **WHEN** an admin with `BO_AUDIT_LOG` filters the audit log by actor `admin`
|
|
- **THEN** only events by `admin` are listed, newest first
|
|
|
|
#### Scenario: Event detail
|
|
|
|
- **WHEN** an admin opens an event for a role grant change
|
|
- **THEN** the detail shows the event's fields and the modules added and removed
|
|
|
|
#### Scenario: Without the module
|
|
|
|
- **WHEN** an admin without `BO_AUDIT_LOG` calls the audit log API or opens `/audit-log`
|
|
- **THEN** the API answers 403 and the page shows Not authorised
|