First bits of the management side for warnings.

This commit is contained in:
flash 2018-12-27 00:21:44 +01:00
parent dcd2830b40
commit 306690c8a7
7 changed files with 175 additions and 51 deletions

View file

@ -9,6 +9,7 @@ tpl_vars([
'can_manage_users' => $canManageUsers = perms_check($userPerms, MSZ_PERM_USER_MANAGE_USERS),
'can_manage_roles' => $canManageRoles = perms_check($userPerms, MSZ_PERM_USER_MANAGE_ROLES),
'can_manage_perms' => $canManagePerms = perms_check($userPerms, MSZ_PERM_USER_MANAGE_PERMS),
'can_manage_warns' => $canManageWarnings = perms_check($userPerms, MSZ_PERM_USER_MANAGE_WARNINGS),
]);
switch ($_GET['v'] ?? null) {
@ -461,4 +462,25 @@ switch ($_GET['v'] ?? null) {
echo tpl_render('manage.users.role');
break;
case 'warnings':
if (!$canManageWarnings) {
echo render_error(403);
break;
}
$warningsCount = user_warning_global_count();
$warningsTake = 50;
$warningsOffset = max(0, (int)($_GET['o'] ?? 0));
$warningsList = user_warning_global_fetch($warningsOffset, $warningsTake);
echo tpl_render('manage.users.warnings', [
'warnings' => [
'count' => $warningsCount,
'take' => $warningsTake,
'offset' => $warningsOffset,
'list' => $warningsList,
],
]);
break;
}

View file

@ -12,7 +12,7 @@ define('MSZ_PERM_USER_MANAGE_USERS', 1 << 20);
define('MSZ_PERM_USER_MANAGE_ROLES', 1 << 21);
define('MSZ_PERM_USER_MANAGE_PERMS', 1 << 22);
define('MSZ_PERM_USER_MANAGE_REPORTS', 1 << 23);
define('MSZ_PERM_USER_MANAGE_RESTRICTIONS', 1 << 24);
define('MSZ_PERM_USER_MANAGE_WARNINGS', 1 << 24);
//define('MSZ_PERM_USER_MANAGE_BLACKLISTS', 1 << 25); // Replaced with MSZ_PERM_GENERAL_MANAGE_BLACKLIST
define(

View file

@ -88,6 +88,7 @@ function user_warning_fetch(
ON iu.`user_id` = uw.`issuer_id`
WHERE uw.`user_id` = :user_id
%s
ORDER BY uw.`warning_id` DESC
',
$days !== null ? 'AND uw.`warning_created` >= NOW() - INTERVAL :days DAY' : ''
));
@ -100,3 +101,35 @@ function user_warning_fetch(
$warnings = $fetchWarnings->execute() ? $fetchWarnings->fetchAll(PDO::FETCH_ASSOC) : false;
return $warnings ? $warnings : [];
}
function user_warning_global_count(): int
{
$countWarnings = db_query('
SELECT COUNT(`warning_id`)
FROM `msz_user_warnings`
');
return (int)$countWarnings->fetchColumn();
}
function user_warning_global_fetch(int $offset, int $take): array
{
$fetchWarnings = db_prepare('
SELECT
uw.`warning_id`, uw.`warning_created`, uw.`warning_type`, uw.`warning_note`,
uw.`warning_note_private`, uw.`user_id`, uw.`issuer_id`, uw.`warning_duration`,
TIMESTAMPDIFF(SECOND, uw.`warning_created`, uw.`warning_duration`) AS `warning_duration_secs`,
INET6_NTOA(uw.`user_ip`) AS `user_ip`, INET6_NTOA(uw.`issuer_ip`) AS `issuer_ip`,
iu.`username` AS `issuer_username`, wu.`username` AS `username`
FROM `msz_user_warnings` AS uw
LEFT JOIN `msz_users` AS iu
ON iu.`user_id` = uw.`issuer_id`
LEFT JOIN `msz_users` AS wu
ON wu.`user_id` = uw.`user_id`
ORDER BY uw.`warning_id` DESC
LIMIT :offset, :take
');
$fetchWarnings->bindValue('offset', $offset);
$fetchWarnings->bindValue('take', $take);
$warnings = $fetchWarnings->execute() ? $fetchWarnings->fetchAll(PDO::FETCH_ASSOC) : false;
return $warnings ? $warnings : [];
}

View file

@ -43,8 +43,8 @@ function manage_get_menu(int $userId): array
$menu['Users']['Reports'] = '/manage/users.php?v=reports';
}
if (perms_check($perms['user'], MSZ_PERM_USER_MANAGE_RESTRICTIONS)) {
$menu['Users']['Restrictions'] = '/manage/users.php?v=restrictions';
if (perms_check($perms['user'], MSZ_PERM_USER_MANAGE_WARNINGS)) {
$menu['Users']['Warnings'] = '/manage/users.php?v=warnings';
}
if (perms_check($perms['news'], MSZ_PERM_NEWS_MANAGE_POSTS)) {
@ -251,9 +251,9 @@ function manage_perms_list(array $rawPerms): array
'perm' => MSZ_PERM_USER_MANAGE_REPORTS,
],
[
'section' => 'manage-restrictions',
'title' => 'Can manage restrictions.',
'perm' => MSZ_PERM_USER_MANAGE_RESTRICTIONS,
'section' => 'manage-warnings',
'title' => 'Can manage warnings, silences and bans.',
'perm' => MSZ_PERM_USER_MANAGE_WARNINGS,
],
],
],

View file

@ -0,0 +1,64 @@
{% extends 'manage/users/master.twig' %}
{% from 'macros.twig' import pagination, container_title %}
{% from 'user/macros.twig' import user_profile_warning %}
{% block manage_content %}
<div class="container">
{{ container_title('<i class="fas fa-exclamation-circle"></i> Warnings', '', true) }}
{% set warnpag = pagination(warnings.count, warnings.take, warnings.offset, '/manage/users.php?v=warnings') %}
{{ warnpag }}
<div class="profile__warnings__container">
<div class="profile__warning">
<div class="profile__warning__background"></div>
<div class="profile__warning__content">
<div class="profile__warning__type">
Type
</div>
<div class="profile__warning__created">
Created
</div>
<div class="profile__warning__duration">
Expires
</div>
<div class="profile__warning__note">
Note
</div>
</div>
</div>
{% for warning in warnings.list %}
{{ user_profile_warning(warning) }}
{% endfor %}
<div class="profile__warning">
<div class="profile__warning__background"></div>
<div class="profile__warning__content">
<div class="profile__warning__type">
Type
</div>
<div class="profile__warning__created">
Created
</div>
<div class="profile__warning__duration">
Expires
</div>
<div class="profile__warning__note">
Note
</div>
</div>
</div>
</div>
{{ warnpag }}
</div>
{% endblock %}

View file

@ -221,3 +221,51 @@
</div>
</div>
{% endmacro %}
{% macro user_profile_warning(warning, show_private_note) %}
{% if warning.warning_type == constant('MSZ_WARN_SILENCE') %}
{% set warning_text = 'Silence' %}
{% set warning_class = 'silence' %}
{% elseif warning.warning_type == constant('MSZ_WARN_BAN') %}
{% set warning_text = 'Ban' %}
{% set warning_class = 'ban' %}
{% elseif warning.warning_type == constant('MSZ_WARN_WARNING') %}
{% set warning_text = 'Warning' %}
{% set warning_class = 'warning' %}
{% else %}
{% set warning_text = 'Note' %}
{% set warning_class = 'note' %}
{% endif %}
<div class="profile__warning profile__warning--{{ warning_class }}">
<div class="profile__warning__background"></div>
<div class="profile__warning__content">
<div class="profile__warning__type">
{{ warning_text }}
</div>
<time datetime="{{ warning.warning_created|date('c') }}" title="{{ warning.warning_created|date('r') }}" class="profile__warning__created">
{{ warning.warning_created|time_diff }}
</time>
{% if warning.warning_duration_secs > 0 %}
<time datetime="{{ warning.warning_duration|date('c') }}" title="{{ warning.warning_duration|date('r') }}" class="profile__warning__duration">
{{ warning.warning_created|time_diff }}
</time>
{% else %}
<div class="profile__warning__duration"></div>
{% endif %}
<div class="profile__warning__note">
{{ warning.warning_note }}
{% if show_private_note and warning.warning_note_private|length > 0 %}
<div class="profile__warning__private">
{{ warning.warning_note_private|nl2br }}
</div>
{% endif %}
</div>
</div>
</div>
{% endmacro %}

View file

@ -1,5 +1,6 @@
{% extends 'user/master.twig' %}
{% from 'macros.twig' import container_title %}
{% from 'user/macros.twig' import user_profile_warning %}
{% from '_layout/input.twig' import input_hidden, input_csrf, input_text, input_checkbox, input_file, input_file_raw, input_select %}
{% set image = '/profile.php?u=' ~ profile.user_id ~ '&m=avatar' %}
@ -202,51 +203,7 @@
</div>
{% for warning in warnings %}
{% if warning.warning_type == constant('MSZ_WARN_SILENCE') %}
{% set warning_text = 'Silence' %}
{% set warning_class = 'silence' %}
{% elseif warning.warning_type == constant('MSZ_WARN_BAN') %}
{% set warning_text = 'Ban' %}
{% set warning_class = 'ban' %}
{% elseif warning.warning_type == constant('MSZ_WARN_WARNING') %}
{% set warning_text = 'Warning' %}
{% set warning_class = 'warning' %}
{% else %}
{% set warning_text = 'Note' %}
{% set warning_class = 'note' %}
{% endif %}
<div class="profile__warning profile__warning--{{ warning_class }}">
<div class="profile__warning__background"></div>
<div class="profile__warning__content">
<div class="profile__warning__type">
{{ warning_text }}
</div>
<time datetime="{{ warning.warning_created|date('c') }}" title="{{ warning.warning_created|date('r') }}" class="profile__warning__created">
{{ warning.warning_created|time_diff }}
</time>
{% if warning.warning_duration_secs > 0 %}
<time datetime="{{ warning.warning_duration|date('c') }}" title="{{ warning.warning_duration|date('r') }}" class="profile__warning__duration">
{{ warning.warning_created|time_diff }}
</time>
{% else %}
<div class="profile__warning__duration"></div>
{% endif %}
<div class="profile__warning__note">
{{ warning.warning_note }}
{% if can_view_private_note and warning.warning_note_private|length > 0 %}
<div class="profile__warning__private">
{{ warning.warning_note_private|nl2br }}
</div>
{% endif %}
</div>
</div>
</div>
{{ user_profile_warning(warning, can_view_private_note) }}
{% endfor %}
</div>
{% endif %}