- Overview: users, organizations, workspaces, spaces, pages, files and storage (org admins see their organization), plus pages open right now, the search index size, and version, uptime and database health. - Users: invite people by email (with resend, revoke and a copyable link when mail fails) and send a password-reset email. - Authentication: sign-up on or off, the email-domain allow-list, and sign-in links by email. - Branding: instance name, accent colour and logo. The web app shows them on the sign-in pages and applies the accent colour everywhere. - Email and Storage: SMTP and S3 settings with test buttons. - Maintenance: create, download and delete database backups, and a view of the background jobs with their last run, duration and errors. On the server, a small jobs registry records each search-indexing pass, and "search.rebuild" replaces the separate reindex endpoint. A new instance package serves the dashboard numbers, health and backups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
277 lines
9.9 KiB
Vue
277 lines
9.9 KiB
Vue
<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
|
|
<script setup lang="ts">
|
|
import type { Organization, Role, User, UserList } from "@docwell/api-client";
|
|
import { DwBadge, DwButton, DwCallout } from "@docwell/ui";
|
|
import { computed, onMounted, reactive, ref, watch } from "vue";
|
|
import InvitesPanel from "../components/InvitesPanel.vue";
|
|
import { api, currentUser, errorMessage, isSuperadmin } from "../session";
|
|
|
|
// Mirrors the server's rules so the form only offers what will be accepted:
|
|
// org admins manage their own organization and never touch superadmins;
|
|
// superadmins manage everyone and move people between organizations.
|
|
const perPage = 20;
|
|
const page = ref(1);
|
|
const search = ref("");
|
|
const orgFilter = ref("");
|
|
const list = ref<UserList | null>(null);
|
|
const orgs = ref<Organization[]>([]);
|
|
const error = ref("");
|
|
const busy = ref(false);
|
|
|
|
const roles = computed<Role[]>(() => (isSuperadmin.value ? ["user", "admin", "superadmin"] : ["user", "admin"]));
|
|
const roleLabel: Record<string, string> = { user: "User", admin: "Admin", superadmin: "Superadmin" };
|
|
|
|
async function load() {
|
|
error.value = "";
|
|
try {
|
|
list.value = await api.users.list({ page: page.value, perPage, q: search.value, organization: orgFilter.value });
|
|
} catch (e) {
|
|
error.value = errorMessage(e);
|
|
}
|
|
}
|
|
|
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
watch(search, () => {
|
|
clearTimeout(timer);
|
|
timer = setTimeout(() => {
|
|
page.value = 1;
|
|
load();
|
|
}, 250);
|
|
});
|
|
watch([page, orgFilter], load);
|
|
onMounted(async () => {
|
|
orgs.value = await api.orgs.list().catch(() => []);
|
|
load();
|
|
});
|
|
|
|
// ---- Create / edit form ----------------------------------------------------
|
|
const editing = ref<User | "new" | null>(null);
|
|
const form = reactive({ name: "", email: "", password: "", role: "user" as Role, organization: "", status: "active" });
|
|
|
|
function startNew() {
|
|
editing.value = "new";
|
|
Object.assign(form, {
|
|
name: "",
|
|
email: "",
|
|
password: "",
|
|
role: "user",
|
|
organization: isSuperadmin.value ? orgFilter.value.replace("none", "") : "",
|
|
status: "active",
|
|
});
|
|
}
|
|
|
|
function startEdit(u: User) {
|
|
editing.value = u;
|
|
Object.assign(form, {
|
|
name: u.name,
|
|
email: u.email,
|
|
password: "",
|
|
role: u.role,
|
|
organization: u.organization,
|
|
status: u.status,
|
|
});
|
|
}
|
|
|
|
const isSelf = computed(() => editing.value !== "new" && editing.value?.id === currentUser.value?.id);
|
|
// An org admin cannot edit a superadmin at all.
|
|
const canEdit = (u: User) => isSuperadmin.value || u.role !== "superadmin";
|
|
|
|
async function save() {
|
|
busy.value = true;
|
|
error.value = "";
|
|
try {
|
|
if (editing.value === "new") {
|
|
await api.users.create({
|
|
name: form.name,
|
|
email: form.email,
|
|
password: form.password,
|
|
role: form.role,
|
|
organization: isSuperadmin.value ? form.organization : undefined,
|
|
});
|
|
} else if (editing.value) {
|
|
const u = editing.value;
|
|
await api.users.update(u.id, {
|
|
name: form.name !== u.name ? form.name : undefined,
|
|
email: form.email !== u.email ? form.email : undefined,
|
|
password: form.password || undefined,
|
|
role: form.role !== u.role ? form.role : undefined,
|
|
status: form.status !== u.status ? (form.status as User["status"]) : undefined,
|
|
organization: isSuperadmin.value && form.organization !== u.organization ? form.organization : undefined,
|
|
});
|
|
}
|
|
editing.value = null;
|
|
await load();
|
|
} catch (e) {
|
|
error.value = errorMessage(e);
|
|
} finally {
|
|
busy.value = false;
|
|
}
|
|
}
|
|
|
|
const notice = ref("");
|
|
async function sendReset(u: User) {
|
|
busy.value = true;
|
|
error.value = "";
|
|
notice.value = "";
|
|
try {
|
|
await api.users.sendPasswordReset(u.id);
|
|
notice.value = `A password reset link is on its way to ${u.email}.`;
|
|
} catch (e) {
|
|
error.value = errorMessage(e);
|
|
} finally {
|
|
busy.value = false;
|
|
}
|
|
}
|
|
|
|
async function remove(u: User) {
|
|
if (!confirm(`Delete ${u.email}? This cannot be undone.`)) return;
|
|
busy.value = true;
|
|
error.value = "";
|
|
try {
|
|
await api.users.remove(u.id);
|
|
await load();
|
|
} catch (e) {
|
|
error.value = errorMessage(e);
|
|
} finally {
|
|
busy.value = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="flex flex-wrap items-center justify-between gap-3">
|
|
<div>
|
|
<h1 class="text-2xl font-semibold tracking-tight">Users</h1>
|
|
<p class="mt-1 text-ink-muted">
|
|
{{ isSuperadmin ? "Everyone on this server." : `Members of ${currentUser?.organizationName}.` }}
|
|
</p>
|
|
</div>
|
|
<DwButton variant="primary" @click="startNew">New user</DwButton>
|
|
</div>
|
|
|
|
<div class="mt-4 flex flex-wrap gap-2">
|
|
<input
|
|
v-model="search"
|
|
type="search"
|
|
placeholder="Search name or email"
|
|
aria-label="Search users"
|
|
class="dw-input sm:w-64"
|
|
/>
|
|
<select v-if="isSuperadmin" v-model="orgFilter" aria-label="Filter by organization" class="dw-input sm:w-56">
|
|
<option value="">All organizations</option>
|
|
<option value="none">No organization</option>
|
|
<option v-for="o in orgs" :key="o.id" :value="o.id">{{ o.name }}</option>
|
|
</select>
|
|
</div>
|
|
|
|
<InvitesPanel :orgs="orgs" @accepted="load" />
|
|
|
|
<DwCallout v-if="error" tone="danger" size="ui" class="mt-4">{{ error }}</DwCallout>
|
|
<DwCallout v-if="notice" tone="success" size="ui" class="mt-4">{{ notice }}</DwCallout>
|
|
|
|
<form v-if="editing" class="mt-4 grid gap-3 dw-card !p-4 sm:grid-cols-2" @submit.prevent="save">
|
|
<h2 class="text-ui-lg sm:col-span-2">{{ editing === "new" ? "New user" : `Edit ${editing.email}` }}</h2>
|
|
<label class="flex flex-col gap-1.5">
|
|
<span class="text-ui-sm font-semibold">Name</span>
|
|
<input v-model="form.name" required class="dw-input" />
|
|
</label>
|
|
<label class="flex flex-col gap-1.5">
|
|
<span class="text-ui-sm font-semibold">Email</span>
|
|
<input v-model="form.email" type="email" required class="dw-input" />
|
|
</label>
|
|
<label class="flex flex-col gap-1.5">
|
|
<span class="text-ui-sm font-semibold">{{ editing === "new" ? "Password" : "New password (optional)" }}</span>
|
|
<input
|
|
v-model="form.password"
|
|
type="password"
|
|
autocomplete="new-password"
|
|
:required="editing === 'new'"
|
|
minlength="8"
|
|
class="dw-input"
|
|
/>
|
|
</label>
|
|
<label class="flex flex-col gap-1.5">
|
|
<span class="text-ui-sm font-semibold">Role</span>
|
|
<select v-model="form.role" :disabled="isSelf" class="dw-input">
|
|
<option v-for="r in roles" :key="r" :value="r">{{ roleLabel[r] }}</option>
|
|
</select>
|
|
<span v-if="isSelf" class="text-ui-sm text-ink-muted">You cannot change your own role.</span>
|
|
</label>
|
|
<label v-if="isSuperadmin" class="flex flex-col gap-1.5">
|
|
<span class="text-ui-sm font-semibold">Organization</span>
|
|
<select v-model="form.organization" class="dw-input">
|
|
<option value="">No organization</option>
|
|
<option v-for="o in orgs" :key="o.id" :value="o.id">{{ o.name }}</option>
|
|
</select>
|
|
</label>
|
|
<label v-if="editing !== 'new'" class="flex flex-col gap-1.5">
|
|
<span class="text-ui-sm font-semibold">Status</span>
|
|
<select v-model="form.status" :disabled="isSelf" class="dw-input">
|
|
<option value="active">Active</option>
|
|
<option value="disabled">Disabled</option>
|
|
</select>
|
|
</label>
|
|
<div class="flex gap-2 sm:col-span-2">
|
|
<DwButton type="submit" variant="primary" :disabled="busy">{{
|
|
editing === "new" ? "Create user" : "Save"
|
|
}}</DwButton>
|
|
<DwButton variant="ghost" :disabled="busy" @click="editing = null">Cancel</DwButton>
|
|
</div>
|
|
</form>
|
|
|
|
<div class="mt-6 overflow-x-auto rounded-md border border-line bg-surface-raised">
|
|
<table class="w-full text-left text-ui-md">
|
|
<thead class="bg-surface-sunken text-ui-xs uppercase text-ink-muted">
|
|
<tr>
|
|
<th class="px-4 py-2 font-medium">Name</th>
|
|
<th class="px-4 py-2 font-medium">Email</th>
|
|
<th class="px-4 py-2 font-medium">Role</th>
|
|
<th v-if="isSuperadmin" class="px-4 py-2 font-medium">Organization</th>
|
|
<th class="px-4 py-2 font-medium">Status</th>
|
|
<th class="px-4 py-2"><span class="sr-only">Actions</span></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-for="u in list?.items" :key="u.id" class="border-t border-line">
|
|
<td class="px-4 py-2 font-medium">{{ u.name }}</td>
|
|
<td class="px-4 py-2">{{ u.email }}</td>
|
|
<td class="px-4 py-2">{{ roleLabel[u.role] }}</td>
|
|
<td v-if="isSuperadmin" class="px-4 py-2">{{ u.organizationName || "—" }}</td>
|
|
<td class="px-4 py-2">
|
|
<DwBadge
|
|
:tone="u.status === 'active' ? 'success' : u.status === 'disabled' ? 'danger' : 'neutral'"
|
|
class="capitalize"
|
|
>{{ u.status }}</DwBadge
|
|
>
|
|
</td>
|
|
<td class="px-4 py-2 text-right whitespace-nowrap">
|
|
<template v-if="canEdit(u)">
|
|
<DwButton variant="ghost" size="sm" @click="startEdit(u)">Edit</DwButton>
|
|
<DwButton variant="ghost" size="sm" :disabled="busy" @click="sendReset(u)">Reset password</DwButton>
|
|
<DwButton
|
|
v-if="u.id !== currentUser?.id"
|
|
variant="ghost"
|
|
size="sm"
|
|
class="!text-danger"
|
|
:disabled="busy"
|
|
@click="remove(u)"
|
|
>
|
|
Delete
|
|
</DwButton>
|
|
</template>
|
|
</td>
|
|
</tr>
|
|
<tr v-if="list && list.items.length === 0">
|
|
<td :colspan="isSuperadmin ? 6 : 5" class="px-4 py-6 text-center text-ink-muted">No users found.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div v-if="list && list.totalItems > perPage" class="mt-4 flex items-center gap-3 text-ui-md">
|
|
<DwButton size="sm" :disabled="page <= 1" @click="page--">Previous</DwButton>
|
|
<span class="text-ink-muted">Page {{ page }} of {{ Math.ceil(list.totalItems / perPage) }}</span>
|
|
<DwButton size="sm" :disabled="page * perPage >= list.totalItems" @click="page++">Next</DwButton>
|
|
</div>
|
|
</template>
|