Skip to content

Commit

Permalink
add viewFilters setting
Browse files Browse the repository at this point in the history
  • Loading branch information
matfish3 committed Sep 13, 2023
1 parent 360620d commit 1ebb5e7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
2 changes: 1 addition & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Settings extends Model
public array $filterPayloadKeys = [];
public array $filterPayloadCallbacks = [];

public array $viewFiltersPerUser = [];
public array $viewFilters = [];

public function rules(): array
{
Expand Down
6 changes: 3 additions & 3 deletions src/services/ApplyFiltersPerViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
2 changes: 1 addition & 1 deletion src/services/VueTablesActivityLogRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1ebb5e7

Please sign in to comment.