Admin: switch for unlinking Discord, keep table actions in view
The user list gets a switch "Mitglieder dürfen ihre Discord-Verknüpfung im Profil lösen" (users.edit, default on). Turned off, the profile shows a note instead of the button and discord_unlink.php refuses the request. The value lives in a new settings table, created automatically like the other schema additions (SCHEMA_VERSION 2). The user and group tables were wider than the 1100px content column, so the actions column (edit/delete/approve) scrolled out of view. Both pages now use the wide container and the actions column sticks to the right edge. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
01719dd958
commit
0eb8816ef8
11 changed files with 152 additions and 4 deletions
|
|
@ -143,6 +143,11 @@ Discord-Konto einschaltet, muss dabei gleich ein Passwort setzen. Ein Konto ohne
|
|||
Discord-Verknüpfung braucht den Passwort-Login zwingend. Wer sich nur über Discord anmeldet,
|
||||
kann die Verknüpfung im Profil nicht entfernen und sieht dort kein „Passwort ändern“.
|
||||
|
||||
Ob Mitglieder ihre Discord-Verknüpfung im Profil überhaupt selbst lösen dürfen, legt die
|
||||
Leitung mit dem Schalter oben in der Benutzerverwaltung fest (Berechtigung `users.edit`,
|
||||
Standard: erlaubt). Gespeichert wird das in der Tabelle `settings`, die die Website ebenfalls
|
||||
selbst anlegt.
|
||||
|
||||
#### Berechtigungsgruppen mit Discord-Rollen
|
||||
|
||||
Im Formular einer Berechtigungsgruppe lässt sich eine **Discord-Rolle** auswählen (Liste über
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ try {
|
|||
}
|
||||
|
||||
$pageTitle = 'Berechtigungsgruppen';
|
||||
// Die Tabelle hat viele Spalten - volle Breite statt der schmalen Inhaltsspalte.
|
||||
$containerWide = true;
|
||||
include __DIR__ . '/../includes/header.php';
|
||||
?>
|
||||
<div class="panel">
|
||||
|
|
@ -38,7 +40,7 @@ include __DIR__ . '/../includes/header.php';
|
|||
<p><a class="button" href="/admin/role_form.php">Neue Gruppe anlegen</a></p>
|
||||
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<table class="table-actions">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
|
|
|
|||
20
admin/settings_action.php
Normal file
20
admin/settings_action.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/../includes/bootstrap.php';
|
||||
require_permission('users.edit');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
redirect('/admin/users.php');
|
||||
}
|
||||
verify_csrf();
|
||||
|
||||
$key = (string) ($_POST['setting'] ?? '');
|
||||
if (!array_key_exists($key, SETTINGS_DEFAULTS)) {
|
||||
set_flash('error', 'Unbekannte Einstellung.');
|
||||
redirect('/admin/users.php');
|
||||
}
|
||||
|
||||
// Bisher gibt es nur Ja/Nein-Einstellungen: angehakt = "1", sonst "0".
|
||||
setting_set($key, isset($_POST['value']) ? '1' : '0');
|
||||
|
||||
set_flash('success', 'Einstellung gespeichert.');
|
||||
redirect('/admin/users.php');
|
||||
|
|
@ -26,6 +26,8 @@ $statusLabels = [
|
|||
];
|
||||
|
||||
$pageTitle = 'Benutzerverwaltung';
|
||||
// Die Tabelle hat viele Spalten - volle Breite statt der schmalen Inhaltsspalte.
|
||||
$containerWide = true;
|
||||
include __DIR__ . '/../includes/header.php';
|
||||
?>
|
||||
<div class="panel">
|
||||
|
|
@ -40,8 +42,20 @@ include __DIR__ . '/../includes/header.php';
|
|||
<p><a class="button" href="/admin/user_form.php">Neuen Benutzer anlegen</a></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($canEdit): ?>
|
||||
<form class="settings-toggle" method="post" action="/admin/settings_action.php">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="setting" value="discord_unlink_allowed">
|
||||
<label>
|
||||
<input type="checkbox" name="value" value="1" <?= discord_unlink_allowed() ? 'checked' : '' ?> onchange="this.form.submit()">
|
||||
Mitglieder dürfen ihre Discord-Verknüpfung im Profil lösen
|
||||
</label>
|
||||
<noscript><button type="submit" class="button-secondary button-small">Speichern</button></noscript>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<table class="table-actions">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Benutzername</th>
|
||||
|
|
|
|||
|
|
@ -1997,3 +1997,29 @@ input.role-weight-input {
|
|||
line-height: 1.1rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.settings-toggle {
|
||||
margin: 0 0 1.25rem;
|
||||
padding: 0.75rem 1rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
background: var(--bg-panel-alt);
|
||||
}
|
||||
|
||||
.settings-toggle label { display: flex; align-items: center; gap: 0.5rem; margin: 0; cursor: pointer; }
|
||||
.settings-toggle input { width: auto; }
|
||||
|
||||
/* Tabellen mit Aktionen-Spalte (Verwaltung): die letzte Spalte bleibt rechts angeheftet,
|
||||
damit Bearbeiten/Loeschen/Freischalten auch bei seitlich scrollender Tabelle sichtbar sind. */
|
||||
.table-actions th:last-child,
|
||||
.table-actions td:last-child {
|
||||
position: sticky;
|
||||
right: 0;
|
||||
z-index: 1;
|
||||
background: var(--bg-panel);
|
||||
box-shadow: -8px 0 8px -8px rgba(0, 0, 0, 0.8);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.table-actions tr:hover td:last-child { background: var(--bg-panel-alt); }
|
||||
.table-actions .row-pending td:last-child { background: #2e2a1c; }
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@ verify_csrf();
|
|||
|
||||
$user = current_user();
|
||||
|
||||
if (!discord_unlink_allowed()) {
|
||||
set_flash('error', 'Das Lösen der Discord-Verknüpfung ist derzeit von der Legionsleitung deaktiviert.');
|
||||
redirect('/profile.php');
|
||||
}
|
||||
|
||||
// Ohne Passwort-Login waere das Konto danach nicht mehr erreichbar.
|
||||
if (empty($user['password_login'])) {
|
||||
set_flash('error', 'Du meldest dich nur über Discord an - ohne Verknüpfung kämst du nicht mehr in dein Konto. Lass dir zuerst den Passwort-Login freischalten.');
|
||||
|
|
|
|||
|
|
@ -24,5 +24,6 @@ require_once __DIR__ . '/functions.php';
|
|||
require_once __DIR__ . '/auth.php';
|
||||
require_once __DIR__ . '/permissions.php';
|
||||
require_once __DIR__ . '/schema.php';
|
||||
require_once __DIR__ . '/settings.php';
|
||||
|
||||
ensure_schema();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,22 @@ declare(strict_types=1);
|
|||
*/
|
||||
|
||||
// Hochzaehlen, sobald unten eine Aenderung dazukommt - dann pruefen alle Sitzungen neu.
|
||||
const SCHEMA_VERSION = 1;
|
||||
const SCHEMA_VERSION = 2;
|
||||
|
||||
/**
|
||||
* Tabellen, die nachtraeglich dazugekommen sind: Tabelle => CREATE-Befehl (wie in sql/schema.sql).
|
||||
*/
|
||||
function schema_table_upgrades(): array
|
||||
{
|
||||
return [
|
||||
'settings' => <<<'SQL'
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
`key` VARCHAR(100) NOT NULL PRIMARY KEY,
|
||||
value TEXT NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||
SQL,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Spalten, die nachtraeglich dazugekommen sind: Tabelle => [Spalte => ALTER-Befehl].
|
||||
|
|
@ -57,6 +72,16 @@ function ensure_schema(): void
|
|||
}
|
||||
|
||||
$statements = [];
|
||||
|
||||
$tables = $pdo->query(
|
||||
"SELECT LOWER(table_name) FROM information_schema.tables WHERE table_schema = DATABASE()"
|
||||
)->fetchAll(PDO::FETCH_COLUMN);
|
||||
foreach (schema_table_upgrades() as $table => $sql) {
|
||||
if (!in_array($table, $tables, true)) {
|
||||
$statements[] = $sql;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($upgrades as $table => $columns) {
|
||||
foreach ($columns as $column => $sql) {
|
||||
if (empty($existing[$table][$column])) {
|
||||
|
|
|
|||
41
includes/settings.php
Normal file
41
includes/settings.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Einstellungen der Website, die die Leitung in der Oberflaeche aendert (Tabelle settings).
|
||||
* Fehlt ein Eintrag, gilt der Standardwert aus dem Code.
|
||||
*/
|
||||
|
||||
// Einstellungen, die ueber admin/settings_action.php geaendert werden duerfen: Schluessel => Standardwert.
|
||||
const SETTINGS_DEFAULTS = [
|
||||
'discord_unlink_allowed' => '1',
|
||||
];
|
||||
|
||||
function setting_get(string $key): string
|
||||
{
|
||||
static $cache = null;
|
||||
if ($cache === null) {
|
||||
$cache = [];
|
||||
try {
|
||||
foreach (db()->query('SELECT `key`, value FROM settings')->fetchAll() as $row) {
|
||||
$cache[$row['key']] = (string) $row['value'];
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
// Tabelle (noch) nicht vorhanden - Standardwerte verwenden.
|
||||
}
|
||||
}
|
||||
|
||||
return $cache[$key] ?? (SETTINGS_DEFAULTS[$key] ?? '');
|
||||
}
|
||||
|
||||
function setting_set(string $key, string $value): void
|
||||
{
|
||||
db()->prepare('INSERT INTO settings (`key`, value) VALUES (?, ?) ON DUPLICATE KEY UPDATE value = VALUES(value)')
|
||||
->execute([$key, $value]);
|
||||
}
|
||||
|
||||
/** Duerfen Mitglieder ihre Discord-Verknuepfung selbst loesen? */
|
||||
function discord_unlink_allowed(): bool
|
||||
{
|
||||
return setting_get('discord_unlink_allowed') === '1';
|
||||
}
|
||||
|
|
@ -181,7 +181,9 @@ document.getElementById('avatar-upload-input').addEventListener('change', functi
|
|||
<?php if (!empty($user['discord_id'])): ?>
|
||||
<p>Verknüpft als <strong><?= e((string) $user['discord_username']) ?></strong></p>
|
||||
<p class="text-muted">Deine Berechtigungsgruppen werden automatisch mit deinen Rollen auf dem Discord-Server abgeglichen.</p>
|
||||
<?php if (!empty($user['password_login'])): ?>
|
||||
<?php if (!discord_unlink_allowed()): ?>
|
||||
<p class="text-muted">Das Lösen der Verknüpfung ist von der Legionsleitung deaktiviert.</p>
|
||||
<?php elseif (!empty($user['password_login'])): ?>
|
||||
<form method="post" action="/discord_unlink.php" class="inline-form" onsubmit="return confirm('Discord-Verknüpfung wirklich entfernen? Gruppen, die über Discord-Rollen vergeben werden, gehen dabei verloren.');">
|
||||
<?= csrf_field() ?>
|
||||
<button type="submit" class="button-secondary">Verknüpfung entfernen</button>
|
||||
|
|
|
|||
|
|
@ -60,6 +60,13 @@ CREATE TABLE IF NOT EXISTS role_permissions (
|
|||
FOREIGN KEY (permission_id) REFERENCES permissions(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Einstellungen der Website, die die Leitung in der Oberflaeche aendert (z.B. ob Mitglieder
|
||||
-- ihre Discord-Verknuepfung loesen duerfen). Fehlende Eintraege = Standardwert im Code.
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
`key` VARCHAR(100) NOT NULL PRIMARY KEY,
|
||||
value TEXT NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_roles (
|
||||
user_id INT UNSIGNED NOT NULL,
|
||||
role_id INT UNSIGNED NOT NULL,
|
||||
|
|
|
|||
Loading…
Reference in a new issue