Delete policy, remove member, revoke token, remove passkey and delete source now open the shared AlertDialog confirmation that names the item, matching the binding/mapping/event-type deletes that already confirmed.
190 lines
6.6 KiB
Vue
190 lines
6.6 KiB
Vue
<script setup lang="ts">
|
|
import { Spinner } from "@/components/ui/spinner";
|
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
|
|
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
|
import PageHeader from "@/base/PageHeader.vue";
|
|
import { computed, onMounted, ref } from "vue";
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Section } from "@/components/ui/section";
|
|
import { Input } from "@/components/ui/input";
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select";
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
import { api } from "@/lib/api";
|
|
|
|
type Level = "instance" | "org" | "workspace" | "object";
|
|
|
|
interface Policy {
|
|
id: string;
|
|
level: Level;
|
|
org_id?: string;
|
|
workspace_id?: string;
|
|
object_kind?: string;
|
|
object_id?: string;
|
|
text: string;
|
|
}
|
|
|
|
const policies = ref<Policy[]>([]);
|
|
const shipped = ref<string[]>([]);
|
|
const error = ref<string | null>(null);
|
|
const saving = ref(false);
|
|
const loading = ref(true);
|
|
|
|
const blank = (): Policy => ({ id: "", level: "org", text: "" });
|
|
const draft = ref<Policy>(blank());
|
|
const editing = ref(false);
|
|
|
|
const scope = (p: Policy) =>
|
|
p.level === "workspace"
|
|
? p.workspace_id
|
|
: p.level === "object"
|
|
? `${p.object_kind}/${p.object_id}`
|
|
: "";
|
|
|
|
const canSave = computed(
|
|
() =>
|
|
draft.value.id.trim() !== "" &&
|
|
draft.value.text.trim() !== "" &&
|
|
(draft.value.level !== "workspace" || !!draft.value.workspace_id) &&
|
|
(draft.value.level !== "object" ||
|
|
(!!draft.value.object_kind && !!draft.value.object_id)),
|
|
);
|
|
|
|
async function load(): Promise<void> {
|
|
loading.value = true;
|
|
try {
|
|
const response = await api.policies<{ policies: Policy[]; shipped: string[] }>();
|
|
policies.value = response.policies;
|
|
shipped.value = response.shipped;
|
|
error.value = null;
|
|
} catch (err) {
|
|
error.value = (err as Error).message;
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
|
|
function edit(p: Policy): void {
|
|
draft.value = { ...p };
|
|
editing.value = true;
|
|
}
|
|
|
|
async function save(): Promise<void> {
|
|
saving.value = true;
|
|
try {
|
|
await api.putPolicy(draft.value);
|
|
draft.value = blank();
|
|
editing.value = false;
|
|
await load();
|
|
} catch (err) {
|
|
error.value = (err as Error).message;
|
|
} finally {
|
|
saving.value = false;
|
|
}
|
|
}
|
|
|
|
const pending = ref<Policy | null>(null);
|
|
async function remove(p: Policy): Promise<void> {
|
|
try {
|
|
await api.deletePolicy(p);
|
|
await load();
|
|
} catch (err) {
|
|
error.value = (err as Error).message;
|
|
}
|
|
}
|
|
|
|
onMounted(load);
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<PageHeader title="Policies" />
|
|
|
|
<div v-if="error" role="alert" class="mb-4 text-label text-danger"><p>{{ error }}</p><Button variant="outline" size="sm" @click="load">Retry</Button></div>
|
|
|
|
<Section>
|
|
<template #action><Button size="sm" @click="editing = true">New policy</Button></template>
|
|
<div class="flex flex-col gap-3">
|
|
<p v-if="loading" class="flex items-center gap-2 text-label text-fg-muted"><Spinner />Loading policies…</p>
|
|
<Empty v-else-if="!error && !policies.length"><EmptyHeader><EmptyTitle>No policies yet</EmptyTitle></EmptyHeader></Empty>
|
|
<div
|
|
v-for="p in policies"
|
|
:key="`${p.level}/${scope(p)}/${p.id}`"
|
|
class="flex items-start justify-between gap-4 border-b pb-3 last:border-0"
|
|
>
|
|
<div class="min-w-0">
|
|
<div class="flex items-center gap-2 text-label">
|
|
<span class="font-mono font-medium">{{ p.id }}</span>
|
|
<Badge variant="default">{{ p.level }}</Badge>
|
|
<span v-if="scope(p)" class="font-mono text-fg-muted">{{ scope(p) }}</span>
|
|
<Badge v-if="shipped.includes(p.id)" variant="ok">shipped</Badge>
|
|
</div>
|
|
<pre class="mt-1 overflow-x-auto text-caption text-fg-muted">{{ p.text }}</pre>
|
|
</div>
|
|
<div class="flex shrink-0 gap-2">
|
|
<Button size="sm" variant="outline" @click="edit(p)">Edit</Button>
|
|
<Button size="sm" variant="outline" @click="pending = p">Delete</Button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Section>
|
|
|
|
<Section v-if="editing" :title="draft.id ? draft.id : 'New policy'">
|
|
<div class="flex flex-col gap-3">
|
|
<div class="flex flex-wrap gap-2">
|
|
<Input v-model="draft.id" placeholder="policy id" aria-label="Policy id" class="w-56" />
|
|
<Select v-model="draft.level">
|
|
<SelectTrigger class="w-40" aria-label="Level"><SelectValue /></SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="instance">instance</SelectItem>
|
|
<SelectItem value="org">org</SelectItem>
|
|
<SelectItem value="workspace">workspace</SelectItem>
|
|
<SelectItem value="object">object</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
<Input
|
|
v-if="draft.level === 'workspace'"
|
|
v-model="draft.workspace_id"
|
|
placeholder="workspace id"
|
|
aria-label="Workspace id"
|
|
class="w-48"
|
|
/>
|
|
<template v-if="draft.level === 'object'">
|
|
<Input v-model="draft.object_kind" placeholder="kind (secret, source...)" aria-label="Object kind" class="w-48" />
|
|
<Input v-model="draft.object_id" placeholder="object id" aria-label="Object id" class="w-48" />
|
|
</template>
|
|
</div>
|
|
<Textarea
|
|
v-model="draft.text"
|
|
class="min-h-40 font-mono text-caption"
|
|
aria-label="Cedar policy"
|
|
placeholder='permit(principal, action == Archie::Action::"read", resource);'
|
|
/>
|
|
<div class="flex gap-2">
|
|
<Button :disabled="!canSave || saving" @click="save">Save</Button>
|
|
<Button variant="outline" @click="(editing = false), (draft = blank())">Cancel</Button>
|
|
</div>
|
|
</div>
|
|
</Section>
|
|
</div>
|
|
<AlertDialog :open="pending !== null" @update:open="(v: boolean) => { if (!v) pending = null; }">
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>Delete policy?</AlertDialogTitle>
|
|
<AlertDialogDescription>Delete the policy "{{ pending?.id }}". This cannot be undone.</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
<AlertDialogAction @click="if (pending) { const p = pending; pending = null; void remove(p); }">Delete policy</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</template>
|