Skip to content

Commit

Permalink
add optioal payload search
Browse files Browse the repository at this point in the history
  • Loading branch information
matfish3 committed Jul 5, 2023
1 parent 4a51963 commit 6c2d34b
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Activity Log

## 1.5.1 - 2023-07-05
### Added
- Add Payload Search (optional field, enable in Settings page)

## 1.5.0 - 2023-06-18
### Fixed
- Do not load natively labeled actions on Actions page
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Data points include:

The user can control which request types to record under the Settings page.

![craft4 test_adminos_settings_plugins_activity-log_site=default](https://user-images.githubusercontent.com/1510460/175233673-87f2f69d-0c45-4b0c-a3d9-7c231026989e.png)
![Screenshot 2023-07-05 122540](https://github.com/matfish2/craft-activity-log/assets/1510460/a0eca755-4351-4e52-8c9d-847a8d38f9ca)

For a more fine-grained control, **on top of** request type settings, you can use the `requestFilter` setting:
1. In you project create a `config/activity-logs.php` file
Expand Down Expand Up @@ -103,6 +103,12 @@ b. Specific: If you only want to filter a certain key from specific requests you
]
```

### Payload Search
By default, searching in request payload is disabled in order to remove unnecessary clutter from the table controls.
You can enable it in the Settings Page.
![Screenshot 2023-07-05 122958](https://github.com/matfish2/craft-activity-log/assets/1510460/5050e149-0872-464c-bc64-e00ff6586666)
Note that you need to press enter or leave the field for the search to be triggered.

### Statistics
![craft4 ddev site_admin_activity-logs_stats (1)](https://user-images.githubusercontent.com/1510460/227717790-51cc3998-f496-4ec3-9346-50e2b443dc14.png)
The statistics page provides some insights gleaned from the raw data.
Expand Down
2 changes: 1 addition & 1 deletion src/ActivityLogAssetBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function init()
// define the relative path to CSS/JS files that should be registered with the page
// when this asset bundle is registered
$this->js = [
'compiled/activity-log.min.js?v=2',
'compiled/activity-log.min.js?v=3',
];

$this->css = [
Expand Down
2 changes: 1 addition & 1 deletion src/assets/compiled/activity-log.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/assets/compiled/activity-log.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ new Vue({
}
},
alwaysShowPerPageSelect: true,
customFilters: ['createdAt', 'actionSegments'],
customFilters: ['createdAt', 'actionSegments','payload'],
filterByColumn: true,
filterable: [
'url',
Expand Down Expand Up @@ -212,6 +212,9 @@ new Vue({
updateDateRange(val) {
Event.$emit('vue-tables.activity-log.filter::createdAt', val)
},
searchPayload(val) {
Event.$emit('vue-tables.activity-log.filter::payload', val)
},
parseQuery(q) {
if (!q) {
return '';
Expand Down
6 changes: 4 additions & 2 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ class Settings extends Model
public bool $recordOnlyActions = false;
public ?\Closure $requestFilter = null;

public bool $enablePayloadSearch = false;

public array $filterPayloadKeys = [];
public array $filterPayloadCallbacks = [];

public function rules() : array
public function rules(): array
{
return [
[['recordSitePageRequests','recordSiteAjaxRequests','recordCpPageRequests','recordCpAjaxRequests','recordOnlyActions'], 'boolean'],
[['recordSitePageRequests', 'recordSiteAjaxRequests', 'recordCpPageRequests', 'recordCpAjaxRequests', 'recordOnlyActions'], 'boolean'],
];
}
}
6 changes: 6 additions & 0 deletions src/services/VueTablesActivityLogRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function retrieve(): array
$action = $req->getQueryParam('actionSegments');
$action = $action ? json_decode($action, true) : null;

$payload = $req->getQueryParam('payload');

$page = $req->getQueryParam('page') ?? 1;
$perPage = $req->getQueryParam('limit');
$orderCol = $req->getQueryParam('orderBy') ?? 'createdAt';
Expand Down Expand Up @@ -68,6 +70,10 @@ public function retrieve(): array
}
}

if ($payload) {
$q->andWhere("[[payload]] LIKE '%$payload%'");
}

$q->orderBy([$orderCol => $orderDir]);

$count = $q->count();
Expand Down
9 changes: 7 additions & 2 deletions src/templates/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
@loaded="loadingTable=false"
url="/{{ craft.app.config.general.cpTrigger }}?action=activity-logs/activity-log/data">
<template slot="beforeLimit">
{% if craft.app.getPlugins().getPlugin('activity-logs').getSettings().enablePayloadSearch %}
<div class="m-2">
<input type="text" placeholder="Search Payload" class="border p-2" @change="searchPayload($event.target.value)">
</div>
{% endif %}
<date-range-picker @selected="updateDateRange"></date-range-picker>
</template>

Expand Down Expand Up @@ -103,11 +108,11 @@
</tr>
<tr class="bg-gray-100">
<th>Is Control Panel?</th>
<td>{!! row.isCp==='1' ? 'Yes' : 'No' !!}</td>
<td>{!! row.isCp === '1' ? 'Yes' : 'No' !!}</td>
</tr>
<tr>
<th>Is AJAX?</th>
<td>{!! row.isAjax==='1' ? 'Yes' : 'No' !!}</td>
<td>{!! row.isAjax === '1' ? 'Yes' : 'No' !!}</td>
</tr>

</tbody>
Expand Down
12 changes: 11 additions & 1 deletion src/templates/settings/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{% set selectedNavItem = 'settings' %}
{% set content %}
<form method="post" accept-charset="UTF-8" data-saveshortcut="">

<h2>Requests</h2>
<hr>
{{ csrfInput() }}

<input type="hidden" name="action" value="activity-logs/settings/save-settings">
Expand Down Expand Up @@ -43,6 +44,15 @@
on: settings.recordOnlyActions
}) }}

<h2>Audit Trail</h2>
<hr>

{{ forms.lightswitchField({
label: 'Enable Payload Search',
name: 'settings[enablePayloadSearch]',
on: settings.enablePayloadSearch
}) }}

<div class="buttons">
<input type="submit" class="btn submit force" value="{{ 'Save'|t('app') }}">
</div>
Expand Down

0 comments on commit 6c2d34b

Please sign in to comment.