feat(ui): link channel accounts from the account page and remove the People page (#2095)
This commit is contained in:
8 files changed
+368
-22
No files matched your search
@@ -4,6 +4,7 @@ import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent,
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import LinkedChannels from "@/accounts/LinkedChannels.vue";
|
||||
import PersonalTokensCard from "@/accounts/PersonalTokensCard.vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
@@ -29,6 +30,7 @@ const change=()=>run(async()=>{await api.changePassword(current.value,next.value
|
||||
<PageHeader title="Your account"><span class="text-label text-fg-muted">{{accounts.status?.user?.display_name}}</span></PageHeader>
|
||||
<Alert v-if="$route.query.welcome" class="mb-4">Your organisation and admin account are ready. Add a passkey below, <RouterLink class="underline" to="/org/members">add members</RouterLink>, or <RouterLink class="underline" to="/settings/authentication">configure OIDC</RouterLink>.</Alert>
|
||||
<Alert v-if="error" variant="destructive" class="mb-4"><AlertDescription>{{error}}<a v-if="sessionExpired" class="underline" href="/?reauth=1"> Sign in again</a></AlertDescription></Alert>
|
||||
<LinkedChannels :welcome="Boolean($route.query.welcome)" />
|
||||
<Section title="Passkeys">
|
||||
<ItemGroup v-if="keys.length" class="mb-3"><Item v-for="key in keys" :key="key.id" as="li" variant="outline" size="xs"><ItemContent class="min-w-0 truncate"><span class="truncate">{{key.name}}</span></ItemContent><ItemActions><Button variant="ghost" size="sm" class="text-danger" :disabled="busy" @click="pending = key">Remove</Button></ItemActions></Item></ItemGroup>
|
||||
<form v-if="eligible" class="flex flex-wrap gap-2" @submit.prevent="enroll"><Input v-model="keyName" aria-label="Passkey name" placeholder="Passkey name (optional)" maxlength="200" class="min-w-40 flex-1"/><Button type="submit" :disabled="busy">Add passkey</Button></form>
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useIntervalFn } from "@vueuse/core";
|
||||
import QRCode from "qrcode";
|
||||
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Item, ItemActions, ItemContent, ItemGroup } from "@/components/ui/item";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api, describeError, type ChannelLink, type ChannelLinks } from "@/lib/api";
|
||||
|
||||
/** Links the signed-in account to the channel accounts it answers approvals
|
||||
* from. Shown only while an installed connector can link. */
|
||||
const props = defineProps<{ welcome?: boolean }>();
|
||||
|
||||
interface Pending {
|
||||
url: string;
|
||||
qr: string;
|
||||
expiresAt: number;
|
||||
}
|
||||
|
||||
const links = ref<ChannelLinks | null>(null);
|
||||
const pending = ref<Record<string, Pending>>({});
|
||||
const error = ref("");
|
||||
const busy = ref(false);
|
||||
|
||||
const label = (connector: string) => connector.charAt(0).toUpperCase() + connector.slice(1);
|
||||
const linkedOn = (connector: string): ChannelLink[] => links.value?.linked.filter((l) => l.connector === connector) ?? [];
|
||||
const waiting = computed(() => Object.keys(pending.value).length > 0);
|
||||
|
||||
async function load(): Promise<void> {
|
||||
try {
|
||||
links.value = await api.channelLinks();
|
||||
error.value = "";
|
||||
} catch (cause) {
|
||||
error.value = describeError(cause, errors.common.unknown);
|
||||
return;
|
||||
}
|
||||
settle();
|
||||
}
|
||||
|
||||
/** A code that was used or ran out stops waiting. */
|
||||
function settle(): void {
|
||||
for (const connector of Object.keys(pending.value)) {
|
||||
const fresh = linkedOn(connector).some((l) => Date.parse(l.linked_at) >= pending.value[connector]!.expiresAt - CODE_LIFETIME_MS);
|
||||
if (fresh || Date.now() >= pending.value[connector]!.expiresAt) delete pending.value[connector];
|
||||
}
|
||||
if (!waiting.value) stop();
|
||||
}
|
||||
|
||||
/** Matches the server's link code lifetime. */
|
||||
const CODE_LIFETIME_MS = 10 * 60 * 1000;
|
||||
const { pause: stop, resume: poll } = useIntervalFn(() => void load(), 2_000, { immediate: false });
|
||||
|
||||
async function run(action: () => Promise<void>): Promise<void> {
|
||||
busy.value = true;
|
||||
try {
|
||||
await action();
|
||||
error.value = "";
|
||||
} catch (cause) {
|
||||
error.value = describeError(cause, errors.common.unknown);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const begin = (connector: string) =>
|
||||
run(async () => {
|
||||
const start = await api.beginChannelLink(connector);
|
||||
pending.value[connector] = {
|
||||
url: start.url,
|
||||
qr: await QRCode.toDataURL(start.url, { margin: 1, width: 192 }),
|
||||
expiresAt: Date.parse(start.expires_at),
|
||||
};
|
||||
poll();
|
||||
});
|
||||
|
||||
const unlink = (link: ChannelLink) =>
|
||||
run(async () => {
|
||||
await api.unlinkChannel(link.connector, link.subject);
|
||||
await load();
|
||||
});
|
||||
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Section v-if="links?.connectors.length || error" :title="props.welcome ? 'Link your channels' : 'Linked accounts'">
|
||||
<Alert v-if="error" variant="destructive" class="mb-3"><AlertDescription>{{ error }}</AlertDescription></Alert>
|
||||
<ItemGroup v-if="links" class="gap-3">
|
||||
<div v-for="connector in links.connectors" :key="connector" class="space-y-2">
|
||||
<Item v-for="link in linkedOn(connector)" :key="link.subject" as="li" variant="outline" size="xs">
|
||||
<ItemContent class="min-w-0 truncate">{{ label(connector) }}: Linked as {{ link.name || link.subject }}</ItemContent>
|
||||
<ItemActions>
|
||||
<Button variant="ghost" size="sm" class="text-danger" :disabled="busy" @click="unlink(link)">Unlink</Button>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
<div v-if="pending[connector]" class="flex flex-wrap items-center gap-4">
|
||||
<img :src="pending[connector].qr" :alt="`QR code to link ${label(connector)}`" width="192" height="192" class="rounded-md bg-white" />
|
||||
<div class="space-y-2">
|
||||
<Button as-child><a :href="pending[connector].url" target="_blank" rel="noopener">Open in {{ label(connector) }}</a></Button>
|
||||
<p class="text-caption text-fg-muted">Scan the code or open the link, then press Start.</p>
|
||||
</div>
|
||||
</div>
|
||||
<Button v-else-if="!linkedOn(connector).length" :disabled="busy" @click="begin(connector)">Link your {{ label(connector) }}</Button>
|
||||
<Button v-else variant="outline" size="sm" :disabled="busy" @click="begin(connector)">Link another {{ label(connector) }} account</Button>
|
||||
</div>
|
||||
</ItemGroup>
|
||||
</Section>
|
||||
</template>
|
||||
+26
-9
@@ -365,9 +365,15 @@ export const api = {
|
||||
alerts: <T = unknown>() => request<T>("/api/alerts"),
|
||||
dismissAlert: (id: number) =>
|
||||
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 }),
|
||||
channelLinks: () => request<ChannelLinks>("/api/account/channels"),
|
||||
/** Issues a single-use code and returns the URL that sends it to the channel. */
|
||||
beginChannelLink: (connector: string) =>
|
||||
request<ChannelLinkStart>(`/api/account/channels/${encodeURIComponent(connector)}/link`, { method: "POST" }),
|
||||
unlinkChannel: (connector: string, subject: string) =>
|
||||
request<void>(`/api/account/channels/${encodeURIComponent(connector)}/${encodeURIComponent(subject)}`, {
|
||||
method: "DELETE",
|
||||
parse: false,
|
||||
}),
|
||||
identities: <T = unknown>() => request<T>("/api/identities"),
|
||||
identityCreate: <T = unknown>(identity: { display_name: string; kind: string }) =>
|
||||
request<T>("/api/identities", { method: "POST", body: identity }),
|
||||
@@ -681,13 +687,24 @@ export interface Run {
|
||||
result?: unknown;
|
||||
}
|
||||
|
||||
/** A person who may answer approvals, and the identities they answer as. */
|
||||
export interface Person {
|
||||
/** Empty for a new person. */
|
||||
id: string;
|
||||
/** A channel account linked to the signed-in account. */
|
||||
export interface ChannelLink {
|
||||
connector: string;
|
||||
subject: string;
|
||||
name: string;
|
||||
authority: boolean;
|
||||
identities: string[];
|
||||
linked_at: string;
|
||||
}
|
||||
|
||||
/** The connectors that can link, and the channel accounts already linked. */
|
||||
export interface ChannelLinks {
|
||||
connectors: string[];
|
||||
linked: ChannelLink[];
|
||||
}
|
||||
|
||||
/** A link code ready to open in a channel. */
|
||||
export interface ChannelLinkStart {
|
||||
url: string;
|
||||
expires_at: string;
|
||||
}
|
||||
|
||||
/** A passkey assertion made for one approval request. */
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ const orgSpecs: NavSpec[] = [
|
||||
sections: [
|
||||
{
|
||||
label: "People & access",
|
||||
paths: ["/org/members", "/org/people", "/org/agents", "/org/workspaces", "/org/policies", "/org/denials", "/org/audit"],
|
||||
paths: ["/org/members", "/org/agents", "/org/workspaces", "/org/policies", "/org/denials", "/org/audit"],
|
||||
},
|
||||
{
|
||||
label: "Connections & models",
|
||||
|
||||
@@ -13,7 +13,6 @@ const OrgShell = () => import("@/org/OrgShell.vue");
|
||||
const OrgOverviewPage = () => import("@/org/OrgOverviewPage.vue");
|
||||
const OrgMembersPage = () => import("@/org/OrgMembersPage.vue");
|
||||
const OrgAgentsPage = () => import("@/org/OrgAgentsPage.vue");
|
||||
const OrgPeoplePage = () => import("@/org/OrgPeoplePage.vue");
|
||||
const OrgWorkspacesPage = () => import("@/org/OrgWorkspacesPage.vue");
|
||||
const OrgAccessPage = () => import("@/org/OrgAccessPage.vue");
|
||||
const OrgModelsPage = () => import("@/org/OrgModelsPage.vue");
|
||||
@@ -279,12 +278,6 @@ export const routes: RouteRecordRaw[] = [
|
||||
component: OrgMembersPage,
|
||||
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",
|
||||
name: "org-agents",
|
||||
|
||||
Reference in new issue
Block a user