LuminaWebsite/includes/permissions.php
Maaxxs 77bb1b3ff5 Use real German umlauts instead of ASCII transliterations
Every "oe/ae/ue" spelling throughout the UI text and comments (fuer,
loeschen, koennen, ...) was my own typo, not an encoding bug - the
charset fix in the last commit was unrelated. Replaced all of them
with proper ö/ä/ü across every PHP file and the README.

Also fix table rows rendering inconsistently: `.actions` and the
status badges were applying `display:flex` directly to a <td>, which
fights the table layout model and renders unreliably across browsers.
Moved the flex layout into a wrapper <div> inside each cell instead,
and restyled row-level delete buttons as plain text links so they
match the height of the "Bearbeiten" link exactly. Tables also get a
horizontal-scroll wrapper so narrow viewports scroll instead of
squeezing cell content.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-18 07:16:15 +02:00

49 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
// Feste Kern-Berechtigungen, die das System versteht/pflegt.
// Admins können in der Oberfläche zusätzliche eigene Berechtigungen anlegen,
// die dann z.B. für spätere Features verwendet werden können.
const CORE_PERMISSIONS = [
['key' => 'dashboard.view', 'description' => 'Zugriff auf das Mitglieder-Dashboard'],
['key' => 'admin.access', 'description' => 'Zugriff auf den Admin-Bereich'],
['key' => 'users.view', 'description' => 'Benutzerliste einsehen'],
['key' => 'users.create', 'description' => 'Neue Benutzer anlegen'],
['key' => 'users.edit', 'description' => 'Benutzer bearbeiten'],
['key' => 'users.delete', 'description' => 'Benutzer löschen'],
['key' => 'roles.manage', 'description' => 'Berechtigungsgruppen verwalten'],
];
function user_has_permission(string $key): bool
{
$user = current_user();
if (!$user) {
return false;
}
static $cache = [];
if (array_key_exists($key, $cache)) {
return $cache[$key];
}
$stmt = db()->prepare(
'SELECT COUNT(*) FROM user_roles ur
JOIN role_permissions rp ON rp.role_id = ur.role_id
JOIN permissions p ON p.id = rp.permission_id
WHERE ur.user_id = ? AND p.key = ?'
);
$stmt->execute([$user['id'], $key]);
$cache[$key] = ((int) $stmt->fetchColumn()) > 0;
return $cache[$key];
}
function require_permission(string $key): void
{
require_login();
if (!user_has_permission($key)) {
http_response_code(403);
include __DIR__ . '/forbidden.php';
exit;
}
}