diff --git a/CHANGELOG.md b/CHANGELOG.md index 06f0c5a..f7a813f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Release Notes for Activity Log -## 1.6.0 - 2023-09-11 +## 1.6.0 - 2023-09-13 ### Added -- Add `viewFiltersPerUser` setting +- Add `viewFilters` setting ## 1.5.4 - 2023-09-09 ### Fixed diff --git a/README.md b/README.md index 5d4bdb7..d464b36 100644 --- a/README.md +++ b/README.md @@ -64,25 +64,25 @@ return [ The `$this` object in this context will be an instance of the request class ([`craft\web\Request`](https://docs.craftcms.com/api/v4/craft-web-request.html)). Only requests satisfying the condition (returning `true`) will be recorded. -### View Filtering per User +### View Filtering While `reqestsFilter` allows you to control which requests are being **recorded** to the database, at times, you may wish to filter some recorded requests from the [**viewable** audit trail](#audit-trail-ui) for specific users, either due to permissions or in order to reduce the cognitive load of parsing unnecessary data. -This can be accomplished using the `viewFiltersPerUser` setting, following the same structure as the example below: +This can be accomplished using the `viewFilters` setting, following the same structure as the example below: ```php -'viewFiltersPerUser'=> [ +'viewFilters'=> [ [ 'users'=>['admin'], // Username(s) of relevant users - 'filters'=>[ // Filters to be applied for said users + 'filters'=>[ // Filters to be applied for said users: 'isCp'=>true, // Only Control Panel requests 'isAction'=>true, // Only Action requests 'isAjax'=>false, // Only page Requests 'siteId'=>1, // or (e.g) [1,2] for multiple sites 'actions'=>[ // Only display those actions - ['user-settings','save-group'] // full action array, can be found under `actionSegments` in `activitylogs` table + ['user-settings','save-group'] // full action array, can be found under `actionSegments` in `activitylog` table ] ] ] ``` -Users not included in any of the array items will be shown the full audit trail. +Users not included in any of the array items will be shown the full audit trail as per usual. ### Action Requests [Controller Actions](https://craftcms.com/docs/4.x/dev/controller-actions.html) are automatically labelled using a naming convention. E.g ["fields","save-group"] will become "Fields Save Group". diff --git a/src/models/Settings.php b/src/models/Settings.php index 5aecbd9..f80c573 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -18,7 +18,7 @@ class Settings extends Model public array $filterPayloadKeys = []; public array $filterPayloadCallbacks = []; - public array $viewFiltersPerUser = []; + public array $viewFilters = []; public function rules(): array { diff --git a/src/services/ApplyFiltersPerViewer.php b/src/services/ApplyFiltersPerViewer.php index d643a23..b2eaa87 100644 --- a/src/services/ApplyFiltersPerViewer.php +++ b/src/services/ApplyFiltersPerViewer.php @@ -72,12 +72,12 @@ private function getFilters($username): array /** @var Settings $settings */ $settings = Plugin::getInstance()->getSettings(); - return $this->getUserFilters($username, $settings->viewFiltersPerUser); + return $this->getUserFilters($username, $settings->viewFilters); } - private function getUserFilters(string $username, array $viewFiltersPerUser) + private function getUserFilters(string $username, array $viewFilters) { - $filters = array_filter($viewFiltersPerUser, function ($record) use ($username) { + $filters = array_filter($viewFilters, function ($record) use ($username) { return in_array($username, $record['users'], true); }); diff --git a/src/services/VueTablesActivityLogRetriever.php b/src/services/VueTablesActivityLogRetriever.php index ab2930c..ddfb433 100644 --- a/src/services/VueTablesActivityLogRetriever.php +++ b/src/services/VueTablesActivityLogRetriever.php @@ -43,7 +43,7 @@ public function retrieve(): array $q->where("[[createdAt]]>='{$start}'"); $q->andWhere("[[createdAt]]<='{$end}'"); - $initialFilters = Plugin::getInstance()->getSettings()->viewFiltersPerUser; + $initialFilters = Plugin::getInstance()->getSettings()->viewFilters; if ($initialFilters) { $q = (new ApplyFiltersPerViewer($q))->apply();