mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-04 04:59:41 +00:00
Document audit triggers in ApiController actions
- Added examples to demonstrate how to override the `onAfterFlush` method for triggering audits based on HTTP methods. - Updated developer documentation (`audit.md`) with detailed instructions and code snippets.
This commit is contained in:
@@ -90,6 +90,36 @@ Examples:
|
||||
);
|
||||
```
|
||||
|
||||
### Audits in ApiController
|
||||
|
||||
When using `Chill\MainBundle\CRUD\Controller\ApiController`, the `onAfterFlush` method can be overridden to trigger audits. This method is called after the database operations (flush) are completed.
|
||||
|
||||
Example (based on `AccompanyingCourseWorkApiController`):
|
||||
|
||||
```php
|
||||
protected function onAfterFlush(
|
||||
string $action,
|
||||
Request $request,
|
||||
string $_format,
|
||||
$entity,
|
||||
ConstraintViolationListInterface $errors,
|
||||
array $more = []
|
||||
): ?Response {
|
||||
if (Request::METHOD_GET === $request->getMethod()) {
|
||||
$this->triggerAudit->triggerAudit(AuditTrail::AUDIT_VIEW, $entity);
|
||||
} elseif (Request::METHOD_PUT === $request->getMethod() || Request::METHOD_PATCH === $request->getMethod()) {
|
||||
$this->triggerAudit->triggerAudit(AuditTrail::AUDIT_UPDATE, $entity);
|
||||
} elseif (Request::METHOD_POST === $request->getMethod()) {
|
||||
$this->triggerAudit->triggerAudit(AuditTrail::AUDIT_CREATE, $entity);
|
||||
} elseif (Request::METHOD_DELETE === $request->getMethod()) {
|
||||
$this->triggerAudit->triggerAudit(AuditTrail::AUDIT_DELETE, $entity);
|
||||
} else {
|
||||
throw new \RuntimeException(sprintf('Unsupported HTTP method "%s" for audit trail.', $request->getMethod()));
|
||||
}
|
||||
|
||||
return parent::onAfterFlush($action, $request, $_format, $entity, $errors, $more);
|
||||
}
|
||||
```
|
||||
|
||||
## Use new entities in Audits
|
||||
|
||||
|
||||
Reference in New Issue
Block a user