Add change history for user entity. #330
This commit is contained in:
parent
eb1ce1a97f
commit
e3cece2165
6 changed files with 131 additions and 5 deletions
|
|
@ -23,6 +23,8 @@ access_keys:
|
||||||
label: User Profile
|
label: User Profile
|
||||||
- id: user.logs
|
- id: user.logs
|
||||||
label: User Logs
|
label: User Logs
|
||||||
|
- id: user.change.history
|
||||||
|
label: User Change History
|
||||||
- id: role
|
- id: role
|
||||||
label: Role Access
|
label: Role Access
|
||||||
acls:
|
acls:
|
||||||
|
|
|
||||||
|
|
@ -49,5 +49,15 @@ user_view_logs_form:
|
||||||
|
|
||||||
user_view_logs:
|
user_view_logs:
|
||||||
path: /user/{id}/logs
|
path: /user/{id}/logs
|
||||||
controller: App\Controller\UserController::getLogs
|
controller: App\Controller\UserController::getAuditLogs
|
||||||
|
methods: [POST]
|
||||||
|
|
||||||
|
user_view_change_history_form:
|
||||||
|
path: /users/{id}/change-history
|
||||||
|
controller: App\Controller\UserController::viewChangeHistoryForm
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
user_view_change_history:
|
||||||
|
path: /user/{id}/change-history
|
||||||
|
controller: App\Controller\UserController::getChangeHistory
|
||||||
methods: [POST]
|
methods: [POST]
|
||||||
|
|
|
||||||
|
|
@ -497,10 +497,10 @@ class UserController extends Controller
|
||||||
$params['id'] = $id;
|
$params['id'] = $id;
|
||||||
|
|
||||||
// response
|
// response
|
||||||
return $this->render('user/log.html.twig', $params);
|
return $this->render('user/audit.log.html.twig', $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogs(Client $client, $id)
|
public function getAuditLogs(Client $client, $id)
|
||||||
{
|
{
|
||||||
// fetch database
|
// fetch database
|
||||||
$log_db = $this->getParameter('log_db');
|
$log_db = $this->getParameter('log_db');
|
||||||
|
|
@ -513,10 +513,40 @@ class UserController extends Controller
|
||||||
// get the points from the resultset, which is an array
|
// get the points from the resultset, which is an array
|
||||||
$points = $result->getPoints();
|
$points = $result->getPoints();
|
||||||
|
|
||||||
// TODO: might need to format time data
|
return $this->json([
|
||||||
|
'data' => $points,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Menu(selected="user_list")
|
||||||
|
*/
|
||||||
|
public function viewChangeHistoryForm($id)
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('user.change.history', null, 'No access.');
|
||||||
|
|
||||||
|
$params['id'] = $id;
|
||||||
|
|
||||||
|
// response
|
||||||
|
return $this->render('user/change.history.log.html.twig', $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getChangeHistory(Client $client, $id)
|
||||||
|
{
|
||||||
|
// fetch database
|
||||||
|
$log_db = $this->getParameter('log_db');
|
||||||
|
$database = $client->selectDB($log_db);
|
||||||
|
|
||||||
|
// query will return a resultset object
|
||||||
|
$query_string = 'SELECT * FROM entity_log WHERE entity_id = \'' . $id . '\'';
|
||||||
|
$result = $database->query($query_string);
|
||||||
|
|
||||||
|
// get the points from the resultset, which is an array
|
||||||
|
$points = $result->getPoints();
|
||||||
|
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'data' => $points,
|
'data' => $points,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
79
templates/user/change.history.log.html.twig
Normal file
79
templates/user/change.history.log.html.twig
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<!-- BEGIN: Subheader -->
|
||||||
|
<div class="m-subheader">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="mr-auto">
|
||||||
|
<h3 class="m-subheader__title">Audit Logs</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- END: Subheader -->
|
||||||
|
<div class="m-content">
|
||||||
|
<!--Begin::Section-->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-12">
|
||||||
|
<div class="m-portlet m-portlet--mobile">
|
||||||
|
<div class="m-portlet__body">
|
||||||
|
<!--begin: Datatable -->
|
||||||
|
<div id="data-rows"></div>
|
||||||
|
<!--end: Datatable -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
console.log( {{ id }} );
|
||||||
|
var options = {
|
||||||
|
data: {
|
||||||
|
type: 'remote',
|
||||||
|
source: {
|
||||||
|
read: {
|
||||||
|
url: '{{ url('user_view_change_history', {'id': id}) }}',
|
||||||
|
method: 'POST'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
saveState: {
|
||||||
|
cookie: false,
|
||||||
|
webstorage: false
|
||||||
|
},
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'time',
|
||||||
|
title: 'Time'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'action',
|
||||||
|
title: 'Action'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'content',
|
||||||
|
title: 'Content'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'entity_id',
|
||||||
|
title: 'Entity ID'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'entity_type',
|
||||||
|
title: 'Entity Type'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'user',
|
||||||
|
title: 'User'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
var table = $("#data-rows").mDatatable(options);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
@ -57,11 +57,16 @@
|
||||||
<div class="form-control-feedback hide" data-field="username"></div>
|
<div class="form-control-feedback hide" data-field="username"></div>
|
||||||
<span class="m-form__help">Unique alias for this user</span>
|
<span class="m-form__help">Unique alias for this user</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-3">
|
||||||
{% if mode == 'update' %}
|
{% if mode == 'update' %}
|
||||||
<a href="{{ url('user_view_logs_form', {'id':obj.getID()}) }}" class="btn btn-success">View Audit Logs</a>
|
<a href="{{ url('user_view_logs_form', {'id':obj.getID()}) }}" class="btn btn-success">View Audit Logs</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-lg-3">
|
||||||
|
{% if mode == 'update' %}
|
||||||
|
<a href="{{ url('user_view_change_history_form', {'id':obj.getID()}) }}" class="btn btn-success">View Change History</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group m-form__group row">
|
<div class="form-group m-form__group row">
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue