98 lines
5.1 KiB
Vue
98 lines
5.1 KiB
Vue
<script setup lang="ts">
|
||
import { storeToRefs } from "pinia";
|
||
import { onMounted } from "vue";
|
||
|
||
import PageHeader from "@/base/PageHeader.vue";
|
||
import { Badge } from "@/components/ui/badge";
|
||
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 { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||
import { Section } from "@/components/ui/section";
|
||
import { Spinner } from "@/components/ui/spinner";
|
||
import { Timestamp } from "@/components/ui/timestamp";
|
||
import { useDecisionsStore } from "@/stores/decisions";
|
||
import UserReference from "@/org/UserReference.vue";
|
||
import { decisionResource, type AccessDecision } from "./decisions";
|
||
|
||
const store = useDecisionsStore();
|
||
const { decisions, filters, more, loading, error } = storeToRefs(store);
|
||
|
||
const columns: DataTableColumn<AccessDecision>[] = [
|
||
{ id: "at", label: "When", fixed: true, width: "9rem", sort: (d) => d.at },
|
||
{ id: "principal", label: "Principal", fixed: true, width: "auto", class: "whitespace-normal" },
|
||
{ id: "outcome", label: "Outcome", width: "7rem" },
|
||
{ id: "action", label: "Action", width: "12rem" },
|
||
{ id: "resource", label: "Resource", width: "14rem", class: "whitespace-normal" },
|
||
{ id: "level", label: "Level", width: "6rem" },
|
||
{ id: "policies", label: "Deciding policies", hide: "md", width: "14rem", class: "whitespace-normal" },
|
||
{ id: "count", label: "Count", width: "6rem", sort: (d) => d.count },
|
||
];
|
||
|
||
onMounted(() => void store.load());
|
||
</script>
|
||
|
||
<template>
|
||
<div>
|
||
<PageHeader title="Access decisions">
|
||
<Button variant="outline" size="sm" :disabled="loading" @click="store.load()">Refresh</Button>
|
||
</PageHeader>
|
||
|
||
<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" />
|
||
<Select v-model="filters.outcome">
|
||
<SelectTrigger class="w-32" aria-label="Outcome"><SelectValue /></SelectTrigger>
|
||
<SelectContent>
|
||
<SelectItem value="any">Any outcome</SelectItem>
|
||
<SelectItem value="allowed">Allowed</SelectItem>
|
||
<SelectItem value="denied">Denied</SelectItem>
|
||
</SelectContent>
|
||
</Select>
|
||
<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 && !decisions.length" class="flex items-center gap-2 text-label text-fg-muted">
|
||
<Spinner />Loading decisions…
|
||
</p>
|
||
<Empty v-else-if="!error && !decisions.length">
|
||
<EmptyHeader><EmptyTitle>No decisions recorded</EmptyTitle></EmptyHeader>
|
||
</Empty>
|
||
<DataTable
|
||
v-else-if="!error || decisions.length"
|
||
:columns="columns"
|
||
:rows="decisions"
|
||
:row-key="(d) => `${d.at}:${d.principal}:${d.action}:${d.kind}:${d.resource}:${d.outcome}`"
|
||
storage-key="decisions"
|
||
>
|
||
<template #empty>
|
||
<Empty><EmptyHeader><EmptyTitle>No decisions recorded</EmptyTitle></EmptyHeader></Empty>
|
||
</template>
|
||
<template #cell-at="{ row }"><Timestamp :at="row.at" /></template>
|
||
<template #cell-outcome="{ row }">
|
||
<Badge :variant="row.outcome === 'allowed' ? 'ok' : 'danger'">{{ row.outcome === "allowed" ? "Allowed" : "Denied" }}</Badge>
|
||
</template>
|
||
<template #cell-action="{ row }"><span class="font-mono text-caption">{{ row.action }}</span></template>
|
||
<template #cell-principal="{ row }"><UserReference :id="row.principal" class="text-caption" /></template>
|
||
<template #cell-resource="{ row }"><span class="font-mono text-caption">{{ decisionResource(row) }}</span></template>
|
||
<template #cell-level="{ row }"><Badge variant="idle">{{ row.level }}</Badge></template>
|
||
<template #cell-policies="{ row }">
|
||
<span class="font-mono text-caption text-fg-muted">{{ row.policies.join(", ") || "–" }}</span>
|
||
</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>
|
||
</template>
|