feat(approvals): add a People page, leave channel approvals unchanged, make a binding's target optional (#2072)
This commit is contained in:
8 files changed
+214
-10
No files matched your search
@@ -377,10 +377,6 @@ func (m *Module) Settle(ctx context.Context, id uuid.UUID, identity, via string,
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
who, err := m.verify(ctx, identity, row)
|
who, err := m.verify(ctx, identity, row)
|
||||||
if err == nil && approved && row.Irreversible {
|
|
||||||
// A channel message can't carry a passkey assertion.
|
|
||||||
err = ErrNeedsFreshAuthentication
|
|
||||||
}
|
|
||||||
if refusal(err) {
|
if refusal(err) {
|
||||||
m.log.WarnContext(ctx, "approval answer refused", "request", id, "identity", identity, "reason", err.Error())
|
m.log.WarnContext(ctx, "approval answer refused", "request", id, "identity", identity, "reason", err.Error())
|
||||||
return false, m.store.Refuse(ctx, store.Refusal{
|
return false, m.store.Refuse(ctx, store.Refusal{
|
||||||
|
|||||||
@@ -93,8 +93,6 @@ func (b Binding) complete() error {
|
|||||||
missing = "action"
|
missing = "action"
|
||||||
case len(bytes.TrimSpace(b.Input)) == 0:
|
case len(bytes.TrimSpace(b.Input)) == 0:
|
||||||
missing = "arguments"
|
missing = "arguments"
|
||||||
case b.Target.Kind == "" || b.Target.ID == "":
|
|
||||||
missing = "target"
|
|
||||||
case b.Approvers == nil:
|
case b.Approvers == nil:
|
||||||
missing = "approvers"
|
missing = "approvers"
|
||||||
case b.Expires.IsZero():
|
case b.Expires.IsZero():
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ func TestBindingDigestCoversTheWholeAction(t *testing.T) {
|
|||||||
{"the action", func(b *Binding) { b.Action = "forward" }},
|
{"the action", func(b *Binding) { b.Action = "forward" }},
|
||||||
{"the arguments", func(b *Binding) { b.Input = jsontext.Value(`{"to":"b@example.com","body":"hi"}`) }},
|
{"the arguments", func(b *Binding) { b.Input = jsontext.Value(`{"to":"b@example.com","body":"hi"}`) }},
|
||||||
{"the target's id", func(b *Binding) { b.Target.ID = "outbox" }},
|
{"the target's id", func(b *Binding) { b.Target.ID = "outbox" }},
|
||||||
|
{"a target removed", func(b *Binding) { b.Target = connectors.Target{} }},
|
||||||
{"the target's environment", func(b *Binding) { b.Target.Environment = "dev" }},
|
{"the target's environment", func(b *Binding) { b.Target.Environment = "dev" }},
|
||||||
{"the effect", func(b *Binding) { b.Effect.Reversibility = connectors.Recoverable }},
|
{"the effect", func(b *Binding) { b.Effect.Reversibility = connectors.Recoverable }},
|
||||||
{"the approvers", func(b *Binding) { b.Approvers = []string{bob} }},
|
{"the approvers", func(b *Binding) { b.Approvers = []string{bob} }},
|
||||||
@@ -103,8 +104,6 @@ func TestBindingDigestCoversTheWholeAction(t *testing.T) {
|
|||||||
{"connector", func(b *Binding) { b.Connector = "" }},
|
{"connector", func(b *Binding) { b.Connector = "" }},
|
||||||
{"action", func(b *Binding) { b.Action = "" }},
|
{"action", func(b *Binding) { b.Action = "" }},
|
||||||
{"arguments", func(b *Binding) { b.Input = nil }},
|
{"arguments", func(b *Binding) { b.Input = nil }},
|
||||||
{"target kind", func(b *Binding) { b.Target.Kind = "" }},
|
|
||||||
{"target id", func(b *Binding) { b.Target.ID = "" }},
|
|
||||||
{"approvers", func(b *Binding) { b.Approvers = nil }},
|
{"approvers", func(b *Binding) { b.Approvers = nil }},
|
||||||
{"expiry", func(b *Binding) { b.Expires = time.Time{} }},
|
{"expiry", func(b *Binding) { b.Expires = time.Time{} }},
|
||||||
}
|
}
|
||||||
@@ -262,6 +261,16 @@ func TestRunApprovedRunsOnlyWhatWasApprovedAndOnlyOnce(t *testing.T) {
|
|||||||
},
|
},
|
||||||
wantDiscard: "its target changed",
|
wantDiscard: "its target changed",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "a target appeared where there was none",
|
||||||
|
change: func(f *approvalFixture) {
|
||||||
|
b := baseBinding()
|
||||||
|
b.Target = connectors.Target{}
|
||||||
|
f.action.Binding, _ = json.Marshal(b)
|
||||||
|
f.action.BindingDigest, _ = b.Digest()
|
||||||
|
},
|
||||||
|
wantDiscard: "its target changed",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "the target changed and would now run unattended",
|
name: "the target changed and would now run unattended",
|
||||||
change: func(f *approvalFixture) {
|
change: func(f *approvalFixture) {
|
||||||
|
|||||||
@@ -612,7 +612,7 @@ func (m *Module) capabilities(ctx context.Context, _ *struct{}) (*httpapi.Reply[
|
|||||||
p, signedIn := PrincipalFromContext(ctx)
|
p, signedIn := PrincipalFromContext(ctx)
|
||||||
sections := map[string]bool{"chat": signedIn, "memory": signedIn}
|
sections := map[string]bool{"chat": signedIn, "memory": signedIn}
|
||||||
for _, name := range []string{
|
for _, name := range []string{
|
||||||
"settings", "events", "workflows", "runs", "credentials", "extensions", "secret_engines", "models", "controls", "memory_admin",
|
"settings", "org_people", "events", "workflows", "runs", "credentials", "extensions", "secret_engines", "models", "controls", "memory_admin",
|
||||||
} {
|
} {
|
||||||
sections[name] = p.InstanceAdmin()
|
sections[name] = p.InstanceAdmin()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -365,6 +365,9 @@ export const api = {
|
|||||||
alerts: <T = unknown>() => request<T>("/api/alerts"),
|
alerts: <T = unknown>() => request<T>("/api/alerts"),
|
||||||
dismissAlert: (id: number) =>
|
dismissAlert: (id: number) =>
|
||||||
request<void>(`/api/alerts/${id}/dismiss`, { method: "POST", parse: false }),
|
request<void>(`/api/alerts/${id}/dismiss`, { method: "POST", parse: false }),
|
||||||
|
people: () => request<Person[]>("/api/people"),
|
||||||
|
/** Replaces the organisation's people with the list. */
|
||||||
|
putPeople: (people: Person[]) => request<Person[]>("/api/people", { method: "PUT", body: people }),
|
||||||
identities: <T = unknown>() => request<T>("/api/identities"),
|
identities: <T = unknown>() => request<T>("/api/identities"),
|
||||||
identityCreate: <T = unknown>(identity: { display_name: string; kind: string }) =>
|
identityCreate: <T = unknown>(identity: { display_name: string; kind: string }) =>
|
||||||
request<T>("/api/identities", { method: "POST", body: identity }),
|
request<T>("/api/identities", { method: "POST", body: identity }),
|
||||||
@@ -678,6 +681,15 @@ export interface Run {
|
|||||||
result?: unknown;
|
result?: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A person who may answer approvals, and the identities they answer as. */
|
||||||
|
export interface Person {
|
||||||
|
/** Empty for a new person. */
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
authority: boolean;
|
||||||
|
identities: string[];
|
||||||
|
}
|
||||||
|
|
||||||
/** A passkey assertion made for one approval request. */
|
/** A passkey assertion made for one approval request. */
|
||||||
export interface ApprovalAssertion {
|
export interface ApprovalAssertion {
|
||||||
token: string;
|
token: string;
|
||||||
|
|||||||
+1
-1
@@ -35,7 +35,7 @@ const orgSpecs: NavSpec[] = [
|
|||||||
sections: [
|
sections: [
|
||||||
{
|
{
|
||||||
label: "People & access",
|
label: "People & access",
|
||||||
paths: ["/org/members", "/org/agents", "/org/workspaces", "/org/policies", "/org/denials", "/org/audit"],
|
paths: ["/org/members", "/org/people", "/org/agents", "/org/workspaces", "/org/policies", "/org/denials", "/org/audit"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Connections & models",
|
label: "Connections & models",
|
||||||
|
|||||||
@@ -0,0 +1,182 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted, ref } from "vue";
|
||||||
|
import { Link, Plus, Trash2, X } from "@lucide/vue";
|
||||||
|
|
||||||
|
import { useAccountsStore } from "@/accounts/accounts";
|
||||||
|
import PageHeader from "@/base/PageHeader.vue";
|
||||||
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Section } from "@/components/ui/section";
|
||||||
|
import { Switch } from "@/components/ui/switch";
|
||||||
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||||
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||||
|
import { errors } from "@/copy/errors";
|
||||||
|
import { api, describeError, type Person } from "@/lib/api";
|
||||||
|
import { useOrgStore } from "@/stores/org";
|
||||||
|
|
||||||
|
/** The people who answer approvals. Saving replaces the whole list, so each
|
||||||
|
* change sends the list with that one change and shows what the server kept. */
|
||||||
|
const people = ref<Person[]>([]);
|
||||||
|
const error = ref("");
|
||||||
|
const loading = ref(true);
|
||||||
|
const busy = ref(false);
|
||||||
|
const name = ref("");
|
||||||
|
const identity = ref<Record<string, string>>({});
|
||||||
|
|
||||||
|
const accounts = useAccountsStore();
|
||||||
|
const orgStore = useOrgStore();
|
||||||
|
orgStore.watchIdentities();
|
||||||
|
|
||||||
|
const accountPrefix = "account:";
|
||||||
|
const mine = () => (accounts.status?.user ? accountPrefix + accounts.status.user.id : "");
|
||||||
|
|
||||||
|
/** An account identity reads as the account's name; a channel identity as written. */
|
||||||
|
function label(value: string): string {
|
||||||
|
return value.startsWith(accountPrefix) ? orgStore.identityName(value.slice(accountPrefix.length)) : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load(): Promise<void> {
|
||||||
|
try {
|
||||||
|
people.value = await api.people();
|
||||||
|
error.value = "";
|
||||||
|
} catch (cause) {
|
||||||
|
error.value = describeError(cause, errors.common.unknown);
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
if (!accounts.status) await accounts.load();
|
||||||
|
await load();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function save(next: Person[]): Promise<void> {
|
||||||
|
busy.value = true;
|
||||||
|
try {
|
||||||
|
people.value = await api.putPeople(next);
|
||||||
|
error.value = "";
|
||||||
|
} catch (cause) {
|
||||||
|
error.value = describeError(cause, errors.common.unknown);
|
||||||
|
} finally {
|
||||||
|
busy.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const change = (person: Person, edit: Partial<Person>) =>
|
||||||
|
save(people.value.map((p) => (p === person ? { ...p, ...edit } : p)));
|
||||||
|
|
||||||
|
async function add(): Promise<void> {
|
||||||
|
const value = name.value.trim();
|
||||||
|
if (!value) return;
|
||||||
|
await save([...people.value, { id: "", name: value, authority: false, identities: [] }]);
|
||||||
|
if (!error.value) name.value = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const rename = (person: Person, event: Event) => {
|
||||||
|
const next = (event.target as HTMLInputElement).value.trim();
|
||||||
|
if (next && next !== person.name) void change(person, { name: next });
|
||||||
|
};
|
||||||
|
|
||||||
|
async function addIdentity(person: Person, value: string): Promise<void> {
|
||||||
|
const next = value.trim();
|
||||||
|
if (!next || person.identities.includes(next)) return;
|
||||||
|
await change(person, { identities: [...person.identities, next] });
|
||||||
|
if (!error.value) identity.value[person.id] = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeIdentity = (person: Person, value: string) =>
|
||||||
|
change(person, { identities: person.identities.filter((i) => i !== value) });
|
||||||
|
|
||||||
|
const remove = (person: Person) => save(people.value.filter((p) => p !== person));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<PageHeader title="People" />
|
||||||
|
|
||||||
|
<Alert v-if="error" variant="destructive" class="mb-4"><AlertDescription>{{ error }}</AlertDescription></Alert>
|
||||||
|
|
||||||
|
<form class="mb-4 flex flex-wrap items-center gap-2" @submit.prevent="add">
|
||||||
|
<Input v-model="name" class="max-w-64" placeholder="Name" aria-label="Name" required />
|
||||||
|
<Button type="submit" size="sm" :disabled="!name.trim() || busy"><Plus data-icon="inline-start" />Add</Button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Section>
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead class="w-64">Name</TableHead>
|
||||||
|
<TableHead class="w-28">Authority</TableHead>
|
||||||
|
<TableHead>Identities</TableHead>
|
||||||
|
<TableHead class="w-16 text-right">Actions</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
<TableRow v-for="person in people" :key="person.id">
|
||||||
|
<TableCell>
|
||||||
|
<Input :default-value="person.name" :aria-label="`Name of ${person.name}`" :disabled="busy" @change="rename(person, $event)" />
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Switch
|
||||||
|
:model-value="person.authority"
|
||||||
|
:aria-label="`Authority for ${person.name}`"
|
||||||
|
:disabled="busy"
|
||||||
|
@update:model-value="(on: boolean) => change(person, { authority: on })"
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<Badge v-for="value in person.identities" :key="value" variant="outline" class="gap-1">
|
||||||
|
{{ label(value) }}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-sm focus-visible:outline focus-visible:outline-2"
|
||||||
|
:aria-label="`Remove ${label(value)} from ${person.name}`"
|
||||||
|
:disabled="busy"
|
||||||
|
@click="removeIdentity(person, value)"
|
||||||
|
><X class="size-3" /></button>
|
||||||
|
</Badge>
|
||||||
|
<form class="flex items-center gap-1" @submit.prevent="addIdentity(person, identity[person.id] ?? '')">
|
||||||
|
<Input
|
||||||
|
v-model="identity[person.id]"
|
||||||
|
class="h-8 w-44"
|
||||||
|
placeholder="telegram:1001"
|
||||||
|
:aria-label="`Add an identity to ${person.name}`"
|
||||||
|
/>
|
||||||
|
<Button type="submit" size="icon" variant="ghost" :aria-label="`Add identity to ${person.name}`" :disabled="busy || !identity[person.id]?.trim()"><Plus /></Button>
|
||||||
|
</form>
|
||||||
|
<Button
|
||||||
|
v-if="mine() && !person.identities.includes(mine())"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
:disabled="busy"
|
||||||
|
@click="addIdentity(person, mine())"
|
||||||
|
><Link data-icon="inline-start" />Link my account</Button>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell class="text-right">
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger as-child>
|
||||||
|
<Button variant="ghost" size="icon" :aria-label="`Remove ${person.name}`" :disabled="busy" @click="remove(person)"><Trash2 /></Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>Remove</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow v-if="loading">
|
||||||
|
<TableCell colspan="4" class="text-label text-fg-muted" role="status">Loading people…</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
<TableRow v-else-if="!people.length && !error">
|
||||||
|
<TableCell colspan="4">
|
||||||
|
<Empty class="py-6"><EmptyHeader><EmptyTitle>No people yet</EmptyTitle></EmptyHeader></Empty>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</Section>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -13,6 +13,7 @@ const OrgShell = () => import("@/org/OrgShell.vue");
|
|||||||
const OrgOverviewPage = () => import("@/org/OrgOverviewPage.vue");
|
const OrgOverviewPage = () => import("@/org/OrgOverviewPage.vue");
|
||||||
const OrgMembersPage = () => import("@/org/OrgMembersPage.vue");
|
const OrgMembersPage = () => import("@/org/OrgMembersPage.vue");
|
||||||
const OrgAgentsPage = () => import("@/org/OrgAgentsPage.vue");
|
const OrgAgentsPage = () => import("@/org/OrgAgentsPage.vue");
|
||||||
|
const OrgPeoplePage = () => import("@/org/OrgPeoplePage.vue");
|
||||||
const OrgWorkspacesPage = () => import("@/org/OrgWorkspacesPage.vue");
|
const OrgWorkspacesPage = () => import("@/org/OrgWorkspacesPage.vue");
|
||||||
const OrgAccessPage = () => import("@/org/OrgAccessPage.vue");
|
const OrgAccessPage = () => import("@/org/OrgAccessPage.vue");
|
||||||
const OrgModelsPage = () => import("@/org/OrgModelsPage.vue");
|
const OrgModelsPage = () => import("@/org/OrgModelsPage.vue");
|
||||||
@@ -278,6 +279,12 @@ export const routes: RouteRecordRaw[] = [
|
|||||||
component: OrgMembersPage,
|
component: OrgMembersPage,
|
||||||
meta: { section: "org_members", label: "Members", navPath: "/org", description: "People in the organisation and their roles." },
|
meta: { section: "org_members", label: "Members", navPath: "/org", description: "People in the organisation and their roles." },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "people",
|
||||||
|
name: "org-people",
|
||||||
|
component: OrgPeoplePage,
|
||||||
|
meta: { section: "org_people", label: "People", navPath: "/org", description: "Who answers approvals, and the accounts and channels they answer from." },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "agents",
|
path: "agents",
|
||||||
name: "org-agents",
|
name: "org-agents",
|
||||||
|
|||||||
Reference in new issue
Block a user