fix(ui): stop offering an organisation the binary cannot create (#2150)

The organisations page could create one, and POST /api/orgs is not served: the
binary resolves a single organisation from the credential. The dialog and the
client method go, and the page lists what exists.

The gateway test missed it because it compared paths, not methods. It now reads
each request the client makes with the method it asks for, so a call to a path
the binary serves for another verb fails the gate.
This commit is contained in:
sam committed 2026-11-27 19:40:21 +11:00
1 parent 61d486fdc0
commit bf17e2471b
4 files changed
+86 -130

No files matched your search

+1 -5
View File
@@ -185,7 +185,7 @@ async function request<T = unknown>(
export const api = {
// The archie binary's module API; the wire types are below the object.
runs: (limit = 200, workflowId?: string, sysQuery?: string) =>
runs: (limit = 50, workflowId?: string, sysQuery?: string) =>
request<Run[]>("/api/runs" + qs({ limit, workflow_id: workflowId, sys_query: sysQuery })),
run: (id: string) => request<RunTrail>(`/api/runs/${encodeURIComponent(id)}`),
/** Queues a parked run again from the step that parked it, or from `from`. */
@@ -401,10 +401,6 @@ export const api = {
deletePolicy: (policy: unknown) =>
request<void>("/api/access/policies", { method: "DELETE", body: policy, parse: false }),
orgs: <T = unknown>() => request<T>("/api/orgs"),
// orgCreate makes an org with its default workspace and first owner; only
// an instance admin may.
orgCreate: <T = unknown>(org: { id: string; name: string; owner_identity: string }) =>
request<T>("/api/orgs", { method: "POST", body: org }),
org: <T = unknown>(id: string) => request<T>(`/api/orgs/${encodeURIComponent(id)}`),
// renameOrg changes the org's display name; expected_version refuses a save
// made from a name someone else has since changed.
-105
View File
@@ -1,105 +0,0 @@
<script setup lang="ts">
import { Alert, AlertDescription } from "@/components/ui/alert";
import { computed, ref } from "vue";
import { Plus } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { api, describeError } from "@/lib/api";
import { errors } from "@/copy/errors";
import { useOrgStore } from "@/stores/org";
import type { Org } from "./org";
/** Creates an org with its default workspace and first owner, then opens it. */
const open = ref(false);
const id = ref("");
const name = ref("");
const owner = ref("");
const error = ref("");
const busy = ref(false);
const identities = useOrgStore();
// The owner has to be an identity that already exists, so the candidates are the
// members of the caller's organisation.
const people = computed(() =>
(identities.membersByOrg.get(identities.homeOrg) ?? []).filter((member) => member.kind !== "system" && member.status === "active"),
);
function opened(value: boolean): void {
open.value = value;
if (value) {
void identities.loadOrg()
.then(() => identities.readMembers(identities.homeOrg))
.catch((cause) => (error.value = describeError(cause, errors.common.unknown)));
}
}
async function create(): Promise<void> {
busy.value = true;
try {
const created = await api.orgCreate<{ org: Org }>({
id: id.value.trim(),
name: name.value.trim(),
owner_identity: owner.value,
});
await identities.loadOrg(true);
identities.viewOrg(created.org.id);
open.value = false;
id.value = name.value = owner.value = error.value = "";
} catch (cause) {
error.value = describeError(cause, errors.common.unknown);
} finally {
busy.value = false;
}
}
</script>
<template>
<Dialog :open="open" @update:open="opened">
<DialogTrigger as-child>
<Button size="sm" variant="outline"><Plus data-icon="inline-start" />New org</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>New org</DialogTitle>
</DialogHeader>
<form id="new-org" class="flex flex-col gap-3" @submit.prevent="create">
<Input v-model="name" placeholder="Name" aria-label="Org name" required />
<Input v-model="id" class="font-mono" placeholder="id" aria-label="Org id" required />
<Select v-model="owner">
<SelectTrigger class="w-full" aria-label="Owner">
<SelectValue placeholder="Owner" />
</SelectTrigger>
<SelectContent>
<SelectItem v-for="person in people" :key="person.identity_id" :value="person.identity_id">
{{ person.display_name }}
</SelectItem>
</SelectContent>
</Select>
<Alert v-if="error" variant="destructive"><AlertDescription>{{ error }}</AlertDescription></Alert>
</form>
<DialogFooter>
<Button
type="submit"
form="new-org"
:disabled="!id.trim() || !name.trim() || !owner || busy"
>Create</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</template>
+1 -2
View File
@@ -20,7 +20,6 @@ import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemTitle } from "@/components/ui/item";
import NewOrgDialog from "@/org/NewOrgDialog.vue";
import { useOrgStore } from "@/stores/org";
import { errors } from "@/copy/errors";
import { describeError } from "@/lib/api";
@@ -51,7 +50,7 @@ function open(id: string): void {
<template>
<div>
<PageHeader title="Organisations"><NewOrgDialog /></PageHeader>
<PageHeader title="Organisations" />
<Alert v-if="error" variant="destructive" class="mb-4"><AlertDescription>{{ error }}</AlertDescription></Alert>
<Empty v-else-if="!orgs.length"><EmptyHeader><EmptyTitle>No organisations</EmptyTitle></EmptyHeader></Empty>
<ItemGroup v-else class="gap-2">