diff --git a/ui/src/archie/GroupsView.vue b/ui/src/archie/GroupsView.vue index a978065b6..cca8f1136 100644 --- a/ui/src/archie/GroupsView.vue +++ b/ui/src/archie/GroupsView.vue @@ -1,30 +1,53 @@ @@ -76,35 +146,90 @@ onBeforeUnmount(() => controller.abort()); No unmatched events - {{ actionError }} - - - - Trigger - Events - Last seen - Workflow - - - - - - {{ g.proposed.source }} {{ g.proposed.event_type }} - {{ filterText(g.proposed.filter) }} - - {{ g.count }} - - - - - - Create - - - - - - + + + + {{ g.count }} events, last + + + {{ errors[g.id] }} + Draft + + + {{ d.summary }} + + + + + + + {{ policyKinds.find((k) => k.value === editing[g.id]!.policy_kind)?.label }} + + + + {{ k.label }} + + + + + + Save + Cancel + + + + + + Dry run + {{ d.dry_run.state }} + + + {{ d.dry_run.error }} + {{ d.dry_run.findings }} + + + + Action + Judgement + Result + + + + + + {{ a.action }} + {{ a.target }} + + + {{ levelLabel(a.level) }} + {{ a.why }} + + + {{ outcomeLabel(a) }} + {{ a.ask.join(", then ") }} + + + + + No actions proposed. + + Would send: {{ d.dry_run.notice.title }}. {{ d.dry_run.notice.body }} + + + + + Dry run + Edit + Publish + + + + diff --git a/ui/src/archie/api.ts b/ui/src/archie/api.ts index 2a6b4e3bc..cb817fa22 100644 --- a/ui/src/archie/api.ts +++ b/ui/src/archie/api.ts @@ -210,10 +210,14 @@ async function put(path: string, payload: unknown): Promise { } async function putJSON(path: string, payload: unknown): Promise { + return send("PUT", path, payload); +} + +async function send(method: string, path: string, payload?: unknown): Promise { const res = await fetch(path, { - method: "PUT", + method, headers: { Authorization: `Bearer ${token()}`, "Content-Type": "application/json" }, - body: JSON.stringify(payload), + body: payload === undefined ? undefined : JSON.stringify(payload), }); if (res.status === 401) throw new Unauthorized("The admin token was refused."); if (!res.ok) { @@ -330,8 +334,54 @@ export interface EventGroup { export const listGroups = (signal?: AbortSignal) => get("/api/groups", signal); -export const saveTrigger = (name: string, trigger: EventGroup["proposed"]) => - put(`/api/triggers/${encodeURIComponent(name)}`, trigger); +/** What a dry run did with one action: only reads ran; everything else was judged and left alone. */ +export interface DryAction { + action: string; + target: string; + summary?: string; + level: Level; + outcome: "ran" | "would_run" | "would_ask" | "refused"; + why?: string; + ask?: string[]; +} + +export interface DryReport { + run_id: string; + state: Run["state"]; + error?: string; + findings?: string; + actions: DryAction[]; + notice?: { title: string; body: string }; + at: string; +} + +/** The trigger, workflow and policy an unmatched group could become, with its latest dry run. */ +export interface Draft { + id: string; + group_id: string; + name: string; + trigger: { source: string; event_type: string; filter: Record }; + workflow: string; + policy_kind: "hard_rules" | "change_request"; + policy: string; + summary: string; + dry_run?: DryReport; + dry_event_id?: string; + published_at?: string; +} + +export interface DraftEdit { + name: string; + workflow: string; + policy_kind: Draft["policy_kind"]; + policy: string; +} + +export const listDrafts = (signal?: AbortSignal) => get("/api/drafts", signal); +export const createDraft = (groupId: string) => send("POST", `/api/groups/${encodeURIComponent(groupId)}/draft`); +export const saveDraft = (id: string, edit: DraftEdit) => send("PUT", `/api/drafts/${encodeURIComponent(id)}`, edit); +export const dryRunDraft = (id: string) => send("POST", `/api/drafts/${encodeURIComponent(id)}/dry-run`); +export const publishDraft = (id: string) => send("POST", `/api/drafts/${encodeURIComponent(id)}/publish`); export const listRuns =(signal?: AbortSignal) => get("/api/runs", signal); export const runTrail = (id: string, signal?: AbortSignal) => get(`/api/runs/${encodeURIComponent(id)}`, signal);
{{ actionError }}
{{ errors[g.id] }}
{{ d.summary }}
{{ d.dry_run.error }}
{{ d.dry_run.findings }}
No actions proposed.
+ Would send: {{ d.dry_run.notice.title }}. {{ d.dry_run.notice.body }} +