Added basic permission viewing stuff.
This commit is contained in:
parent
7fd2a8d286
commit
33df85b980
7 changed files with 284 additions and 18 deletions
70
public/manage/forum.php
Normal file
70
public/manage/forum.php
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?php
|
||||||
|
use Misuzu\Database;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../misuzu.php';
|
||||||
|
|
||||||
|
switch ($_GET['v'] ?? null) {
|
||||||
|
case 'listing':
|
||||||
|
$forums = Database::query('SELECT * FROM `msz_forum_categories`');
|
||||||
|
|
||||||
|
echo tpl_render('manage.forum.listing', compact('forums'));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'forum':
|
||||||
|
$getForum = Database::prepare('
|
||||||
|
SELECT *
|
||||||
|
FROM `msz_forum_categories`
|
||||||
|
WHERE `forum_id` = :forum_id
|
||||||
|
');
|
||||||
|
$getForum->bindValue('forum_id', (int)($_GET['f'] ?? 0));
|
||||||
|
$forum = $getForum->execute() ? $getForum->fetch(PDO::FETCH_ASSOC) : false;
|
||||||
|
|
||||||
|
if (!$forum) {
|
||||||
|
echo render_error(404);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$roles = Database::query('SELECT `role_id`, `role_name` FROM `msz_roles`')->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
$perms = manage_forum_perms_list(forum_perms_get_role_raw($forum['forum_id'], null));
|
||||||
|
|
||||||
|
echo tpl_render('manage.forum.forum', compact('forum', 'roles', 'perms'));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'forumperms':
|
||||||
|
$getRole = Database::prepare('
|
||||||
|
SELECT `role_id`, `role_name`
|
||||||
|
FROM `msz_roles`
|
||||||
|
WHERE `role_id` = :role_id
|
||||||
|
');
|
||||||
|
$getRole->bindValue('role_id', (int)($_GET['r'] ?? 0));
|
||||||
|
$role = $getRole->execute() ? $getRole->fetch(PDO::FETCH_ASSOC) : false;
|
||||||
|
|
||||||
|
if (!$role) {
|
||||||
|
echo render_error(404);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$forumId = empty($_GET['f']) ? null : (int)($_GET['f'] ?? 0);
|
||||||
|
|
||||||
|
if ($forumId) {
|
||||||
|
$getForum = Database::prepare('
|
||||||
|
SELECT `forum_name`
|
||||||
|
FROM `msz_forum_categories`
|
||||||
|
WHERE `forum_id` = :forum_id
|
||||||
|
');
|
||||||
|
$getForum->bindValue('forum_id', $forumId);
|
||||||
|
$forum = $getForum->execute() ? $getForum->fetch(PDO::FETCH_ASSOC) : false;
|
||||||
|
|
||||||
|
if (!$forum) {
|
||||||
|
echo render_error(404);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
tpl_var('forum', $forum);
|
||||||
|
}
|
||||||
|
|
||||||
|
$perms = manage_forum_perms_list(forum_perms_get_role_raw($forumId, $role['role_id']));
|
||||||
|
|
||||||
|
echo tpl_render('manage.forum.forumperms', compact('role', 'perms'));
|
||||||
|
break;
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ function forum_perms_get_keys(): array
|
||||||
return $perms;
|
return $perms;
|
||||||
}
|
}
|
||||||
|
|
||||||
function forum_perms_create(): int
|
function forum_perms_create(): array
|
||||||
{
|
{
|
||||||
$perms = [];
|
$perms = [];
|
||||||
|
|
||||||
|
@ -131,28 +131,34 @@ function forum_perms_get_user_raw(?int $forum, int $user): array
|
||||||
return $perms;
|
return $perms;
|
||||||
}
|
}
|
||||||
|
|
||||||
function forum_perms_get_role_raw(?int $forum, int $role): array
|
function forum_perms_get_role_raw(?int $forum, ?int $role): array
|
||||||
{
|
{
|
||||||
$emptyPerms = forum_perms_create();
|
$emptyPerms = forum_perms_create();
|
||||||
|
|
||||||
if ($role < 1) {
|
if ($role < 1 && $role !== null) {
|
||||||
return $emptyPerms;
|
return $emptyPerms;
|
||||||
}
|
}
|
||||||
|
|
||||||
$getPerms = Database::prepare(sprintf('
|
$getPerms = Database::prepare(sprintf(
|
||||||
|
'
|
||||||
SELECT
|
SELECT
|
||||||
`' . implode('`, `', forum_perms_get_keys()) . '`
|
`' . implode('`, `', forum_perms_get_keys()) . '`
|
||||||
FROM `msz_forum_permissions`
|
FROM `msz_forum_permissions`
|
||||||
WHERE `forum_id` %s
|
WHERE `forum_id` %s
|
||||||
AND `user_id` IS NULL
|
AND `user_id` IS NULL
|
||||||
AND `role_id` = :role_id
|
AND `role_id` %s
|
||||||
', $forum === null ? 'IS NULL' : '= :forum_id'));
|
',
|
||||||
|
$forum === null ? 'IS NULL' : '= :forum_id',
|
||||||
|
$role === null ? 'IS NULL' : '= :role_id'
|
||||||
|
));
|
||||||
|
|
||||||
if ($forum !== null) {
|
if ($forum !== null) {
|
||||||
$getPerms->bindValue('forum_id', $forum);
|
$getPerms->bindValue('forum_id', $forum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($role !== null) {
|
||||||
$getPerms->bindValue('role_id', $role);
|
$getPerms->bindValue('role_id', $role);
|
||||||
|
}
|
||||||
|
|
||||||
if (!$getPerms->execute()) {
|
if (!$getPerms->execute()) {
|
||||||
return $emptyPerms;
|
return $emptyPerms;
|
||||||
|
|
160
src/manage.php
160
src/manage.php
|
@ -55,15 +55,11 @@ function manage_get_menu(int $userId): array
|
||||||
}
|
}
|
||||||
|
|
||||||
if (perms_check($perms['forum'], MSZ_PERM_FORUM_MANAGE_FORUMS)) {
|
if (perms_check($perms['forum'], MSZ_PERM_FORUM_MANAGE_FORUMS)) {
|
||||||
$menu['Forums']['Listing'] = '/manage/forums.php?v=listing';
|
$menu['Forum']['Listing'] = '/manage/forum.php?v=listing';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (perms_check($perms['forum'], 0)) {
|
if (perms_check($perms['forum'], 0)) {
|
||||||
$menu['Forums']['Permissions'] = '/manage/forums.php?v=permissions';
|
$menu['Forum']['Settings'] = '/manage/forum.php?v=settings';
|
||||||
}
|
|
||||||
|
|
||||||
if (perms_check($perms['forum'], 0)) {
|
|
||||||
$menu['Forums']['Settings'] = '/manage/forums.php?v=settings';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (perms_check($perms['changelog'], MSZ_PERM_CHANGELOG_MANAGE_CHANGES)) {
|
if (perms_check($perms['changelog'], MSZ_PERM_CHANGELOG_MANAGE_CHANGES)) {
|
||||||
|
@ -442,3 +438,155 @@ function manage_perms_list(array $rawPerms): array
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function manage_forum_perms_list(array $rawPerms): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'section' => 'forum',
|
||||||
|
'title' => 'Forum',
|
||||||
|
'perms' => [
|
||||||
|
[
|
||||||
|
'section' => 'can-list',
|
||||||
|
'title' => 'Can see the forum listed, but not access it.',
|
||||||
|
'perm' => MSZ_FORUM_PERM_LIST_FORUM,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_LIST_FORUM,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-view',
|
||||||
|
'title' => 'Can view and access the forum.',
|
||||||
|
'perm' => MSZ_FORUM_PERM_VIEW_FORUM,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_VIEW_FORUM,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-create-topic',
|
||||||
|
'title' => 'Can create topics.',
|
||||||
|
'perm' => MSZ_FORUM_PERM_CREATE_TOPIC,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_CREATE_TOPIC,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-delete-topic',
|
||||||
|
'title' => 'Can delete topics (required a post delete permission).',
|
||||||
|
'perm' => MSZ_FORUM_PERM_DELETE_TOPIC,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_DELETE_TOPIC,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-move-topic',
|
||||||
|
'title' => 'Can move topics between forums.',
|
||||||
|
'perm' => MSZ_FORUM_PERM_MOVE_TOPIC,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_MOVE_TOPIC,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-lock-topic',
|
||||||
|
'title' => 'Can lock topics.',
|
||||||
|
'perm' => MSZ_FORUM_PERM_LOCK_TOPIC,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_LOCK_TOPIC,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-sticky-topic',
|
||||||
|
'title' => 'Can make topics sticky.',
|
||||||
|
'perm' => MSZ_FORUM_PERM_STICKY_TOPIC,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_STICKY_TOPIC,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-announce-topic',
|
||||||
|
'title' => 'Can make topics announcements.',
|
||||||
|
'perm' => MSZ_FORUM_PERM_ANNOUNCE_TOPIC,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_ANNOUNCE_TOPIC,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-global-announce-topic',
|
||||||
|
'title' => 'Can make topics global announcements.',
|
||||||
|
'perm' => MSZ_FORUM_PERM_GLOBAL_ANNOUNCE_TOPIC,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_GLOBAL_ANNOUNCE_TOPIC,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-create-post',
|
||||||
|
'title' => 'Can make posts (reply only, if create topic is disallowed).',
|
||||||
|
'perm' => MSZ_FORUM_PERM_CREATE_POST,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_CREATE_POST,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-edit-post',
|
||||||
|
'title' => 'Can edit their own posts.',
|
||||||
|
'perm' => MSZ_FORUM_PERM_EDIT_POST,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_EDIT_POST,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-edit-any-post',
|
||||||
|
'title' => 'Can edit any posts.',
|
||||||
|
'perm' => MSZ_FORUM_PERM_EDIT_ANY_POST,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_EDIT_ANY_POST,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-delete-post',
|
||||||
|
'title' => 'Can delete own posts.',
|
||||||
|
'perm' => MSZ_FORUM_PERM_DELETE_POST,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_DELETE_POST,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'section' => 'can-delete-any-post',
|
||||||
|
'title' => 'Can delete any posts.',
|
||||||
|
'perm' => MSZ_FORUM_PERM_DELETE_ANY_POST,
|
||||||
|
'value' => manage_perms_value(
|
||||||
|
MSZ_FORUM_PERM_DELETE_ANY_POST,
|
||||||
|
$rawPerms['forum_perms_allow'],
|
||||||
|
$rawPerms['forum_perms_deny']
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
25
templates/manage/forum/forum.twig
Normal file
25
templates/manage/forum/forum.twig
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{% extends 'manage/users/master.twig' %}
|
||||||
|
{% from 'manage/macros.twig' import permissions_table %}
|
||||||
|
|
||||||
|
{% block manage_content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="container__title">{{ forum.forum_name }}</div>
|
||||||
|
<div class="container__content">
|
||||||
|
<form action="" method="get">
|
||||||
|
<input type="hidden" name="v" value="forumperms">
|
||||||
|
<input type="hidden" name="f" value="{{ forum.forum_id }}">
|
||||||
|
<select name="r" class="input__select">
|
||||||
|
{% for role in roles %}
|
||||||
|
<option value="{{ role.role_id }}">{{ role.role_name }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<button class="input__button">Manage permissions</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="container__title">Base Permissions</div>
|
||||||
|
{{ permissions_table(perms) }}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
9
templates/manage/forum/forumperms.twig
Normal file
9
templates/manage/forum/forumperms.twig
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends 'manage/users/master.twig' %}
|
||||||
|
{% from 'manage/macros.twig' import permissions_table %}
|
||||||
|
|
||||||
|
{% block manage_content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="container__title">{{ forum is defined ? forum.forum_name ~ ' ' : '' }}Permissions for {{ role.role_name }}</div>
|
||||||
|
{{ permissions_table(perms) }}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
7
templates/manage/forum/listing.twig
Normal file
7
templates/manage/forum/listing.twig
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{% extends 'manage/users/master.twig' %}
|
||||||
|
|
||||||
|
{% block manage_content %}
|
||||||
|
{% for forum in forums %}
|
||||||
|
<a href="?v=forum&f={{ forum.forum_id }}">{{ forum.forum_name }}</a><br>
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
1
templates/manage/forum/master.twig
Normal file
1
templates/manage/forum/master.twig
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{% extends 'manage/forum/master.twig' %}
|
Loading…
Add table
Reference in a new issue