AuditAction.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Domain\Audit;
  4. /**
  5. * Stable string constants for `audit_log.action`. The value is the
  6. * "<entity>.<verb>" pair surfaced in the API and the UI's filter
  7. * dropdown. Kept as constants (not an enum) so adding a new action
  8. * is a one-line patch and so the values can flow through DBAL without
  9. * the enum casting boilerplate.
  10. *
  11. * `entityType` for each action is the prefix before the dot (e.g.
  12. * `reporter.created` -> entity_type=reporter); the helper below maps
  13. * automatically.
  14. */
  15. final class AuditAction
  16. {
  17. public const REPORTER_CREATED = 'reporter.created';
  18. public const REPORTER_UPDATED = 'reporter.updated';
  19. public const REPORTER_DELETED = 'reporter.deleted';
  20. public const CONSUMER_CREATED = 'consumer.created';
  21. public const CONSUMER_UPDATED = 'consumer.updated';
  22. public const CONSUMER_DELETED = 'consumer.deleted';
  23. public const TOKEN_CREATED = 'token.created';
  24. public const TOKEN_REVOKED = 'token.revoked';
  25. public const POLICY_CREATED = 'policy.created';
  26. public const POLICY_UPDATED = 'policy.updated';
  27. public const POLICY_DELETED = 'policy.deleted';
  28. public const CATEGORY_CREATED = 'category.created';
  29. public const CATEGORY_UPDATED = 'category.updated';
  30. public const CATEGORY_DELETED = 'category.deleted';
  31. public const MANUAL_BLOCK_CREATED = 'manual_block.created';
  32. public const MANUAL_BLOCK_DELETED = 'manual_block.deleted';
  33. public const ALLOWLIST_CREATED = 'allowlist.created';
  34. public const ALLOWLIST_DELETED = 'allowlist.deleted';
  35. public const USER_ROLE_CHANGED = 'user.role_changed';
  36. public const OIDC_ROLE_MAPPING_CREATED = 'oidc_role_mapping.created';
  37. public const OIDC_ROLE_MAPPING_DELETED = 'oidc_role_mapping.deleted';
  38. public const JOB_TRIGGERED = 'job.triggered';
  39. public static function entityTypeFor(string $action): string
  40. {
  41. $dot = strpos($action, '.');
  42. return $dot === false ? $action : substr($action, 0, $dot);
  43. }
  44. }