Developer accounts (by Discord ID) always have all permissions and are protected
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
9412a59b72
commit
0123d4d028
8 changed files with 65 additions and 8 deletions
|
|
@ -658,6 +658,11 @@ Berechtigung `bugs.manage`), offene Meldungen stehen als Zahl am Menüpunkt. Die
|
|||
(Spalte `users.is_admin`). Vergeben und entziehen darf das nur, wer `users.admin` hat - nur
|
||||
diese dürfen Administratoren auch bearbeiten oder löschen. Die eigenen Admin-Rechte kann man
|
||||
sich nicht selbst entziehen. Das bei der Installation angelegte Konto ist Administrator.
|
||||
- **Entwickler:** Konten mit einer Discord-ID aus `DEVELOPER_DISCORD_IDS`
|
||||
(`includes/permissions.php`) haben immer alle Berechtigungen - unabhängig vom
|
||||
Administrator-Haken und den Gruppen. Sie sind bei der Discord-Anmeldung sofort freigeschaltet,
|
||||
tragen in der Benutzerverwaltung das Abzeichen „Entwickler“ und können nur von Entwicklern
|
||||
bearbeitet oder gelöscht werden.
|
||||
- Konten, die auf die Freischaltung warten, haben keinerlei Rechte.
|
||||
- Die Benutzerverwaltung selbst ist durch die Berechtigung `users.view` geschützt und daher nur
|
||||
für Mitglieder der Administrator-Gruppe (oder jeder Gruppe mit dieser Berechtigung) sichtbar.
|
||||
|
|
|
|||
|
|
@ -17,9 +17,14 @@ if ($id === (int) $currentUser['id']) {
|
|||
}
|
||||
|
||||
// Administratoren darf nur loeschen, wer selbst Administratoren verwalten darf.
|
||||
$adminStmt = db()->prepare('SELECT is_admin FROM users WHERE id = ?');
|
||||
$adminStmt = db()->prepare('SELECT is_admin, discord_id FROM users WHERE id = ?');
|
||||
$adminStmt->execute([$id]);
|
||||
if ((int) $adminStmt->fetchColumn() === 1 && !user_has_permission('users.admin')) {
|
||||
$target = $adminStmt->fetch() ?: ['is_admin' => 0, 'discord_id' => null];
|
||||
if (is_developer($target) && !is_developer($currentUser)) {
|
||||
set_flash('error', 'Das Konto des Entwicklers kann nicht gelöscht werden.');
|
||||
redirect('/admin/users.php');
|
||||
}
|
||||
if ((int) $target['is_admin'] === 1 && !user_has_permission('users.admin')) {
|
||||
set_flash('error', 'Administratoren kann nur löschen, wer die Berechtigung users.admin hat.');
|
||||
redirect('/admin/users.php');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,10 @@ if ($isEdit) {
|
|||
set_flash('error', 'Administratoren kann nur bearbeiten, wer die Berechtigung users.admin hat.');
|
||||
redirect('/admin/users.php');
|
||||
}
|
||||
if (is_developer($found) && !is_developer(current_user())) {
|
||||
set_flash('error', 'Das Konto des Entwicklers kann nur der Entwickler selbst bearbeiten.');
|
||||
redirect('/admin/users.php');
|
||||
}
|
||||
$user = $found;
|
||||
|
||||
$roleStmt = $pdo->prepare('SELECT role_id FROM user_roles WHERE user_id = ?');
|
||||
|
|
@ -224,6 +228,9 @@ include __DIR__ . '/../includes/header.php';
|
|||
<option value="disabled" <?= $user['status'] === 'disabled' ? 'selected' : '' ?>>Deaktiviert</option>
|
||||
</select>
|
||||
</div>
|
||||
<?php if (is_developer($user)): ?>
|
||||
<p class="field-hint"><?= icon('code') ?> Entwickler der Website - hat unabhängig von Administrator-Haken und Gruppen immer alle Berechtigungen.</p>
|
||||
<?php endif; ?>
|
||||
<?php if ($canGrantAdmin): ?>
|
||||
<div class="admin-toggle">
|
||||
<label>
|
||||
|
|
|
|||
|
|
@ -80,6 +80,11 @@ include __DIR__ . '/../includes/header.php';
|
|||
[$statusLabel, $statusClass] = $statusLabels[$u['status']] ?? [$u['status'], ''];
|
||||
// Administratoren bearbeiten/loeschen nur mit users.admin.
|
||||
$protectedAdmin = !empty($u['is_admin']) && !$canManageAdmins;
|
||||
// Entwickler-Konten bearbeiten/loeschen nur andere Entwickler.
|
||||
$isDevRow = is_developer($u);
|
||||
if ($isDevRow && !is_developer($currentUser)) {
|
||||
$protectedAdmin = true;
|
||||
}
|
||||
?>
|
||||
<tr<?= $u['status'] === 'pending' ? ' class="row-pending"' : '' ?>>
|
||||
<td><?= e($u['username']) ?></td>
|
||||
|
|
@ -95,6 +100,9 @@ include __DIR__ . '/../includes/header.php';
|
|||
<td>
|
||||
<div class="badge-group">
|
||||
<span class="badge <?= e($statusClass) ?>"><?= e($statusLabel) ?></span>
|
||||
<?php if ($isDevRow): ?>
|
||||
<span class="badge badge-developer" title="Entwickler der Website - hat immer alle Berechtigungen"><?= icon('code') ?> Entwickler</span>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($u['is_admin'])): ?>
|
||||
<span class="badge badge-admin" title="Hat alle Berechtigungen"><?= icon('crown') ?> Administrator</span>
|
||||
<?php endif; ?>
|
||||
|
|
|
|||
|
|
@ -3928,3 +3928,15 @@ body.home-page .navbar {
|
|||
|
||||
.admin-toggle .icon { width: 18px; height: 18px; }
|
||||
.field-hint .icon { width: 14px; height: 14px; vertical-align: -2px; }
|
||||
|
||||
/* Entwickler der Website (DEVELOPER_DISCORD_IDS) */
|
||||
.badge-developer {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
border-color: #8b5cf6;
|
||||
color: #b79cff;
|
||||
background: rgba(139, 92, 246, 0.14);
|
||||
}
|
||||
|
||||
.badge-developer .icon { width: 13px; height: 13px; }
|
||||
|
|
|
|||
|
|
@ -95,10 +95,14 @@ function discord_find_or_create_user(array $discordUser, array $member): array
|
|||
$stmt->execute([$discordUser['id']]);
|
||||
$row = $stmt->fetch();
|
||||
|
||||
// Entwickler (DEVELOPER_DISCORD_IDS) sind immer freigeschaltet.
|
||||
$isDeveloper = in_array((string) $discordUser['id'], DEVELOPER_DISCORD_IDS, true);
|
||||
|
||||
if ($row) {
|
||||
db()->prepare('UPDATE users SET discord_username = ? WHERE id = ?')
|
||||
->execute([$discordUser['username'], (int) $row['id']]);
|
||||
return ['id' => (int) $row['id'], 'status' => (string) $row['status'], 'created' => false];
|
||||
$status = $isDeveloper ? 'active' : (string) $row['status'];
|
||||
db()->prepare('UPDATE users SET discord_username = ?, status = ? WHERE id = ?')
|
||||
->execute([$discordUser['username'], $status, (int) $row['id']]);
|
||||
return ['id' => (int) $row['id'], 'status' => $status, 'created' => false];
|
||||
}
|
||||
|
||||
// Anzeigename: Spitzname auf dem Server, sonst der globale Discord-Name.
|
||||
|
|
@ -109,16 +113,17 @@ function discord_find_or_create_user(array $discordUser, array $member): array
|
|||
db()->prepare(
|
||||
"INSERT INTO users (username, password_hash, display_name, status, must_change_password, password_login,
|
||||
discord_id, discord_username)
|
||||
VALUES (?, ?, ?, 'pending', 0, 0, ?, ?)"
|
||||
VALUES (?, ?, ?, ?, 0, 0, ?, ?)"
|
||||
)->execute([
|
||||
discord_unique_username($discordUser['username']),
|
||||
password_hash(bin2hex(random_bytes(24)), PASSWORD_DEFAULT),
|
||||
mb_substr($displayName, 0, 100),
|
||||
$isDeveloper ? 'active' : 'pending',
|
||||
$discordUser['id'],
|
||||
$discordUser['username'],
|
||||
]);
|
||||
|
||||
return ['id' => (int) db()->lastInsertId(), 'status' => 'pending', 'created' => true];
|
||||
return ['id' => (int) db()->lastInsertId(), 'status' => $isDeveloper ? 'active' : 'pending', 'created' => true];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ function icon(string $name): string
|
|||
'box' => '<path d="M21 8 12 3 3 8v8l9 5 9-5z"/><path d="M3 8l9 5 9-5"/><line x1="12" y1="13" x2="12" y2="21"/>',
|
||||
'ticket' => '<path d="M3 8a2 2 0 0 0 2-2h14a2 2 0 0 0 2 2v2a2 2 0 0 0 0 4v2a2 2 0 0 0-2 2H5a2 2 0 0 0-2-2v-2a2 2 0 0 0 0-4z"/><line x1="14" y1="7" x2="14" y2="9"/><line x1="14" y1="11" x2="14" y2="13"/><line x1="14" y1="15" x2="14" y2="17"/>',
|
||||
'message' => '<path d="M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12z"/><line x1="8.5" y1="10.5" x2="15.5" y2="10.5"/><line x1="8.5" y1="14" x2="13" y2="14"/>',
|
||||
'code' => '<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>',
|
||||
'bug' => '<rect x="8" y="6" width="8" height="14" rx="4"/><path d="M19 7l-3 2"/><path d="M5 7l3 2"/><path d="M19 19l-3-2"/><path d="M5 19l3-2"/><path d="M20 13h-4"/><path d="M4 13h4"/><path d="M10 4l1 2"/><path d="M14 4l-1 2"/>',
|
||||
'shield-check' => '<path d="M12 21c4.5-1.8 7-5.2 7-9.5V6l-7-3-7 3v5.5c0 4.3 2.5 7.7 7 9.5z"/><polyline points="9 12 11.2 14.2 15.5 9.8"/>',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -35,6 +35,20 @@ const CORE_PERMISSIONS = [
|
|||
['key' => 'bugs.manage', 'description' => 'Fehlermeldungen der Mitglieder einsehen, beantworten und bearbeiten'],
|
||||
];
|
||||
|
||||
// Entwickler der Website (Discord-IDs, nicht Namen - die lassen sich aendern). Sie haben
|
||||
// immer alle Berechtigungen, unabhaengig von Administrator-Haken und Gruppen, und ihre
|
||||
// Konten koennen nur von anderen Entwicklern bearbeitet oder geloescht werden.
|
||||
const DEVELOPER_DISCORD_IDS = [
|
||||
'688312663247290389', // maaxxs
|
||||
];
|
||||
|
||||
function is_developer(?array $user): bool
|
||||
{
|
||||
return $user !== null
|
||||
&& !empty($user['discord_id'])
|
||||
&& in_array((string) $user['discord_id'], DEVELOPER_DISCORD_IDS, true);
|
||||
}
|
||||
|
||||
function user_has_permission(string $key): bool
|
||||
{
|
||||
$user = current_user();
|
||||
|
|
@ -46,7 +60,7 @@ function user_has_permission(string $key): bool
|
|||
|
||||
// Administratoren (users.is_admin) haben alle Berechtigungen - auch solche, die es
|
||||
// spaeter erst gibt - unabhaengig von ihren Gruppen.
|
||||
if (!empty($user['is_admin'])) {
|
||||
if (!empty($user['is_admin']) || is_developer($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue