CI / go (Server) (push) Failing after 4m38s
CI / go (Web-App) (push) Successful in 12m18s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / frontend (push) Failing after 7m49s
CI / desktop (ubuntu-latest) (push) Successful in 1h25m30s
CI / mobile (push) Failing after 5m14s
CI / docker (push) Successful in 39m26s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
Databases (ADR-13 follow-ups):
- Relation properties link records to another database, on the same page
or on any page the reader can open (read live and read-only, like synced
pages). Cells list the linked titles; clicking one opens the record.
- Rollup properties work out counts, sums, averages, medians, min/max,
ranges, earliest/latest dates and checked counts over related records.
Neither is stored: views compute them before drawing (linked.ts), so they
follow both databases live, and rollups sort and filter as numbers.
- Exports (Markdown, HTML, PDF, Word) resolve them for same-page databases.
- A record opens as a full page at /p/<page>/r/<database>/<record>, with
"Open as full page" on the side panel and "Back to the page".
Edgeless mode (ADR-14 follow-ups):
- History previews show a version's canvas and count canvas changes.
- Comments can be anchored to canvas elements (anchor {element}); elements
with open threads show a badge that opens the thread.
- Workspaces choose how new pages open (workspaces.default_page_mode); the
per-device choice now defaults to following the workspace.
- Phones edit the canvas once a page is opened for editing; the page note
shows the page title.
Languages:
- The admin panel speaks English, Polish, German, French and Spanish, with
a picker sharing the web app's setting and a key parity test.
- The phone app speaks the same five, follows the phone's language (and
Android's per-app language setting), and has its own parity test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
306 lines
11 KiB
Vue
306 lines
11 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 { useI18n } from "vue-i18n";
|
|
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 { t } = useI18n();
|
|
const roleLabel = (r: string) => t(`roles.${r}`);
|
|
|
|
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 = t("users.resetSent", { email: u.email });
|
|
} catch (e) {
|
|
error.value = errorMessage(e);
|
|
} finally {
|
|
busy.value = false;
|
|
}
|
|
}
|
|
|
|
async function resetTotp(u: User) {
|
|
if (!confirm(t("users.confirmTotp", { email: u.email }))) return;
|
|
busy.value = true;
|
|
error.value = "";
|
|
notice.value = "";
|
|
try {
|
|
await api.users.resetTotp(u.id);
|
|
notice.value = t("users.totpOff", { email: u.email });
|
|
await load();
|
|
} catch (e) {
|
|
error.value = errorMessage(e);
|
|
} finally {
|
|
busy.value = false;
|
|
}
|
|
}
|
|
|
|
async function remove(u: User) {
|
|
if (!confirm(t("users.confirmDelete", { email: u.email }))) 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">{{ $t("users.title") }}</h1>
|
|
<p class="mt-1 text-ink-muted">
|
|
{{ isSuperadmin ? $t("users.everyone") : $t("users.membersOf", { org: currentUser?.organizationName }) }}
|
|
</p>
|
|
</div>
|
|
<DwButton variant="primary" @click="startNew">{{ $t("users.new") }}</DwButton>
|
|
</div>
|
|
|
|
<div class="mt-4 flex flex-wrap gap-2">
|
|
<input
|
|
v-model="search"
|
|
type="search"
|
|
:placeholder="$t('users.search')"
|
|
:aria-label="$t('users.searchLabel')"
|
|
class="dw-input sm:w-64"
|
|
/>
|
|
<select v-if="isSuperadmin" v-model="orgFilter" :aria-label="$t('users.filterOrg')" class="dw-input sm:w-56">
|
|
<option value="">{{ $t("users.allOrgs") }}</option>
|
|
<option value="none">{{ $t("common.noOrganization") }}</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" ? $t("users.new") : $t("users.editTitle", { email: editing.email }) }}
|
|
</h2>
|
|
<label class="flex flex-col gap-1.5">
|
|
<span class="text-ui-sm font-semibold">{{ $t("common.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">{{ $t("common.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" ? $t("common.password") : $t("users.newPassword")
|
|
}}</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">{{ $t("common.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">{{ $t("users.ownRole") }}</span>
|
|
</label>
|
|
<label v-if="isSuperadmin" class="flex flex-col gap-1.5">
|
|
<span class="text-ui-sm font-semibold">{{ $t("common.organization") }}</span>
|
|
<select v-model="form.organization" class="dw-input">
|
|
<option value="">{{ $t("common.noOrganization") }}</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">{{ $t("common.status") }}</span>
|
|
<select v-model="form.status" :disabled="isSelf" class="dw-input">
|
|
<option value="active">{{ $t("userStatus.active") }}</option>
|
|
<option value="disabled">{{ $t("userStatus.disabled") }}</option>
|
|
</select>
|
|
</label>
|
|
<div class="flex gap-2 sm:col-span-2">
|
|
<DwButton type="submit" variant="primary" :disabled="busy">{{
|
|
editing === "new" ? $t("users.createUser") : $t("common.save")
|
|
}}</DwButton>
|
|
<DwButton variant="ghost" :disabled="busy" @click="editing = null">{{ $t("common.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">{{ $t("common.name") }}</th>
|
|
<th class="px-4 py-2 font-medium">{{ $t("common.email") }}</th>
|
|
<th class="px-4 py-2 font-medium">{{ $t("common.role") }}</th>
|
|
<th v-if="isSuperadmin" class="px-4 py-2 font-medium">{{ $t("common.organization") }}</th>
|
|
<th class="px-4 py-2 font-medium">{{ $t("common.status") }}</th>
|
|
<th class="px-4 py-2">
|
|
<span class="sr-only">{{ $t("common.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'">{{
|
|
$t(`userStatus.${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)">{{ $t("common.edit") }}</DwButton>
|
|
<DwButton variant="ghost" size="sm" :disabled="busy" @click="sendReset(u)">{{
|
|
$t("users.resetPassword")
|
|
}}</DwButton>
|
|
<DwButton v-if="u.totp" variant="ghost" size="sm" :disabled="busy" @click="resetTotp(u)">{{
|
|
$t("users.turnOffTotp")
|
|
}}</DwButton>
|
|
<DwButton
|
|
v-if="u.id !== currentUser?.id"
|
|
variant="ghost"
|
|
size="sm"
|
|
class="!text-danger"
|
|
:disabled="busy"
|
|
@click="remove(u)"
|
|
>
|
|
{{ $t("common.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">
|
|
{{ $t("users.none") }}
|
|
</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--">{{ $t("common.previous") }}</DwButton>
|
|
<span class="text-ink-muted">{{ $t("common.pageOf", { page, total: Math.ceil(list.totalItems / perPage) }) }}</span>
|
|
<DwButton size="sm" :disabled="page * perPage >= list.totalItems" @click="page++">{{ $t("common.next") }}</DwButton>
|
|
</div>
|
|
</template>
|