feat: add member candidates endpoint and approvals page
- serve active identities outside the org at /api/orgs/{id}/member-candidates and back the members page from it
- add an org approvals page for default owner, deadline and escalation path over /api/settings
This commit is contained in:
11 files changed
+398
-22
No files matched your search
@@ -288,6 +288,9 @@ export const api = {
|
||||
credentialKinds: () => request<CredentialKind[]>("/api/credential-kinds"),
|
||||
putCredential: (name: string, kind: string, fields: Record<string, CredentialField>) =>
|
||||
request<{ name: string; kind: string; restarted: string[] }>(`/api/credentials/${encodeURIComponent(name)}`, { method: "PUT", body: { kind, fields }, timeoutMs: 60_000 }),
|
||||
orgSettings: () => request<OrgSettings>("/api/settings"),
|
||||
putOrgSettings: (settings: OrgSettings) =>
|
||||
request<OrgSettings>("/api/settings", { method: "PUT", body: settings }),
|
||||
instructions: () => request<{ text: string }>("/api/settings/instructions"),
|
||||
saveInstructions: (text: string) =>
|
||||
request<{ text: string }>("/api/settings/instructions", { method: "PUT", body: { text } }),
|
||||
@@ -412,6 +415,8 @@ export const api = {
|
||||
orgAgents: <T = unknown>(id: string) => request<T>(`/api/orgs/${encodeURIComponent(id)}/agents`),
|
||||
orgMembers: <T = unknown>(id: string) =>
|
||||
request<T>(`/api/orgs/${encodeURIComponent(id)}/members`),
|
||||
orgMemberCandidates: <T = unknown>(id: string) =>
|
||||
request<T>(`/api/orgs/${encodeURIComponent(id)}/member-candidates`),
|
||||
addOrgMember: <T = unknown>(
|
||||
id: string,
|
||||
member: { subject?: string; email?: string; role: string },
|
||||
@@ -1205,6 +1210,23 @@ export interface ExtensionInput {
|
||||
effects?: ServerEffects;
|
||||
}
|
||||
|
||||
/** One stop on the escalation path; the deadline is a Go duration string. */
|
||||
export interface EscalationStep {
|
||||
account: string;
|
||||
deadline: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The organisation settings. The server replaces all of them on save, so a page
|
||||
* that edits some sends back the rest as it read them.
|
||||
*/
|
||||
export interface OrgSettings {
|
||||
approval_deadline: string;
|
||||
default_owner: string;
|
||||
escalation: EscalationStep[];
|
||||
[other: string]: unknown;
|
||||
}
|
||||
|
||||
export interface Credential {
|
||||
name: string;
|
||||
kind: string;
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ const orgSpecs: NavSpec[] = [
|
||||
sections: [
|
||||
{
|
||||
label: "People & access",
|
||||
paths: ["/org/members", "/org/agents", "/org/workspaces", "/org/policies", "/org/denials", "/org/audit"],
|
||||
paths: ["/org/members", "/org/approvals", "/org/agents", "/org/workspaces", "/org/policies", "/org/denials", "/org/audit"],
|
||||
},
|
||||
{
|
||||
label: "Agents",
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
<script setup lang="ts">
|
||||
import { Plus, Trash2 } from "@lucide/vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DurationInput } from "@/components/ui/duration-input";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api, describeError, type OrgSettings } from "@/lib/api";
|
||||
import { useOrgStore } from "@/stores/org";
|
||||
import type { Member } from "./org";
|
||||
|
||||
// The select has no empty option value, so "no default owner" is this marker.
|
||||
const NONE = "none";
|
||||
// Default deadline for a new step. The server accepts one minute to 30 days.
|
||||
const NEW_STEP_DEADLINE = "4h";
|
||||
|
||||
interface Draft {
|
||||
approval_deadline: string;
|
||||
default_owner: string;
|
||||
escalation: { account: string; deadline: string }[];
|
||||
}
|
||||
|
||||
const orgStore = useOrgStore();
|
||||
const { org } = storeToRefs(orgStore);
|
||||
|
||||
const saved = ref<OrgSettings | null>(null);
|
||||
const people = ref<Member[]>([]);
|
||||
const draft = ref<Draft | null>(null);
|
||||
const loadError = ref("");
|
||||
const saveError = ref("");
|
||||
const busy = ref(false);
|
||||
|
||||
// Only people with an org-wide membership can approve; the server rejects anyone else.
|
||||
const eligible = computed(() => people.value.filter((member) => member.kind === "user" && !member.workspace_id));
|
||||
const nameOf = (id: string) => eligible.value.find((member) => member.identity_id === id)?.display_name ?? id;
|
||||
|
||||
function toDraft(settings: OrgSettings): Draft {
|
||||
return {
|
||||
approval_deadline: settings.approval_deadline,
|
||||
default_owner: settings.default_owner,
|
||||
escalation: settings.escalation.map((step) => ({ ...step })),
|
||||
};
|
||||
}
|
||||
|
||||
const dirty = computed(() => saved.value !== null && JSON.stringify(draft.value) !== JSON.stringify(toDraft(saved.value)));
|
||||
|
||||
async function load(): Promise<void> {
|
||||
loadError.value = "";
|
||||
try {
|
||||
await orgStore.loadOrg();
|
||||
if (!org.value) return;
|
||||
const [settings, members] = await Promise.all([api.orgSettings(), api.orgMembers<{ members: Member[] }>(org.value.id)]);
|
||||
people.value = members.members;
|
||||
saved.value = settings;
|
||||
draft.value = toDraft(settings);
|
||||
} catch (cause) {
|
||||
loadError.value = describeError(cause, errors.common.unknown);
|
||||
}
|
||||
}
|
||||
|
||||
// A person can appear on the path only once, so each step offers its current
|
||||
// selection plus the people not used by other steps.
|
||||
function choices(account: string) {
|
||||
const taken = new Set(draft.value?.escalation.map((step) => step.account));
|
||||
return eligible.value.filter((member) => member.identity_id === account || !taken.has(member.identity_id));
|
||||
}
|
||||
|
||||
const canAdd = computed(() => draft.value !== null && choices("").length > 0);
|
||||
|
||||
function addStep(): void {
|
||||
const next = choices("")[0];
|
||||
if (draft.value && next) draft.value.escalation.push({ account: next.identity_id, deadline: NEW_STEP_DEADLINE });
|
||||
}
|
||||
|
||||
async function save(): Promise<void> {
|
||||
if (!saved.value || !draft.value || busy.value) return;
|
||||
busy.value = true;
|
||||
saveError.value = "";
|
||||
try {
|
||||
const updated = await api.putOrgSettings({ ...saved.value, ...draft.value });
|
||||
saved.value = updated;
|
||||
draft.value = toDraft(updated);
|
||||
} catch (cause) {
|
||||
saveError.value = describeError(cause, errors.common.unknown);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Approvals" />
|
||||
<ReadError v-if="loadError" :message="loadError" retry-label="Retry" @retry="load" />
|
||||
<form v-else-if="draft" @submit.prevent="save">
|
||||
<Section>
|
||||
<SettingRow label="Default owner" for="approvals-owner">
|
||||
<Select
|
||||
:model-value="draft.default_owner || NONE"
|
||||
@update:model-value="draft.default_owner = $event === NONE ? '' : String($event)"
|
||||
>
|
||||
<SelectTrigger id="approvals-owner" class="w-64">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem :value="NONE">None</SelectItem>
|
||||
<SelectItem v-for="member in eligible" :key="member.identity_id" :value="member.identity_id">
|
||||
{{ member.display_name }}
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</SettingRow>
|
||||
<SettingRow label="Approval deadline" for="approvals-deadline">
|
||||
<DurationInput id="approvals-deadline" v-model="draft.approval_deadline" :units="['m', 'h']" />
|
||||
</SettingRow>
|
||||
</Section>
|
||||
|
||||
<Section title="Escalation path">
|
||||
<template #action>
|
||||
<Button type="button" variant="ghost" size="icon" aria-label="Add a step" :disabled="!canAdd" @click="addStep">
|
||||
<Plus />
|
||||
</Button>
|
||||
</template>
|
||||
<ol class="flex flex-col gap-2">
|
||||
<li v-for="(step, index) in draft.escalation" :key="index" class="flex flex-wrap items-center gap-3">
|
||||
<span class="w-6 text-label text-fg-muted">{{ index + 1 }}</span>
|
||||
<Select v-model="step.account">
|
||||
<SelectTrigger class="w-64" :aria-label="`Person for step ${index + 1}`">
|
||||
<SelectValue>{{ nameOf(step.account) }}</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="member in choices(step.account)" :key="member.identity_id" :value="member.identity_id">
|
||||
{{ member.display_name }}
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<DurationInput v-model="step.deadline" :units="['m', 'h']" />
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
:aria-label="`Remove step ${index + 1}`"
|
||||
@click="draft.escalation.splice(index, 1)"
|
||||
>
|
||||
<Trash2 />
|
||||
</Button>
|
||||
</li>
|
||||
</ol>
|
||||
</Section>
|
||||
|
||||
<Alert v-if="saveError" variant="destructive" class="mb-4"><AlertDescription>{{ saveError }}</AlertDescription></Alert>
|
||||
<div class="flex justify-end gap-2">
|
||||
<Button type="button" variant="ghost" :disabled="busy || !dirty" @click="draft = toDraft(saved!)">Discard</Button>
|
||||
<Button type="submit" :disabled="busy || !dirty">Save</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
@@ -6,7 +6,7 @@ import PageHeader from "@/base/PageHeader.vue";
|
||||
import CreateAccount from "@/accounts/CreateAccount.vue";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { onMounted, ref } from "vue";
|
||||
import { Pause, Play, Plus, Trash2 } from "@lucide/vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -33,7 +33,7 @@ import {
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { useOrgStore } from "@/stores/org";
|
||||
import { ROLE_LABELS, ROLES, type Member, type Role } from "./org";
|
||||
import { ROLE_LABELS, ROLES, type Candidate, type Member, type Role } from "./org";
|
||||
|
||||
/**
|
||||
* The org's members and the role each holds. A membership is org-wide, or
|
||||
@@ -41,6 +41,7 @@ import { ROLE_LABELS, ROLES, type Member, type Role } from "./org";
|
||||
* a member touches exactly that membership.
|
||||
*/
|
||||
const members = ref<Member[]>([]);
|
||||
const candidates = ref<Candidate[]>([]);
|
||||
const error = ref("");
|
||||
const loading = ref(true);
|
||||
const busy = ref("");
|
||||
@@ -57,9 +58,14 @@ const personRole = ref<Role>("viewer");
|
||||
async function load(): Promise<void> {
|
||||
if (!org.value) return;
|
||||
try {
|
||||
members.value = (
|
||||
await api.orgMembers<{ members: Member[] }>(org.value.id)
|
||||
).members;
|
||||
const id = org.value.id;
|
||||
const [list, offered] = await Promise.all([
|
||||
api.orgMembers<{ members: Member[] }>(id),
|
||||
api.orgMemberCandidates<{ identities: Candidate[] }>(id),
|
||||
]);
|
||||
if (org.value?.id !== id) return;
|
||||
members.value = list.members;
|
||||
candidates.value = offered.identities;
|
||||
error.value = "";
|
||||
} catch (cause) {
|
||||
error.value = describeError(cause, errors.common.unknown);
|
||||
@@ -69,7 +75,6 @@ async function load(): Promise<void> {
|
||||
onMounted(async () => {
|
||||
try {
|
||||
await identities.loadOrg();
|
||||
identities.watchIdentities();
|
||||
await load();
|
||||
} catch (cause) {
|
||||
error.value = describeError(cause, errors.common.unknown);
|
||||
@@ -78,17 +83,6 @@ onMounted(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
// Active identities that hold no org-wide membership yet, so Add cannot pick
|
||||
// someone the table already shows. The system identity is not a person.
|
||||
const candidates = computed(() => {
|
||||
const taken = new Set(
|
||||
members.value.filter((m) => !m.workspace_id).map((m) => m.identity_id),
|
||||
);
|
||||
return identities.identities.filter(
|
||||
(i) => i.kind !== "system" && i.lifecycle === "active" && !taken.has(i.id),
|
||||
);
|
||||
});
|
||||
|
||||
async function run(key: string, action: () => Promise<void>): Promise<void> {
|
||||
busy.value = key;
|
||||
try {
|
||||
|
||||
@@ -41,6 +41,13 @@ export const ROLE_LABELS: Record<Role, string> = {
|
||||
viewer: "Viewer",
|
||||
};
|
||||
|
||||
/** An identity that can be added to the org as a member. */
|
||||
export interface Candidate {
|
||||
id: string;
|
||||
kind: string;
|
||||
display_name: string;
|
||||
}
|
||||
|
||||
export interface Member {
|
||||
identity_id: string;
|
||||
kind: string;
|
||||
|
||||
@@ -18,6 +18,7 @@ const OrgAccessPage = () => import("@/org/OrgAccessPage.vue");
|
||||
const OrgUsagePage = () => import("@/org/OrgUsagePage.vue");
|
||||
const SchedulingPolicyPage = () => import("@/settings/SchedulingPolicyPage.vue");
|
||||
const ToolsPage = () => import("@/settings/ToolsPage.vue");
|
||||
const OrgApprovalsPage = () => import("@/org/OrgApprovalsPage.vue");
|
||||
const InstructionsPage = () => import("@/settings/InstructionsPage.vue");
|
||||
const ExtensionsPage = () => import("@/settings/ExtensionsPage.vue");
|
||||
const PluginsPage = () => import("@/settings/PluginsPage.vue");
|
||||
@@ -325,6 +326,12 @@ export const routes: RouteRecordRaw[] = [
|
||||
redirect: "/settings/models",
|
||||
meta: { section: "org_config", label: "Models", navPath: "/org", description: "The organisation's agent models and aliases." },
|
||||
},
|
||||
{
|
||||
path: "approvals",
|
||||
name: "org-approvals",
|
||||
component: OrgApprovalsPage,
|
||||
meta: { section: "org_config", label: "Approvals", navPath: "/org", description: "Default owner, escalation path and approval deadline." },
|
||||
},
|
||||
{
|
||||
path: "instructions",
|
||||
name: "org-instructions",
|
||||
|
||||
Reference in new issue
Block a user