Accounts, groups, invites and activity each wrote the same first load: clear the error, try, put the server's reason or a fallback in error, and stop loading. useLoad (composables/useAction.ts) is that, and its load() is also the retry. Kept: ShareDialog and Settings. Their load sets loading back to true on a reload, which the lists never did, so moving them would change what a retry shows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
3.5 KiB
Vue
120 lines
3.5 KiB
Vue
<script setup lang="ts">
|
|
import { onMounted, ref } from "vue";
|
|
import { api } from "../api/client";
|
|
import { errorMessage } from "../api/errors";
|
|
import { formatShortDateTime } from "../notes/datetime";
|
|
import { useLoad } from "../composables/useAction";
|
|
|
|
// Admin: what has happened to accounts on this instance, newest first (#2939 §5).
|
|
// Kept for `audit_retention_days` (Settings → Security).
|
|
|
|
interface AuditEvent {
|
|
id: string;
|
|
at: string;
|
|
event: string;
|
|
email: string | null;
|
|
address: string | null;
|
|
detail: string | null;
|
|
}
|
|
|
|
// One phrase per event name in `audit.py`. A new event needs a line here.
|
|
const WORDS: Record<string, string> = {
|
|
sign_in: "Signed in",
|
|
sign_in_failed: "Sign-in failed",
|
|
registered: "Account created",
|
|
registration_refused: "Sign-up refused",
|
|
reset_requested: "Reset email asked for",
|
|
reset_link_made: "Reset link made",
|
|
password_reset: "Password reset",
|
|
reset_refused: "Reset link refused",
|
|
password_changed: "Password changed",
|
|
password_change_refused: "Password change refused",
|
|
signed_out_elsewhere: "Signed out elsewhere",
|
|
device_linked: "Device linked",
|
|
device_unlinked: "Device unlinked",
|
|
invite_created: "Invite made",
|
|
invite_revoked: "Invite revoked",
|
|
};
|
|
|
|
// Shown in red: something was tried and refused.
|
|
const REFUSALS = new Set([
|
|
"sign_in_failed",
|
|
"registration_refused",
|
|
"reset_refused",
|
|
"password_change_refused",
|
|
]);
|
|
|
|
const events = ref<AuditEvent[]>([]);
|
|
const more = ref(false);
|
|
const { loading, error, load } = useLoad(async () => {
|
|
const res = await page();
|
|
events.value = res.events;
|
|
more.value = res.more;
|
|
}, "Couldn't load activity.");
|
|
const loadingMore = ref(false);
|
|
|
|
async function page(before?: string) {
|
|
const query = before ? `?before=${encodeURIComponent(before)}` : "";
|
|
return api.get<{ events: AuditEvent[]; more: boolean }>(`/api/accounts/activity${query}`);
|
|
}
|
|
|
|
async function loadMore() {
|
|
const last = events.value[events.value.length - 1];
|
|
if (!last) return;
|
|
loadingMore.value = true;
|
|
try {
|
|
const res = await page(last.at);
|
|
events.value.push(...res.events);
|
|
more.value = res.more;
|
|
} catch (e) {
|
|
error.value = errorMessage(e, "Couldn't load older activity.");
|
|
} finally {
|
|
loadingMore.value = false;
|
|
}
|
|
}
|
|
|
|
function where(e: AuditEvent): string {
|
|
return [formatShortDateTime(e.at), e.address, e.detail].filter(Boolean).join(" · ");
|
|
}
|
|
|
|
onMounted(() => {
|
|
void load();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<section class="flex flex-col gap-5">
|
|
<h2 class="section-label">Activity</h2>
|
|
|
|
<p v-if="error" class="form-error">{{ error }}</p>
|
|
|
|
<div v-if="loading" class="list-empty">Loading…</div>
|
|
<p v-else-if="!events.length" class="text-sm text-neutral-400">Nothing yet.</p>
|
|
<ul v-else class="flex flex-col gap-2">
|
|
<li
|
|
v-for="e in events"
|
|
:key="e.id"
|
|
class="rounded-xl border border-neutral-200 px-4 py-3 dark:border-neutral-800"
|
|
>
|
|
<p class="truncate text-sm font-medium text-neutral-800 dark:text-neutral-100">
|
|
<span :class="REFUSALS.has(e.event) ? 'text-red-600 dark:text-red-400' : ''">
|
|
{{ WORDS[e.event] ?? e.event }}
|
|
</span>
|
|
<span v-if="e.email" class="font-normal text-neutral-500"> · {{ e.email }}</span>
|
|
</p>
|
|
<p class="truncate text-xs text-neutral-400">{{ where(e) }}</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<button
|
|
v-if="more"
|
|
type="button"
|
|
class="self-start btn-sm"
|
|
:disabled="loadingMore"
|
|
@click="loadMore"
|
|
>
|
|
Show older
|
|
</button>
|
|
</section>
|
|
</template>
|