feat(ui): members, policies and denials pages use the binary's access API (#2023)
This commit is contained in:
6 files changed
+116
-21
No files matched your search
@@ -8,6 +8,7 @@ import { ReadError } from "@/components/ui/read-error";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
@@ -15,7 +16,7 @@ import { useDenialsStore } from "@/stores/denials";
|
||||
import { denialResource, type Denial } from "./denials";
|
||||
|
||||
const store = useDenialsStore();
|
||||
const { denials, loading, error } = storeToRefs(store);
|
||||
const { denials, filters, more, loading, error } = storeToRefs(store);
|
||||
|
||||
const columns: DataTableColumn<Denial>[] = [
|
||||
{ id: "at", label: "When", fixed: true, sort: (d) => d.at },
|
||||
@@ -39,6 +40,15 @@ onMounted(() => void store.load());
|
||||
<ReadError v-if="error" :message="error" retry-label="Retry" class="mb-4" @retry="store.load()" />
|
||||
|
||||
<Section>
|
||||
<form class="mb-3 flex flex-wrap items-center gap-2" @submit.prevent="store.load()">
|
||||
<Input v-model="filters.principal" class="w-48" aria-label="Principal" placeholder="Principal" />
|
||||
<Input v-model="filters.action" class="w-36" aria-label="Action" placeholder="Action" />
|
||||
<Input v-model="filters.kind" class="w-36" aria-label="Resource kind" placeholder="Resource kind" />
|
||||
<Input v-model="filters.since" type="datetime-local" class="w-52" aria-label="From" />
|
||||
<Input v-model="filters.until" type="datetime-local" class="w-52" aria-label="Until" />
|
||||
<Button type="submit" size="sm" :disabled="loading">Filter</Button>
|
||||
<Button type="button" variant="outline" size="sm" :disabled="loading" @click="store.clear()">Clear</Button>
|
||||
</form>
|
||||
<div class="flex flex-col gap-3">
|
||||
<p v-if="loading && !denials.length" class="flex items-center gap-2 text-label text-fg-muted">
|
||||
<Spinner />Loading denials…
|
||||
@@ -57,6 +67,7 @@ onMounted(() => void store.load());
|
||||
<Empty><EmptyHeader><EmptyTitle>No denials recorded</EmptyTitle></EmptyHeader></Empty>
|
||||
</template>
|
||||
<template #cell-at="{ row }"><Timestamp :at="row.at" /></template>
|
||||
<template #cell-action="{ row }"><span class="font-mono text-caption">{{ row.action }}</span></template>
|
||||
<template #cell-principal="{ row }"><span class="font-mono text-caption">{{ row.principal }}</span></template>
|
||||
<template #cell-resource="{ row }"><span class="font-mono text-caption">{{ denialResource(row) }}</span></template>
|
||||
<template #cell-level="{ row }"><Badge variant="idle">{{ row.level }}</Badge></template>
|
||||
@@ -65,6 +76,7 @@ onMounted(() => void store.load());
|
||||
</template>
|
||||
<template #cell-count="{ row }"><span class="tabular-nums">{{ row.count }}</span></template>
|
||||
</DataTable>
|
||||
<Button v-if="more" variant="outline" size="sm" class="self-start" :disabled="loading" @click="store.load(true)">Load older</Button>
|
||||
</div>
|
||||
</Section>
|
||||
</div>
|
||||
|
||||
@@ -14,6 +14,8 @@ export interface Denial {
|
||||
|
||||
export interface DenialsResponse {
|
||||
denials: Denial[];
|
||||
/** Whether older refusals match beyond this page. */
|
||||
more: boolean;
|
||||
}
|
||||
|
||||
/** The resource column: the kind and id together, or just the kind. */
|
||||
|
||||
+13
-2
@@ -281,8 +281,8 @@ export const api = {
|
||||
health: <T = unknown>() => request<T>("/health/detailed"),
|
||||
services: <T = unknown>() => request<T>("/api/services"),
|
||||
policies: <T = unknown>() => request<T>("/api/access/policies"),
|
||||
denials: <T = unknown>(limit?: number) =>
|
||||
request<T>(`/api/access/denials${limit ? `?limit=${limit}` : ""}`),
|
||||
denials: <T = unknown>(params: QueryParams = {}) =>
|
||||
request<T>("/api/access/denials" + qs(params)),
|
||||
putPolicy: (policy: unknown) =>
|
||||
request<{ version: number }>("/api/access/policies", { method: "PUT", body: policy }),
|
||||
deletePolicy: (policy: unknown) =>
|
||||
@@ -359,6 +359,17 @@ export const api = {
|
||||
qs({ workspace }),
|
||||
{ method: "DELETE", parse: false },
|
||||
),
|
||||
/** Suspending stops a member acting at once; their memberships stay. */
|
||||
suspendOrgMember: (id: string, identity: string) =>
|
||||
request<void>(
|
||||
`/api/orgs/${encodeURIComponent(id)}/members/${encodeURIComponent(identity)}/suspend`,
|
||||
{ method: "POST", parse: false },
|
||||
),
|
||||
reactivateOrgMember: (id: string, identity: string) =>
|
||||
request<void>(
|
||||
`/api/orgs/${encodeURIComponent(id)}/members/${encodeURIComponent(identity)}/reactivate`,
|
||||
{ method: "POST", parse: false },
|
||||
),
|
||||
assignOrgAgent: <T = unknown>(id: string, identity: string) =>
|
||||
request<T>(
|
||||
`/api/orgs/${encodeURIComponent(id)}/agents/${encodeURIComponent(identity)}`,
|
||||
|
||||
@@ -7,7 +7,10 @@ import CreateAccount from "@/accounts/CreateAccount.vue";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { Plus, Trash2 } from "@lucide/vue";
|
||||
import { Pause, Play, Plus, Trash2 } from "@lucide/vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -128,6 +131,16 @@ const setRole = (member: Member, role: unknown) =>
|
||||
await load();
|
||||
});
|
||||
|
||||
const toggleStatus = (member: Member) =>
|
||||
run(member.identity_id + "status", async () => {
|
||||
if (!org.value) return;
|
||||
await (member.status === "suspended" ? api.reactivateOrgMember : api.suspendOrgMember)(
|
||||
org.value.id,
|
||||
member.identity_id,
|
||||
);
|
||||
await load();
|
||||
});
|
||||
|
||||
const pending = ref<Member | null>(null);
|
||||
const remove = (member: Member) =>
|
||||
run(member.identity_id + (member.workspace_id ?? ""), async () => {
|
||||
@@ -151,7 +164,9 @@ const remove = (member: Member) =>
|
||||
<TableHead class="w-28">Kind</TableHead>
|
||||
<TableHead class="w-44">Workspace</TableHead>
|
||||
<TableHead class="w-44">Role</TableHead>
|
||||
<TableHead class="w-24 text-right">Actions</TableHead>
|
||||
<TableHead class="w-28">Status</TableHead>
|
||||
<TableHead class="w-40">Last sign-in</TableHead>
|
||||
<TableHead class="w-28 text-right">Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
@@ -169,7 +184,22 @@ const remove = (member: Member) =>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</TableCell>
|
||||
<TableCell><Badge :variant="member.status === 'active' ? 'ok' : 'idle'">{{ member.status }}</Badge></TableCell>
|
||||
<TableCell class="text-label text-fg-subtle"><Timestamp v-if="member.last_sign_in" :at="member.last_sign_in" /><template v-else>–</template></TableCell>
|
||||
<TableCell class="text-right">
|
||||
<Tooltip v-if="!member.workspace_id && member.kind !== 'system'">
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
:aria-label="`${member.status === 'suspended' ? 'Reactivate' : 'Suspend'} ${member.display_name}`"
|
||||
:disabled="busy !== ''"
|
||||
@click="toggleStatus(member)"
|
||||
><Play v-if="member.status === 'suspended'" /><Pause v-else
|
||||
/></Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{{ member.status === "suspended" ? "Reactivate" : "Suspend" }}</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
@@ -177,7 +207,7 @@ const remove = (member: Member) =>
|
||||
size="icon"
|
||||
:aria-label="`Remove ${member.display_name}`"
|
||||
:disabled="busy !== ''"
|
||||
@click="remove(member)"
|
||||
@click="pending = member"
|
||||
><Trash2
|
||||
/></Button>
|
||||
</TooltipTrigger>
|
||||
@@ -186,10 +216,10 @@ const remove = (member: Member) =>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<TableRow v-if="loading">
|
||||
<TableCell colspan="5" class="text-label text-fg-muted" role="status">Loading members…</TableCell>
|
||||
<TableCell colspan="7" class="text-label text-fg-muted" role="status">Loading members…</TableCell>
|
||||
</TableRow>
|
||||
<TableRow v-else-if="!members.length && !error">
|
||||
<TableCell colspan="5">
|
||||
<TableCell colspan="7">
|
||||
<Empty class="py-6">
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>No members yet</EmptyTitle>
|
||||
@@ -202,8 +232,8 @@ const remove = (member: Member) =>
|
||||
</Section>
|
||||
|
||||
<CreateAccount v-if="org?.id===identities.homeOrg" @created="load" />
|
||||
<div class="grid gap-4 lg:grid-cols-2">
|
||||
<Section title="Add an identity" class="mb-0">
|
||||
<div class="grid gap-4" :class="candidates.length ? 'lg:grid-cols-2' : ''">
|
||||
<Section v-if="candidates.length" title="Add an identity" class="mb-0">
|
||||
<form class="flex flex-wrap items-center gap-2" @submit.prevent="add">
|
||||
<Select v-model="picked">
|
||||
<SelectTrigger class="w-64" aria-label="Identity">
|
||||
|
||||
@@ -47,4 +47,7 @@ export interface Member {
|
||||
display_name: string;
|
||||
workspace_id?: string;
|
||||
role: Role;
|
||||
/** The identity's lifecycle; a suspended member keeps the role but cannot act. */
|
||||
status: "active" | "suspended" | "retired";
|
||||
last_sign_in?: string;
|
||||
}
|
||||
+48
-11
@@ -1,31 +1,68 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { reactive, ref } from "vue";
|
||||
|
||||
import type { Denial, DenialsResponse } from "@/audit/denials";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { ApiError, api, describeError } from "@/lib/api";
|
||||
|
||||
/** The caller's org's recorded access denials, newest first. */
|
||||
const PAGE = 100;
|
||||
|
||||
/** What narrows the list; an empty field matches everything. `since` and
|
||||
* `until` are datetime-local values, read in the browser's time zone. */
|
||||
export interface DenialFilters {
|
||||
principal: string;
|
||||
action: string;
|
||||
kind: string;
|
||||
since: string;
|
||||
until: string;
|
||||
}
|
||||
|
||||
const noFilters = (): DenialFilters => ({ principal: "", action: "", kind: "", since: "", until: "" });
|
||||
|
||||
const toISO = (local: string): string => (local ? new Date(local).toISOString() : "");
|
||||
|
||||
/** The caller's org's recorded access denials, newest first, a page at a time. */
|
||||
export const useDenialsStore = defineStore("denials", () => {
|
||||
const denials = ref<Denial[]>([]);
|
||||
const filters = reactive<DenialFilters>(noFilters());
|
||||
const more = ref(false);
|
||||
const loading = ref(false);
|
||||
const error = ref("");
|
||||
// A response for filters or a page the operator has since replaced is dropped.
|
||||
let attempt = 0;
|
||||
|
||||
async function load(): Promise<void> {
|
||||
/** load reads the first page, or the next one after those already shown. */
|
||||
async function load(next = false): Promise<void> {
|
||||
const mine = ++attempt;
|
||||
loading.value = true;
|
||||
try {
|
||||
denials.value = (await api.denials<DenialsResponse>()).denials ?? [];
|
||||
const response = await api.denials<DenialsResponse>({
|
||||
principal: filters.principal.trim(),
|
||||
action: filters.action.trim(),
|
||||
kind: filters.kind.trim(),
|
||||
since: toISO(filters.since),
|
||||
until: toISO(filters.until),
|
||||
limit: PAGE,
|
||||
offset: next ? denials.value.length : 0,
|
||||
});
|
||||
if (mine !== attempt) return;
|
||||
denials.value = next ? [...denials.value, ...(response.denials ?? [])] : (response.denials ?? []);
|
||||
more.value = response.more;
|
||||
error.value = "";
|
||||
} catch (err) {
|
||||
if (err instanceof ApiError && err.status === 503) {
|
||||
error.value = errors.stores.denials.unavailable;
|
||||
} else {
|
||||
error.value = describeError(err, errors.common.unknown);
|
||||
}
|
||||
if (mine !== attempt) return;
|
||||
error.value = err instanceof ApiError && err.status === 503
|
||||
? errors.stores.denials.unavailable
|
||||
: describeError(err, errors.common.unknown);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
if (mine === attempt) loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
return { denials, loading, error, load };
|
||||
function clear(): void {
|
||||
Object.assign(filters, noFilters());
|
||||
void load();
|
||||
}
|
||||
|
||||
return { denials, filters, more, loading, error, load, clear };
|
||||
});
|
||||
Reference in new issue
Block a user