Add user management UI and stable UUIDs for users

Backend
- New routes/users.js (admin-only via requireAdmin) with list, create,
  update (incl. password reset) and delete endpoints.
- All user-facing API responses identify users by uuid, not the
  numeric primary key — usernames can now be renamed without breaking
  external references.
- Protection rules: cannot delete or demote the last admin; cannot
  delete or demote your own account.

Schema / data
- users table gained a uuid TEXT column (unique). Existing rows are
  backfilled with crypto.randomUUID() on startup. Setup endpoint and
  the create-user CLI both generate a UUID for new users.

Frontend
- New "Benutzer" tab in nav-tabs, marked admin-only and shown only
  after /api/auth/me reports isAdmin.
- Modal with create / edit forms (password optional on edit = leave
  unchanged). XSS-safe rendering of the user list using the existing
  escapeHtml helper and data-* attributes for action buttons.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
kerimatilganandClaude Opus 4.7 committed 2026-05-15 16:03:04 +02:00
1 parent b43ff3c5ca
commit e308c1a7b7
7 files changed
+333 -7

No files matched your search

+52 -1
View File
@@ -878,6 +878,7 @@
<button class="nav-tab" onclick="showTab('provisionen')">Provisionen</button>
<button class="nav-tab" onclick="showTab('geloeschte')">Gelöschte Schaltungen</button>
<button class="nav-tab" onclick="showTab('admin')">Administration</button>
<button class="nav-tab admin-only" onclick="showTab('users')" style="display:none">Benutzer</button>
</div>
<!-- Schaltung erfassen Tab -->
@@ -1427,7 +1428,57 @@
</div>
</div>
<!-- Benutzer-Verwaltung Tab (admin only) -->
<div id="users" class="tab-content">
<h2>Benutzer-Verwaltung</h2>
<div style="margin-bottom: 20px;">
<button type="button" class="btn-success" onclick="openUserModal()">+ Neuer Benutzer</button>
</div>
<table class="data-table" style="width:100%; border-collapse: collapse;">
<thead>
<tr>
<th>Username</th>
<th>Anzeigename</th>
<th>Admin</th>
<th>Erstellt</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody id="usersTableBody"></tbody>
</table>
</div>
<!-- Modal: Benutzer anlegen / bearbeiten -->
<div id="userModal" style="display:none; position:fixed; inset:0; background:rgba(0,0,0,0.5); z-index:1000;">
<div style="position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); background:white; border-radius:8px; width:90%; max-width:500px; padding:24px; box-shadow:0 10px 30px rgba(0,0,0,0.2);">
<h3 id="userModalTitle" style="margin-top:0;">Neuer Benutzer</h3>
<input type="hidden" id="userModalUuid">
<div class="form-group" style="margin-bottom:14px;">
<label for="userModalUsername">Username</label>
<input type="text" id="userModalUsername" style="width:100%; padding:8px; border:1px solid #ccc; border-radius:4px;">
</div>
<div class="form-group" style="margin-bottom:14px;">
<label for="userModalDisplay">Anzeigename</label>
<input type="text" id="userModalDisplay" style="width:100%; padding:8px; border:1px solid #ccc; border-radius:4px;">
</div>
<div class="form-group" style="margin-bottom:14px;">
<label for="userModalPassword">Passwort <span id="userModalPasswordHint" style="color:#666; font-size:12px;">(min. 8 Zeichen)</span></label>
<input type="password" id="userModalPassword" autocomplete="new-password" style="width:100%; padding:8px; border:1px solid #ccc; border-radius:4px;">
<small id="userModalPasswordEditHint" style="color:#666; display:none;">Leer lassen, um Passwort unverändert zu lassen</small>
</div>
<div class="form-group" style="margin-bottom:18px;">
<label style="display:flex; align-items:center; gap:8px; cursor:pointer;">
<input type="checkbox" id="userModalIsAdmin"> Administrator
</label>
</div>
<div style="text-align:right;">
<button type="button" onclick="closeUserModal()" style="margin-right:8px;">Abbrechen</button>
<button type="button" class="btn-success" onclick="saveUserFromModal()">Speichern</button>
</div>
</div>
</div>
<div id="messages"></div>
</div>