Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3']
php: ['8.1', '8.2', '8.3', '8.4']

steps:
- name: Checkout
Expand Down
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,60 @@ data_dog_audit:

You can specify either audited or unaudited entities. If both are specified, only audited entities would be taken into account.

### Specify Audited Entities with specific fields (extends version)

The new configuration has been expanded with fields that can be set as excluded or highlighted.

```php
class Test {
private string $name;
private bool $noImportant;
private \DateTime $createdAt;
private \DateTime $modifiedAt;
}
```

When we only want to audit a few fields:
```yaml
data_dog_audit:
entities:
App\Entity\Test:
mode: include
fields:
- name
- createdAt
- modifiedAt
```
OR
```yaml
data_dog_audit:
entities:
App\Entity\Test:
mode: exclude
fields:
- noImportant
```

The old logic was also included in the new configuration:

If we want to audit everything on an entity
```yaml
data_dog_audit:
entities:
App\Entity\Test:
mode: include
fields: ~
```

If we want to exclude an entity
```yaml
data_dog_audit:
entities:
App\Entity\Test:
mode: exclude
fields: ~
```

### Impersonation

Sometimes, you might also want to blame the `impersonator` user instead of the `impersonated` one.
Expand Down
18 changes: 18 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,33 @@ public function getConfigTreeBuilder(): TreeBuilder
// @formatter:off
$treeBuilder = new TreeBuilder('data_dog_audit');
$treeBuilder->getRootNode()
->validate()
->ifTrue(fn ($v) => !empty($v['entities']) && (!empty($v['audited_entities']) || !empty($v['unaudited_entities'])))
->thenInvalid('If you use the "entities" config you cannot use "audited_entities" and/or "unaudited_entities"')
->end()
->children()
->arrayNode('entities')->canBeUnset()->useAttributeAsKey('key')
->arrayPrototype()
->children()
->enumNode('mode')->values(['include', 'exclude'])->isRequired()->cannotBeEmpty()->end()
->arrayNode('fields')
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
->end()
->children()
->arrayNode('audited_entities')
->setDeprecated('data-dog/audit-bundle', 'v1.2', 'Not setting the "%node%" config option is deprecated. Use the "entities" option instead.')
->canBeUnset()
->performNoDeepMerging()
->scalarPrototype()->end()
->end()
->end()
->children()
->arrayNode('unaudited_entities')
->setDeprecated('data-dog/audit-bundle', 'v1.2', 'Not setting the "%node%" config option is deprecated. Use the "entities" option instead.')
->canBeUnset()
->performNoDeepMerging()
->scalarPrototype()->end()
Expand Down
14 changes: 8 additions & 6 deletions src/DependencyInjection/DataDogAuditExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@ class DataDogAuditExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader->load('services.php');

$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$auditListener = $container->getDefinition('data_dog_audit.listener.audit');

if (isset($config['audited_entities']) && !empty($config['audited_entities'])) {
$auditListener->addMethodCall('addAuditedEntities', array($config['audited_entities']));
} else if (isset($config['unaudited_entities'])) {
$auditListener->addMethodCall('addUnauditedEntities', array($config['unaudited_entities']));
if (isset($config['entities'])) {
$auditListener->addMethodCall('addEntities', [$config['entities']]);
} elseif (isset($config['audited_entities']) && !empty($config['audited_entities'])) {
$auditListener->addMethodCall('addAuditedEntities', [$config['audited_entities']]);
} elseif (isset($config['unaudited_entities'])) {
$auditListener->addMethodCall('addUnauditedEntities', [$config['unaudited_entities']]);
}

if (isset($config['blame_impersonator'])) {
$auditListener->addMethodCall('setBlameImpersonator', array($config['blame_impersonator']));
$auditListener->addMethodCall('setBlameImpersonator', [$config['blame_impersonator']]);
}
}
}
Loading
Loading