Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .changeset/34591-org-menu-posture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@object-ui/app-shell': patch
---

feat(app-shell): the avatar menu's organization entries follow the deployment posture, and the organization switcher moves into the avatar menu

Clause-②: no
Metadata-protocol: none

The avatar menu reads the deployment signals the server already serves on `GET /api/v1/auth/config` (`features.multiOrgEnabled`, `features.cloudManaged`, `features.tenancyPosture`) and offers organization entries by them:

- **Single-tenant** (`multiOrgEnabled` false, the `single` posture): no organization entry at all, and no organization switcher. Member management for the one organization stays at Setup → Organization.
- **Multi-organization**: "My Organizations" and "Create organization"; "Switch organization" joins them only when the member belongs to two or more organizations.
- **Cloud-managed** (`cloudManaged` true): no "Create organization"; organizations are created on the cloud there.

A server that serves none of these flags reads the spec's defaults (multi-organization on, not managed), which is the menu as it was.

The organization switcher no longer sits at the left of the top bar, which now holds only the product mark and the app switcher. It is the avatar menu's "Switch organization" submenu. Under the `group` posture it still names the working organization (the write target) and says that views show data from every organization the member belongs to (ADR-0105). On a walled posture (`group` or `isolated`) the top bar still names the active organization, read-only, now at any membership count (before, only at exactly one), so a member of two or more organizations still sees which organization lists are scoped to; the name is also shown under "My Organizations". The switcher's own "Manage members" and "Create organization" items are gone: "My Organizations" and the menu's own create entry lead to the same pages. Inside the ObjectStack mobile shell, the top-bar button that opens the shell's native connection switcher is unchanged.

There is no Setup setting for this menu.
115 changes: 115 additions & 0 deletions ui/packages/app-shell/src/hooks/useOrgMenuPosture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* useOrgMenuPosture — which organization entries the avatar menu offers, read
* from the deployment signals the server already serves on `GET /auth/config`
* (objectstack-ai/objectstack#34591, ruling 6937513776):
*
* - `features.multiOrgEnabled` — the multi-organization capability flag. The
* server derives it from the effective tenancy posture (`false` on `single`,
* and on a degraded deployment that asked for isolation but has none), and
* the spec says the console offers creating, switching and leaving
* organizations only when it is on. It is default-on: absent reads as on.
* - `features.cloudManaged` — the cloud's control plane runs this environment.
* Organizations are created on the cloud there, so the console offers no
* create entry; the cloud adds its own entries through the existing
* `manifest.navigationContributions` path, never through this menu. Absent
* reads as not managed.
* - `features.tenancyPosture` — how to render organization context (ADR-0105
* D1): under `group` the switcher picks the WRITE target, so it says so.
*
* There is no Setup override: the menu follows the served signals alone (the
* ruling drops the card's settings key). Single-organization member
* management stays reachable at Setup → Organization (ruling 6384629949), so a
* single-tenant menu without organization entries closes no door.
*
* Until the config resolves the defaults are the spec's absent readings
* (multi-organization on, not managed), which is today's rendering.
*/

import { useEffect, useState } from 'react';
import { useAuth } from '@object-ui/auth';
import type { AuthPublicConfig, TenancyPosture } from '@object-ui/auth';

const POSTURES: readonly TenancyPosture[] = ['single', 'group', 'isolated'];

export interface OrgMenuPosture {
/** `features.multiOrgEnabled !== false` — the spec's default-on reading. */
multiOrgEnabled: boolean;
/** `features.cloudManaged === true`. */
cloudManaged: boolean;
/** `features.tenancyPosture` when it is a recognised posture, else `undefined`. */
tenancyPosture: TenancyPosture | undefined;
}

const UNRESOLVED: OrgMenuPosture = {
multiOrgEnabled: true,
cloudManaged: false,
tenancyPosture: undefined,
};

/** The served `features` object, read into the three answers above. */
export function readOrgMenuPosture(features: AuthPublicConfig['features'] | null | undefined): OrgMenuPosture {
const posture: unknown = features?.tenancyPosture;
return {
multiOrgEnabled: features?.multiOrgEnabled !== false,
cloudManaged: features?.cloudManaged === true,
tenancyPosture:
typeof posture === 'string' && (POSTURES as readonly string[]).includes(posture)
? (posture as TenancyPosture)
: undefined,
};
}

export interface OrgMenuEntries {
/** "My Organizations" → `/organizations?manage=1`. */
myOrganizations: boolean;
/** "Switch organization" — the organization switcher, inside the avatar menu. */
switchOrganization: boolean;
/** "Create organization" → `/organizations?create=1`. */
createOrganization: boolean;
}

/**
* The avatar menu's organization entries for one deployment and one member.
*
* - single-tenant (`multiOrgEnabled` off) ⇒ none;
* - multi-organization ⇒ My Organizations and Create organization, plus Switch
* organization only at two or more memberships (one has nothing to switch to);
* - cloud-managed ⇒ no Create organization.
*
* `hasOrgSection` is the member's own organization context (memberships still
* loading, any membership, or an active organization): with none there is
* nothing to manage or switch, as before.
*/
export function orgMenuEntries(input: {
posture: Pick<OrgMenuPosture, 'multiOrgEnabled' | 'cloudManaged'>;
hasOrgSection: boolean;
membershipCount: number;
}): OrgMenuEntries {
const offered = input.posture.multiOrgEnabled && input.hasOrgSection;
return {
myOrganizations: offered,
switchOrganization: offered && input.membershipCount > 1,
createOrganization: offered && !input.posture.cloudManaged,
};
}

export function useOrgMenuPosture(): OrgMenuPosture {
const { getAuthConfig } = useAuth();
const [posture, setPosture] = useState<OrgMenuPosture>(UNRESOLVED);

useEffect(() => {
let cancelled = false;
getAuthConfig?.()
.then((cfg) => {
if (!cancelled) setPosture(readOrgMenuPosture(cfg?.features));
})
.catch(() => {
/* config unavailable — keep the absent readings; the server still enforces */
});
return () => {
cancelled = true;
};
}, [getAuthConfig]);

return posture;
}
99 changes: 55 additions & 44 deletions ui/packages/app-shell/src/layout/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import { useState, useEffect, useLayoutEffect, useCallback, useRef, type RefObje
import { useOffline } from '@object-ui/react';
import { PresenceAvatars, useTenantPresence, type PresenceUser } from '@object-ui/collaboration';
import { ModeToggle } from './ModeToggle.js';
import { WorkspaceSwitcher } from './WorkspaceSwitcher.js';
import { WorkspaceSwitcher, WorkspaceSwitcherMenu } from './WorkspaceSwitcher.js';
import { CurrentOrganizationIndicator } from './CurrentOrganizationIndicator.js';
import { LocaleSwitcher } from './LocaleSwitcher.js';
import { NotificationPreferencesMenu } from './NotificationPreferencesMenu.js';
Expand Down Expand Up @@ -107,6 +107,8 @@ import { useStudioEntryGate } from '../hooks/useStudioDesignGate.js';
import { useSharedActivityFeed, type ActivityFeedReading } from '../hooks/sharedUserFeeds.js';
import { useInboxBell } from '../hooks/useInboxBell.js';
import { useHomePath } from '../hooks/useHomePath.js';
import { orgMenuEntries, useOrgMenuPosture } from '../hooks/useOrgMenuPosture.js';
import { postureHasOrgWall } from '../hooks/useTenancyPosture.js';
import { useServedViewItems } from '../hooks/useServedViewItems.js';
import { viewTabLabel } from '../views/viewTabLabel.js';
import { resolveViewId } from '../utils/resolveViewId.js';
Expand Down Expand Up @@ -475,7 +477,6 @@ export function AppHeader({
organizations,
activeOrganization,
isOrganizationsLoading,
getAuthConfig,
} = useAuth();
const dataSource = useAdapter();
// Runtime AI gating: hide the top-bar AI entry point when the server serves
Expand Down Expand Up @@ -611,24 +612,17 @@ export function AppHeader({
: apiActivity;
const orgList = organizations ?? [];
const hasOrgSection = isOrganizationsLoading || orgList.length > 0 || !!activeOrganization;
// Mirror the server's `beforeCreateOrganization` gate so the "Create
// workspace" entry only shows where multi-org self-service is enabled.
// Default to allowed until the config resolves (avoids hiding it on slow
// networks); the server still enforces.
const [multiOrgDisabled, setMultiOrgDisabled] = useState(false);
useEffect(() => {
let cancelled = false;
getAuthConfig?.()
.then((cfg) => {
if (!cancelled) setMultiOrgDisabled(cfg?.features?.multiOrgEnabled === false);
})
.catch(() => {
/* leave default — server still enforces */
});
return () => {
cancelled = true;
};
}, [getAuthConfig]);
// The avatar menu's organization entries follow the served deployment
// signals (objectstack-ai/objectstack#34591): none on a single-tenant
// deployment, no create entry on a cloud-managed one, and the switcher only
// at two or more memberships. Until the config resolves, the spec's absent
// readings keep today's rendering; the server still enforces.
const orgMenuPosture = useOrgMenuPosture();
const orgMenu = orgMenuEntries({
posture: orgMenuPosture,
hasOrgSection,
membershipCount: orgList.length,
});

// Build path segments (only used in `app` variant)
const pathParts = location.pathname.split('/').filter(Boolean);
Expand Down Expand Up @@ -948,12 +942,13 @@ export function AppHeader({
reports GA. */}
{!isApp && <PreviewBadge className="ml-2 hidden sm:inline-flex" />}

{/* Organization context — "which org am I in", right after the brand and
before the app/section breadcrumb. Two mutually exclusive renderers:
the switcher for multi-membership users (name + switch dropdown),
and the read-only indicator for the single-membership case the
switcher declines to render, on walled deployments only
(objectui#5287 — the switcher's own visibility rule is unchanged). */}
{/* Organization context, right after the brand. The web organization
switcher lives in the avatar menu (objectstack-ai/objectstack#34591):
the left of the bar is the product mark and the app switcher. What
stays here: the mobile shell's own connection-switcher button
(renders only inside a shell that announces it), and the read-only
organization name on a walled deployment, at any membership count
(objectui#5287). */}
<WorkspaceSwitcher />
<CurrentOrganizationIndicator />

Expand Down Expand Up @@ -1306,34 +1301,50 @@ export function AppHeader({
</DropdownMenuItem>
)}
{/*
* Workspace entries. The header-left WorkspaceSwitcher carries
* the same destinations, but it renders NOTHING below two orgs
* (`orgList.length <= 1` → null) — so for the single-org majority
* the avatar menu is the ONLY door to workspace management.
* Leaving just the create shortcut here is what shut every path
* to Members / Invitations / Organization settings for them
* (objectstack#8096): the picker at `/organizations` auto-skips
* with one org, and the switcher never appears.
* Organization entries, by deployment posture (`orgMenuEntries`,
* objectstack-ai/objectstack#34591, ruling 6937513776).
*
* Single-tenant (`multiOrgEnabled` off): none. Member management
* for the one organization is Setup → Organization (ruling
* 6384629949), so dropping these closes no door.
*
* "My Organizations" → `?manage=1`, which OrganizationsPage reads as
* "the user came here to MANAGE": multi-org users get the picker,
* a single-org user is deep-linked straight to that org's members
* page (there is no choice worth showing them). Deliberately NOT
* gated on `multiOrgDisabled` — that flag governs CREATING orgs;
* where self-service creation is off this entry is the only way
* in, so gating it there would re-close the door.
* Multi-organization: "My Organizations" → `?manage=1`, which
* OrganizationsPage reads as "came here to MANAGE" — a member of
* one organization is deep-linked to its members page, since the
* picker auto-skips at one organization (objectstack#8096: this
* entry is that member's door, as the switcher is not offered at
* one membership). Then the switcher, at two or more memberships,
* and "Create organization" unless the cloud manages this
* environment (organizations are created on the cloud there).
*
* On a walled posture the active organization's name also rides
* under "My Organizations", beside the entries that act on it; the
* bar names it read-only (`CurrentOrganizationIndicator`).
*/}
{hasOrgSection && (
{orgMenu.myOrganizations && (
<DropdownMenuItem
onClick={() => leaveTo('/organizations?manage=1')}
className="cursor-pointer"
data-testid="header-my-organizations"
>
<Building2 className="mr-2 h-4 w-4" />
{t('organizations.mine', { defaultValue: 'My Organizations' })}
<span className="grid min-w-0 flex-1 leading-tight">
<span>{t('organizations.mine', { defaultValue: 'My Organizations' })}</span>
{activeOrganization && postureHasOrgWall(orgMenuPosture.tenancyPosture) && (
<span
className="truncate text-xs text-muted-foreground"
data-testid="header-my-organizations-current"
>
{activeOrganization.name}
</span>
)}
</span>
</DropdownMenuItem>
)}
{hasOrgSection && !multiOrgDisabled && (
{orgMenu.switchOrganization && (
<WorkspaceSwitcherMenu isGroupPosture={orgMenuPosture.tenancyPosture === 'group'} />
)}
{orgMenu.createOrganization && (
<DropdownMenuItem
onClick={() => leaveTo('/organizations?create=1')}
className="cursor-pointer"
Expand Down
44 changes: 21 additions & 23 deletions ui/packages/app-shell/src/layout/CurrentOrganizationIndicator.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
/**
* CurrentOrganizationIndicator — read-only "which organization am I in" for
* users who have exactly ONE membership (objectui#5287).
* CurrentOrganizationIndicator — read-only "which organization am I in" on a
* walled deployment, at any membership count (objectui#5287).
*
* `WorkspaceSwitcher` is a multi-membership affordance: with one organization
* there is nothing to switch to, so it renders nothing — and it is also the
* only place the console ever showed the organization name. On a walled
* deployment that left a single-membership business user with no indication
* anywhere of which organization they were looking at, while every list on the
* page was silently scoped to it. Found in a downstream multi-tenant
* acceptance run (case S20-001).
* On a walled posture every list on the page is silently scoped to the active
* organization, so the top bar must say which one without the user opening
* anything. Found in a downstream multi-tenant acceptance run (case S20-001)
* for a single-membership user, who had no organization name anywhere.
*
* This is the other half of that surface, deliberately a SEPARATE component:
* The organization switcher is not in the top bar: the left of the bar is the
* product mark and the app switcher, and switching lives in the avatar menu
* (`WorkspaceSwitcherMenu`, objectstack-ai/objectstack#34591). So this
* indicator is the bar's only organization name, at one membership and at two
* or more alike (seat ruling repo:objectstack#3 on that card).
*
* - the switcher's visibility rule is unchanged (`orgList.length <= 1` still
* renders nothing — a one-entry dropdown was the rejected option);
* - this renders in exactly the case the switcher declines, and renders no
* control at all: no trigger, no menu, no click target. The name is
* context, not navigation. Members / workspace management stay reachable
* from the avatar menu's "My Workspaces" entry (objectstack#8096), which
* is what covers this configuration.
* It renders no control at all: no trigger, no menu, no click target. The name
* is context, not navigation; a read-only name is not a switcher. Switching and
* members / workspace management stay in the avatar menu ("Switch
* organization", "My Organizations").
*
* ## Why it is gated on the tenancy posture, not on "an org exists"
*
Expand All @@ -35,7 +33,8 @@
*
* Inside the mobile shell, when it announces `showConnectionSwitcher`, this
* renders nothing: `WorkspaceSwitcher` then draws the same badge and name, at
* the same widths, as the button that opens the shell's native switcher.
* the same widths, as the top-bar button that opens the shell's native
* switcher.
*
* An absent or unrecognized posture (older server, config fetch still in
* flight or failed) renders nothing, matching how every other posture-keyed
Expand All @@ -61,11 +60,10 @@ export function CurrentOrganizationIndicator() {
// exactly as it is today. Also covers the not-yet-resolved config.
if (!postureHasOrgWall(posture)) return null;

const orgList = organizations ?? [];

// Exactly one membership. Two or more is the switcher's case and it must
// stay the only affordance there; zero means no organization context at all.
if (orgList.length !== 1) return null;
// Any membership count names the organization: the switcher is in the
// avatar menu, so this is the bar's only organization name. Zero memberships
// means no organization context at all.
if ((organizations ?? []).length === 0) return null;

// The organization the SERVER reports as active, never a guess from the
// membership list (objectui#12698): a session with no active organization —
Expand Down
Loading
Loading