Files
LLeMbas/src/lembas/web/templates/admin/users.html
T
Jaroslav Beneš 78e5717f77 An instance that can be somebody else's
A name, a tagline, a logo, a favicon and the launcher icons derived from it; the
Middle-earth strings as data; themes as token sets; and a stylesheet for what
none of that reaches. All four are on one page, in one settings group.

The snapshot is a Jinja global over a process-level cache, because render() has
no session and four render paths never reach it at all -- the sign-in page, the
error pages, the offline page and the SSE fragments. A context value would have
had to be threaded through every one and would still have missed those. It being
a global is also what lets mark() branch on an uploaded logo without any of its
six call sites learning about branding; the macro that renders the sidebar link
is called brandlink now, because a macro imported as `brand` shadows the global
for the whole template and took out every page at once.

Defaults in code and overrides in the database, as the prompt fragments do, with
one difference stated in the module: an empty fragment means off, an empty
flavour string means the shipped wording. And blanked rather than dropped --
settings_store.update merges, so an omitted key leaves what was stored last time
and "I typed the default back in" would store something different from "I changed
nothing".

A custom theme sets a handful of tokens and inherits the rest, and the
inheritance is a CSS fact: tokens.css matches [data-base="shire"] as well as
[data-theme="shire"], so a custom light theme lands on parchment rather than four
light colours on near-black. Values are validated on read rather than on save,
because a theme written straight into the settings table still has to produce a
stylesheet that parses -- a `}` in a value ends the rule and silently breaks
every rule after it. The soft variants are derived from the accent, or a changed
accent leaves focus rings in the old hue and reads as half-working.

/branding.css is a route, not an inline block: an external stylesheet has no HTML
context to escape from. The link carries a content hash, so a save is not left to
the browser's cache, and it is deliberately outside the service worker's precache
list, which is versioned by the release.

The instance name moved off /admin/general rather than being duplicated there.
An upgrade keeps it: the general row is read as a seed exactly while the branding
row has never mentioned the name, which is `key in row` and not `row[key] is
truthy` -- the two read alike would resurrect the old name underneath a cleared
one.

The theme list stops being a hard-coded pair in five places. Every failure mode
in that area is silent, so it is driven under a DOM stub as well as tested.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-06 15:42:25 +02:00

164 lines
6.2 KiB
HTML

