Improved look of global audit log.
This commit is contained in:
parent
ea744c5d91
commit
84948121bc
6 changed files with 110 additions and 38 deletions
|
@ -71,4 +71,23 @@
|
|||
padding: 1px 5px;
|
||||
}
|
||||
}
|
||||
|
||||
&__user {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
display: flex;
|
||||
padding: 4px;
|
||||
border-bottom: 1px solid var(--accent-colour);
|
||||
margin-bottom: -4px;
|
||||
|
||||
&__avatar {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
&__name {
|
||||
color: var(--user-colour);
|
||||
padding-left: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,11 +15,26 @@ switch ($_GET['v'] ?? null) {
|
|||
break;
|
||||
}
|
||||
|
||||
tpl_var('log_dump', print_r(audit_log_list(0, 50), true));
|
||||
echo tpl_render('manage.general.logs');
|
||||
$logTake = 50;
|
||||
$logOffset = (int)($_GET['o'] ?? 0);
|
||||
$logCount = audit_log_count();
|
||||
$logs = audit_log_list($logOffset, $logTake);
|
||||
|
||||
echo tpl_render('manage.general.logs', [
|
||||
'global_logs' => $logs,
|
||||
'global_logs_take' => $logTake,
|
||||
'global_logs_offset' => $logOffset,
|
||||
'global_logs_count' => $logCount,
|
||||
'global_logs_strings' => MSZ_AUDIT_LOG_STRINGS,
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'quotes':
|
||||
if (!perms_check($generalPerms, MSZ_PERM_GENERAL_VIEW_LOGS)) {
|
||||
echo render_error(403);
|
||||
break;
|
||||
}
|
||||
|
||||
$setId = (int)($_GET['s'] ?? '');
|
||||
$quoteId = (int)($_GET['q'] ?? '');
|
||||
|
||||
|
|
|
@ -152,21 +152,7 @@ $logs = [
|
|||
'amount' => audit_log_count(user_session_current('user_id')),
|
||||
'offset' => max(0, intval($_GET['logs']['offset'] ?? 0)),
|
||||
'take' => clamp($_GET['logs']['take'] ?? 15, 5, 30),
|
||||
'strings' => [
|
||||
'PERSONAL_EMAIL_CHANGE' => 'Changed e-mail address to %s.',
|
||||
'PERSONAL_PASSWORD_CHANGE' => 'Changed account password.',
|
||||
'PERSONAL_SESSION_DESTROY' => 'Ended session #%d.',
|
||||
'PERSONAL_SESSION_DESTROY_ALL' => 'Ended all personal sessions.',
|
||||
'PASSWORD_RESET' => 'Successfully used the password reset form to change password.',
|
||||
'CHANGELOG_ENTRY_CREATE' => 'Created a new changelog entry #%d.',
|
||||
'CHANGELOG_ENTRY_EDIT' => 'Edited changelog entry #%d.',
|
||||
'CHANGELOG_TAG_ADD' => 'Added tag #%2$d to changelog entry #%1$d.',
|
||||
'CHANGELOG_TAG_REMOVE' => 'Removed tag #%2$d from changelog entry #%1$d.',
|
||||
'CHANGELOG_TAG_CREATE' => 'Created new changelog tag #%d.',
|
||||
'CHANGELOG_TAG_EDIT' => 'Edited changelog tag #%d.',
|
||||
'CHANGELOG_ACTION_CREATE' => 'Created new changelog action #%d.',
|
||||
'CHANGELOG_ACTION_EDIT' => 'Edited changelog action #%d.',
|
||||
],
|
||||
'strings' => MSZ_AUDIT_LOG_STRINGS,
|
||||
];
|
||||
|
||||
$sessions['list'] = user_session_list($sessions['offset'], $sessions['take'], user_session_current('user_id'));
|
||||
|
|
|
@ -1,4 +1,21 @@
|
|||
<?php
|
||||
// replace this with a localisation system
|
||||
define('MSZ_AUDIT_LOG_STRINGS', [
|
||||
'PERSONAL_EMAIL_CHANGE' => 'Changed e-mail address to %s.',
|
||||
'PERSONAL_PASSWORD_CHANGE' => 'Changed account password.',
|
||||
'PERSONAL_SESSION_DESTROY' => 'Ended session #%d.',
|
||||
'PERSONAL_SESSION_DESTROY_ALL' => 'Ended all personal sessions.',
|
||||
'PASSWORD_RESET' => 'Successfully used the password reset form to change password.',
|
||||
'CHANGELOG_ENTRY_CREATE' => 'Created a new changelog entry #%d.',
|
||||
'CHANGELOG_ENTRY_EDIT' => 'Edited changelog entry #%d.',
|
||||
'CHANGELOG_TAG_ADD' => 'Added tag #%2$d to changelog entry #%1$d.',
|
||||
'CHANGELOG_TAG_REMOVE' => 'Removed tag #%2$d from changelog entry #%1$d.',
|
||||
'CHANGELOG_TAG_CREATE' => 'Created new changelog tag #%d.',
|
||||
'CHANGELOG_TAG_EDIT' => 'Edited changelog tag #%d.',
|
||||
'CHANGELOG_ACTION_CREATE' => 'Created new changelog action #%d.',
|
||||
'CHANGELOG_ACTION_EDIT' => 'Edited changelog action #%d.',
|
||||
]);
|
||||
|
||||
function audit_log(
|
||||
string $action,
|
||||
int $userId = 0,
|
||||
|
@ -32,8 +49,8 @@ function audit_log_count($userId = 0): int
|
|||
$getCount = db_prepare(sprintf('
|
||||
SELECT COUNT(`log_id`)
|
||||
FROM `msz_audit_log`
|
||||
WHERE %s
|
||||
', $userId < 1 ? '1' : '`user_id` = :user_id'));
|
||||
%s
|
||||
', $userId < 1 ? '' : 'WHERE `user_id` = :user_id'));
|
||||
|
||||
if ($userId >= 1) {
|
||||
$getCount->bindValue('user_id', $userId);
|
||||
|
@ -46,24 +63,28 @@ function audit_log_list(int $offset, int $take, int $userId = 0): array
|
|||
{
|
||||
$offset = max(0, $offset);
|
||||
$take = max(1, $take);
|
||||
$isGlobal = $userId < 1;
|
||||
|
||||
$getLogs = db_prepare(sprintf('
|
||||
SELECT
|
||||
l.`log_id`, l.`log_action`, l.`log_params`, l.`log_created`, l.`log_country`,
|
||||
u.`user_id`, u.`username`,
|
||||
INET6_NTOA(l.`log_ip`) as `log_ip`,
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
|
||||
FROM `msz_audit_log` as l
|
||||
LEFT JOIN `msz_users` as u
|
||||
ON u.`user_id` = l.`user_id`
|
||||
LEFT JOIN `msz_roles` as r
|
||||
ON r.`role_id` = u.`display_role`
|
||||
WHERE %s
|
||||
ORDER BY l.`log_id` DESC
|
||||
LIMIT :offset, :take
|
||||
', $userId < 1 ? '1' : 'l.`user_id` = :user_id'));
|
||||
$getLogs = db_prepare(sprintf(
|
||||
'
|
||||
SELECT
|
||||
l.`log_id`, l.`log_action`, l.`log_params`, l.`log_created`, l.`log_country`,
|
||||
INET6_NTOA(l.`log_ip`) as `log_ip`
|
||||
%2$s
|
||||
FROM `msz_audit_log` as l
|
||||
%1$s
|
||||
ORDER BY l.`log_id` DESC
|
||||
LIMIT :offset, :take
|
||||
',
|
||||
$isGlobal
|
||||
? 'LEFT JOIN `msz_users` as u ON u.`user_id` = l.`user_id` LEFT JOIN `msz_roles` as r ON r.`role_id` = u.`display_role`'
|
||||
: 'WHERE l.`user_id` = :user_id',
|
||||
$isGlobal
|
||||
? ', u.`user_id`, u.`username`, COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`'
|
||||
: ''
|
||||
));
|
||||
|
||||
if ($userId >= 1) {
|
||||
if (!$isGlobal) {
|
||||
$getLogs->bindValue('user_id', $userId);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,31 @@
|
|||
{% extends 'manage/general/master.twig' %}
|
||||
{% from 'macros.twig' import container_title, pagination %}
|
||||
{% from 'user/macros.twig' import user_account_log %}
|
||||
|
||||
{% block manage_content %}
|
||||
<pre>
|
||||
{{ log_dump }}
|
||||
</pre>
|
||||
<div class="container settings__container">
|
||||
{{ container_title('<i class="fas fa-file-alt fa-fw"></i> Global Log', '', true) }}
|
||||
{% set glp = pagination(
|
||||
global_logs_count,
|
||||
global_logs_take,
|
||||
global_logs_offset,
|
||||
url_construct('/manage/index.php', {
|
||||
'v': 'logs',
|
||||
})
|
||||
) %}
|
||||
|
||||
<div class="settings__account-logs">
|
||||
<div class="settings__account-logs__pagination">
|
||||
{{ glp }}
|
||||
</div>
|
||||
|
||||
{% for log in global_logs %}
|
||||
{{ user_account_log(log, global_logs_strings) }}
|
||||
{% endfor %}
|
||||
|
||||
<div class="settings__account-logs__pagination">
|
||||
{{ glp }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -179,6 +179,13 @@
|
|||
|
||||
{% macro user_account_log(data, strings) %}
|
||||
<div class="settings__account-log" id="account-log-{{ data.log_id }}">
|
||||
{% if data.user_id is defined %}
|
||||
<a href="/profile.php?u={{ data.user_id }}" class="settings__account-log__user" style="{{ data.user_colour|html_colour }}">
|
||||
<div class="avatar settings__account-log__user__avatar" style="background-image:url('/profile.php?u={{ data.user_id }}&m=avatar');"></div>
|
||||
<div class="settings__account-log__user__name">{{ data.username }}</div>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<div class="settings__account-log__container">
|
||||
<div class="settings__account-log__important">
|
||||
<div class="flag flag--{{ data.log_country|lower }} settings__login-attempt__flag" title="{{ data.log_country|country_name }}">{{ data.log_country }}</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue