feat(webui): act in a selected organisation the caller is a member of, enforced at the dashboard and the State Store

This commit is contained in:
sam committed 2026-10-27 11:06:18 +11:00
1 parent 2cf9d435cc
commit 2fb0084d2c
17 files changed
+356 -69

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
<script setup lang="ts">
import { storeToRefs } from "pinia";
import { computed, onMounted, ref } from "vue";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { useOrgStore } from "@/stores/org";
const orgStore = useOrgStore();
const { homeOrg, memberOrgs, orgs } = storeToRefs(orgStore);
const failed = ref("");
// A failed read leaves the bar without a switcher; the org pages show the error.
onMounted(() => void orgStore.loadOrg().catch(() => undefined));
const choices = computed(() => orgs.value.filter((o) => memberOrgs.value.includes(o.id)));
async function choose(id: string): Promise<void> {
failed.value = "";
try {
await orgStore.actInOrg(id);
} catch (cause) {
failed.value = String((cause as Error).message || cause);
}
}
</script>
<template>
<Select v-if="choices.length > 1" :model-value="homeOrg" @update:model-value="(id) => choose(String(id))">
<SelectTrigger class="w-44 max-sm:w-32" aria-label="Organisation" :title="failed || undefined" :aria-invalid="!!failed">
<SelectValue placeholder="Organisation" />
</SelectTrigger>
<SelectContent>
<SelectItem v-for="o in choices" :key="o.id" :value="o.id">{{ o.name }}</SelectItem>
</SelectContent>
</Select>
</template>
+2
View File
@@ -7,6 +7,7 @@ import Brand from "./Brand.vue";
import ConnectionPill from "./ConnectionPill.vue";
import Nav from "./Nav.vue";
import NavMenu from "./NavMenu.vue";
import OrgSwitcher from "./OrgSwitcher.vue";
import ProfileDropdown from "./ProfileDropdown.vue";
const props = defineProps<{ hidden: string[] }>();
@@ -24,6 +25,7 @@ const newTaskOpen = ref(false);
the operator. -->
<div class="min-w-0 flex-1 max-md:hidden"><Nav :hidden="props.hidden" /></div>
<div class="ml-auto flex shrink-0 items-center gap-2">
<OrgSwitcher />
<ConnectionPill />
<CommandPalette :hidden="props.hidden" @new-task="newTaskOpen = true" />
<NewTaskDialog v-if="!props.hidden.includes('/workflows')" v-model:open="newTaskOpen" />
+4
View File
@@ -190,6 +190,10 @@ export const api = {
scheduleRuns: <T = unknown>(id: string) =>
request<T>(`/api/schedules/${encodeURIComponent(id)}/runs`),
orgs: <T = unknown>() => request<T>("/api/orgs"),
// orgSelect sets the org the caller's tasks, workflows and settings act in;
// the server refuses one the caller is not a member of.
orgSelect: (id: string) =>
request<void>("/api/orgs/current", { method: "PUT", body: { id }, parse: false }),
// 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 }) =>
+13
View File
@@ -17,6 +17,7 @@ interface OrgList {
orgs: Org[];
current: string;
instance_admin: boolean;
member_orgs?: string[];
}
const message = (cause: unknown) => String((cause as Error).message || cause);
@@ -29,6 +30,8 @@ export const useOrgStore = defineStore("org", () => {
const instanceAdmin = ref(false);
/** The org the caller acts in; Access and Tokens always read this one. */
const homeOrg = ref("");
/** The orgs the caller may act in; the server refuses any other. */
const memberOrgs = ref<string[]>([]);
/** The org the Org area shows; an instance admin can point it elsewhere. */
const org = ref<Org | null>(null);
let pending: Promise<void> | null = null;
@@ -43,6 +46,7 @@ export const useOrgStore = defineStore("org", () => {
orgs.value = response.orgs;
instanceAdmin.value = response.instance_admin;
homeOrg.value = response.current;
memberOrgs.value = response.member_orgs ?? [response.current];
const keep = org.value?.id ?? response.current;
org.value = response.orgs.find((o) => o.id === keep) ?? response.orgs[0] ?? null;
})
@@ -52,6 +56,13 @@ export const useOrgStore = defineStore("org", () => {
return pending;
}
/** actInOrg switches the org the whole dashboard acts in. Everything loaded
* so far belongs to the old one, so the page starts over. */
async function actInOrg(id: string): Promise<void> {
await api.orgSelect(id);
window.location.reload();
}
/** viewOrg points the Org area at another org; only an instance admin lists more than one. */
function viewOrg(id: string): void {
org.value = orgs.value.find((o) => o.id === id) ?? org.value;
@@ -118,6 +129,8 @@ export const useOrgStore = defineStore("org", () => {
orgs,
instanceAdmin,
homeOrg,
memberOrgs,
actInOrg,
org,
loadOrg,
viewOrg,