Files
AudioBookRequest/templates/settings_page/users.html
2025-03-15 01:21:29 +01:00

146 lines
5.0 KiB
HTML

{% extends "settings_page/base.html" %} {% block head %}
<title>Settings - Users</title>
{% endblock %} {% block content %}
{% if is_oidc %}
<p class="text-error font-semibold">
OpenID Connect is enabled. Users will be automatically created when they log in.
If a user has a group assigned on the authentication server, it will override their group here.
</p>
{% endif %}
<form
id="create-user-form"
class="flex flex-col gap-2"
hx-post="/settings/user"
hx-target="#user-list"
hx-on::after-request="if (event.detail.successful && event.detail.target?.id === 'user-list') this.reset()"
hx-swap="outerHTML"
hx-disabled-elt="#submit"
>
<h2 class="text-lg">Create user</h2>
<label for="username">Username</label>
<input
id="username"
name="username"
minlength="1"
type="text"
class="input w-full"
required
/>
<label for="password">Password</label>
<input
id="password"
name="password"
type="password"
class="input w-full"
required
/>
<label for="select-group">Group</label>
<select id="select-group" name="group" class="select w-full" required>
<option value="untrusted" selected>Untrusted</option>
<option value="trusted">Trusted</option>
<option value="admin">Admin</option>
</select>
<button id="submit" class="btn btn-primary" type="submit">Create user</button>
</form>
{% block user_block %}
<div id="user-list" class="pt-4 border-t border-base-200">
<h2 class="text-lg">Users</h2>
{% if success %}
<script>
toast("{{success|safe}}", "success");
</script>
{% endif %}
<div class="flex flex-col opacity-60 text-sm">
<span class="font-bold">Untrusted:</span> <span>Can search and request files.</span>
<span class="font-bold">Trusted:</span> <span>Same as untrused, but if auto-download is enabled the user can start downloads.</span>
<span class="font-bold">Admin:</span> <span>Can manage users and settings.</span>
</div>
<div class="max-h-[30rem] overflow-x-auto">
<table class="table table-pin-rows">
<thead>
<tr>
<th></th>
<th>Username</th>
<th>Group</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
{% for u in users %}
<tr>
<th>{{ loop.index }}</th>
<td>{{ u.username }}</td>
<td>
<!-- prettier-ignore -->
<select
id="select-group"
name="group"
class="select w-full"
required {% if u.root %}disabled{% endif %}
hx-patch="/settings/user/{{ u.username|quote_plus }}"
hx-trigger="change"
hx-disabled-elt="this"
hx-target="#user-list"
hx-swap="outerHTML"
>
<option value="untrusted" {% if u.group.value.__eq__("untrusted") %}selected{% endif %}>Untrusted</option>
<option value="trusted" {% if u.group.value.__eq__("trusted") %}selected{% endif %}>Trusted</option>
<option value="admin" {% if u.group.value.__eq__("admin") %}selected{% endif %}>Admin</option>
{% if u.root %}<option value="admin" selected>Root Admin</option>{% endif %}
</select>
</td>
<td {% if u.root %}title="Can't delete the root admin"{% elif u.is_self(user.username) %}title="Can't delete yourself"{% endif %}>
<!--prettier-ignore -->
<button
class="btn btn-square btn-ghost"
onclick="delete_modal_{{ loop.index }}.showModal()"
{% if u.is_self(user.username) or u.root %}disabled{% endif %}
>
{% include 'icons/trash.html' %}
</button>
<dialog id="delete_modal_{{ loop.index }}" class="modal">
<div class="modal-box">
<h3 class="text-lg font-bold">
Are you sure you want to delete a user?
</h3>
<div class="grid grid-cols-2 py-4">
<span class="font-semibold mr-2">Username</span
><span class="font-mono">{{ u.username }}</span>
<span class="font-semibold mr-2">Group</span
><span class="font-mono"
>{{ u.group.value.capitalize() }}</span
>
</div>
<form method="dialog" class="flex justify-between">
<button class="btn">Cancel</button>
<button
class="btn bg-primary"
hx-delete="/settings/user/{{ u.username|quote_plus }}"
hx-disabled-elt="this"
hx-target="#user-list"
hx-swap="outerHTML"
>
Delete
</button>
</form>
</div>
<form method="dialog" class="modal-backdrop">
<button>close</button>
</form>
</dialog>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %} {% endblock %}