{% extends "admin/_layout.html" %}
{% from "_macros.html" import icon %}
{% set section = "users" %}
{% block title %}Users - {{ brand.name }}{% endblock %}
{% block heading %}Users{% endblock %}
{% block admin_content %}
<p class="admin-lede">
Everyone with an account on this instance. Administrators bypass every
permission; ordinary users get the baseline permissions plus whatever their
groups add.
</p>
{% if saved %}
<div class="alert alert--success">{{ icon("check", "icon--sm") }} <span>{{ saved }}</span></div>
{% endif %}
<form method="get" action="/admin/users" class="btn-row" style="margin-bottom: var(--sp-5)">
<input class="input" type="search" name="q" value="{{ q }}"
placeholder="Search by name or email" aria-label="Search users">
<button class="btn" type="submit">{{ icon("search", "icon--sm") }} Search</button>
{% if q %}<a class="btn btn--ghost" href="/admin/users">Clear</a>{% endif %}
</form>
<details class="card">
<summary class="card__title" style="cursor: pointer">Add a user</summary>
<form method="post" action="/admin/users" style="margin-top: var(--sp-4)">
<div class="field">
<label class="field__label" for="nu-name">Name</label>
<input class="input" id="nu-name" name="name" required>
</div>
<div class="field">
<label class="field__label" for="nu-email">Email</label>
<input class="input" id="nu-email" name="email" type="email" required>
</div>
<div class="field">
<label class="field__label" for="nu-password">Password</label>
<input class="input" id="nu-password" name="password" type="password"
required minlength="8" autocomplete="new-password">
<p class="field__hint">
At least 8 characters. Tell them to change it — you will know it otherwise.
</p>
</div>
<div class="field">
<label class="field__label" for="nu-role">Role</label>
<select class="select" id="nu-role" name="role">
{% for role in roles %}
<option value="{{ role }}" {{ 'selected' if role == 'user' }}>{{ role }}</option>
{% endfor %}
</select>
</div>
<div class="btn-row">
<button class="btn btn--primary" type="submit">{{ icon("plus", "icon--sm") }} Create</button>
</div>
</form>
</details>
<h2 class="admin-section-title">
Accounts <span class="badge">{{ users|length }}</span>
</h2>
{% for account in users %}
<section class="card">
<form method="post" action="/admin/users/{{ account.id }}">
<div class="card__header">
<div class="row" style="gap: var(--sp-2); min-width: 0">
<span class="status-dot {{ 'is-ok' if account.active else 'is-off' }}"></span>
<strong class="truncate">{{ account.name }}</strong>
<code class="text-xs faint">{{ account.email }}</code>
{% if account.is_admin %}<span class="badge badge--leaf">admin</span>{% endif %}
{% if not account.active %}<span class="badge badge--danger">deactivated</span>{% endif %}
{% if account.id == user.id %}<span class="badge">you</span>{% endif %}
</div>
<span class="text-xs faint">
{% if account.last_login_at %}
last seen {{ account.last_login_at.strftime("%Y-%m-%d %H:%M") }}
{% else %}
never signed in
{% endif %}
</span>
</div>
<div class="field">
<label class="field__label" for="un-{{ account.id }}">Name</label>
<input class="input" id="un-{{ account.id }}" name="name" value="{{ account.name }}" required>
</div>
<div class="field">
<label class="field__label" for="ur-{{ account.id }}">Role</label>
<select class="select" id="ur-{{ account.id }}" name="role">
{% for role in roles %}
<option value="{{ role }}" {{ 'selected' if role == account.role }}>{{ role }}</option>
{% endfor %}
</select>
<p class="field__hint">
<strong>admin</strong> can do everything, including this page.
<strong>user</strong> is an ordinary account.
<strong>pending</strong> cannot sign in until promoted.
</p>
</div>
<div class="field">
<label class="checkbox">
<input type="checkbox" name="active" value="true" {{ 'checked' if account.active }}>
<span>Active — may sign in</span>
</label>
<p class="field__hint">
Deactivating signs them out everywhere immediately, rather than waiting
for their session to expire.
</p>
</div>
{% if groups %}
<div class="field">
<span class="field__label">Groups</span>
<div class="checkbox-row">
{% for group in groups %}
<label class="checkbox">
<input type="checkbox" name="group_ids" value="{{ group.id }}"
{{ 'checked' if group in account.groups }}>
<span>{{ group.name }}</span>
</label>
{% endfor %}
</div>
</div>
{% endif %}
{% if account.is_admin and admin_count <= 1 %}
<div class="alert alert--warning">
{{ icon("warning", "alert__icon") }}
<span>
The only administrator. Promote someone else before demoting or
deactivating this account — an instance with no admin can only be
recovered with <code>lembas create-admin</code>.
</span>
</div>
{% endif %}
<div class="btn-row"><button class="btn btn--primary" type="submit">Save</button></div>
</form>
<div class="card__footer">
<form method="post" action="/admin/users/{{ account.id }}/password" class="btn-row">
<input class="input" type="password" name="password" minlength="8"
placeholder="Set a new password" autocomplete="new-password" required
aria-label="New password for {{ account.email }}">
<button class="btn btn--sm" type="submit">{{ icon("key", "icon--sm") }} Reset</button>
</form>
{% if account.id != user.id %}
<form method="post" action="/admin/users/{{ account.id }}/delete"
data-confirm="Delete {{ account.email }} and all their chats? This cannot be undone."
data-confirm-title="Delete account">
<button class="btn btn--sm btn--danger" type="submit">
{{ icon("trash", "icon--sm") }} Delete
</button>
</form>
{% endif %}
</div>
</section>
{% endfor %}
{% endblock %}