Skip to content
Closed
1 change: 1 addition & 0 deletions api/accepted-breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ Once the change is on the base branch, oasdiff no longer reports it and its line
- 2026-11-14 POST /api/v2/organizations/{organizationId}/people/{personId}/revoke-access added the new `member` enum value to the `person/role` response property for the response status `200`. Renamed before any release to the organisation-member roles: owner, admin and member, where a person was admin or user.
- 2026-11-14 POST /api/v2/organizations/{organizationId}/people/{personId}/revoke-access added the new `owner` enum value to the `person/role` response property for the response status `200`. Renamed before any release to the organisation-member roles: owner, admin and member, where a person was admin or user.
- 2026-11-14 PATCH /api/v2/organizations/{organizationId}/capabilities/{capabilityId} removed the request property `roles/user`. Renamed before any release to the organisation-member roles: owner, admin and member, where a person was admin or user.
- 2026-11-15 POST /api/v2/organizations/{organizationId}/members api removed without deprecation. Adding somebody who already had an account, by email, was described before any release and no release serves it. People join an organization by invitation: POST /api/v2/organizations/{organizationId}/invitations, which the person accepts.
844 changes: 800 additions & 44 deletions api/openapi.yaml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions api/openapi/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ paths:
/api/v2/organizations/{organizationId}/bots/{botId}/follow-ups/{followUpId}/cancel: { $ref: './schedules.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1bots~1{botId}~1follow-ups~1{followUpId}~1cancel' }
/api/v2/people/me/organizations: { $ref: './organizations.yaml#/paths/~1api~1v2~1people~1me~1organizations' }
/api/v2/organizations/{organizationId}/members: { $ref: './organizations.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1members' }
/api/v2/organizations/{organizationId}/profile: { $ref: './organizations.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1profile' }
/api/v2/organizations/{organizationId}/members/{personId}: { $ref: './organizations.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1members~1{personId}' }
/api/v2/organizations/{organizationId}/invitations: { $ref: './organizations.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1invitations' }
/api/v2/organizations/{organizationId}/invitations/{invitationId}: { $ref: './organizations.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1invitations~1{invitationId}' }
/api/v2/people/me/invitations: { $ref: './organizations.yaml#/paths/~1api~1v2~1people~1me~1invitations' }
/api/v2/people/me/invitations/{invitationId}: { $ref: './organizations.yaml#/paths/~1api~1v2~1people~1me~1invitations~1{invitationId}' }
/api/v2/people/me/invitations/{invitationId}/accept: { $ref: './organizations.yaml#/paths/~1api~1v2~1people~1me~1invitations~1{invitationId}~1accept' }
/api/v2/people/me/invitations/{invitationId}/decline: { $ref: './organizations.yaml#/paths/~1api~1v2~1people~1me~1invitations~1{invitationId}~1decline' }
/api/v2/organizations/{organizationId}/people/{personId}/approvals: { $ref: './approvals.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1people~1{personId}~1approvals' }
/api/v2/organizations/{organizationId}/people/{personId}/approvals/{approvalId}/decide: { $ref: './approvals.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1people~1{personId}~1approvals~1{approvalId}~1decide' }
/api/v2/organizations/{organizationId}/people/{personId}/questions: { $ref: './approvals.yaml#/paths/~1api~1v2~1organizations~1{organizationId}~1people~1{personId}~1questions' }
Expand Down
905 changes: 843 additions & 62 deletions api/openapi/organizations.yaml

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions api/redocly/rules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ import { parse } from "yaml";

const ORGANIZATION_PREFIX = "/api/v2/organizations/{organizationId}/";
/**
* The one address outside an organization: the organizations the caller is a member of, and
* creating one. A person has to be able to ask which organizations they are in before they can
* name one, so this cannot sit under an organization's address.
* The addresses outside an organization. The organizations the caller is a member of, and
* creating one: a person has to be able to ask which organizations they are in before they can
* name one. And the invitations sent to the caller: they answer one before they are a member of
* the organization it is for, so neither can sit under an organization's address.
*/
const OUTSIDE_AN_ORGANIZATION = ["/api/v2/people/me/organizations"];
const OUTSIDE_AN_ORGANIZATION = [
"/api/v2/people/me/organizations",
"/api/v2/people/me/invitations",
"/api/v2/people/me/invitations/{invitationId}",
"/api/v2/people/me/invitations/{invitationId}/accept",
"/api/v2/people/me/invitations/{invitationId}/decline",
];
const WRITE_METHODS = ["post", "put", "patch", "delete"];
const METHODS = ["get", "head", "options", "trace", ...WRITE_METHODS];
const PROBLEM_JSON = "application/problem+json";
Expand Down
8 changes: 6 additions & 2 deletions api/redocly/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ test("each convention is enforced", () => {
}
});

test("only the caller's own organizations sit outside an organization", () => {
test("only the caller's own organizations and invitations sit outside an organization", () => {
const ORGANIZATIONS = "/api/v2/people/me/organizations";
// The one address a person can ask before they can name an organization: allowed as committed.
// What a person can ask before they can name an organization, or before they are a member of
// the one an invitation is for: allowed as committed.
expect(Object.keys(spec().paths)).toContain(ORGANIZATIONS);
expect(Object.keys(spec().paths)).toContain(
"/api/v2/people/me/invitations/{invitationId}/accept",
);
const broken = spec();
// Nothing beside it is: not another of the person's own resources, and not the address under it.
broken.paths["/api/v2/people/me/bots"] = broken.paths[BOTS];
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/app-sidebar/account-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function UserAvatar() {
* `internal-<commit>` reads whole, as a release's `v1.0.2` always did, and the name is what gets
* cut short when the sidebar is narrow. account-version-layout.test.tsx measures it in a browser.
*
* Somebody with more than one organization, or who may create one, reads the one they are working
* in under their name, since the menu this opens is where they change it. Nobody else has that line.
* Where OpenBot lists the person's organizations, they read the one they are working in under their
* name, since the menu this opens is where they change it. Nobody else has that line.
*/
export function AccountLabel() {
const { data: currentUser } = useQuery(currentUserQueryOptions());
Expand Down
9 changes: 7 additions & 2 deletions app/src/components/app-sidebar/app-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ import {
type NavigationLink,
useNavigationItems,
} from "@/lib/navigation";
import { useOrganizationChoices } from "@/lib/organizations/queries";
import {
useOrganizationChoices,
useWaitingInvitationCount,
} from "@/lib/organizations/queries";
import { relativeTimeShort } from "@/lib/relative-time";
import {
type MessageListEmphasis,
Expand Down Expand Up @@ -381,8 +384,9 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
const emphasis = useMessageListEmphasis();
const signOut = useSignOut();
const signOutOffered = useSignOutOffered();
// Somebody with nothing to switch to or create has no organizations in the menu at all.
// Where OpenBot lists no organizations, the menu has none at all.
const organizationChoices = useOrganizationChoices();
const invitationsWaiting = useWaitingInvitationCount();
const switchOrganization = useSwitchOrganization();
const channels = useInfiniteQuery(channelListQueryOptions());
// One socket for the app, opened where the roster is kept live.
Expand Down Expand Up @@ -572,6 +576,7 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
{organizationChoices ? (
<OrganizationMenuItems
choices={organizationChoices}
invitationsWaiting={invitationsWaiting}
itemClassName={userMenuItemClassName}
onNew={() => {
// A narrow window's sheet would wait behind the dialog.
Expand Down
204 changes: 204 additions & 0 deletions app/src/components/organizations/invitations-page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import { IconBuilding, IconMail, IconMailOff } from "@tabler/icons-react";
import { useMutation, useQuery } from "@tanstack/react-query";
import { Fragment, useState } from "react";
import { PageEmpty, PageRows, PageShell } from "@/components/layout/page-shell";
import { Button } from "@/components/ui/button";
import {
Item,
ItemActions,
ItemContent,
ItemDescription,
ItemMedia,
ItemTitle,
} from "@/components/ui/item";
import { Separator } from "@/components/ui/separator";
import { useCurrentOrganizationId } from "@/lib/organizations/current";
import {
acceptInvitationMutationOptions,
declineInvitationMutationOptions,
} from "@/lib/organizations/mutations";
import {
type ReceivedInvitation,
receivedInvitationQueryOptions,
receivedInvitationsQueryOptions,
} from "@/lib/organizations/queries";
import { receivedInvitationLine } from "@/lib/organizations/words";
import { queryClient } from "@/query-client";
import { useSwitchOrganization } from "./use-switch-organization";

/**
* One invitation as the person it was sent to sees it, in whatever state it is in.
*
* Waiting, it offers Accept and Decline. Accepting does not move the person: they keep working
* where they were, and the row then offers the switch. Expired, declined or canceled, it says so
* and offers nothing. A refusal (it expired or was canceled meanwhile) is drawn under the row in
* the server's own sentence.
*/
export function InvitationRow({
invitation,
onAccepted,
}: {
invitation: ReceivedInvitation;
/** Told when the person has joined, for a list the accepted invitation then leaves. */
onAccepted?: (invitation: ReceivedInvitation) => void;
}) {
const accepting = acceptInvitationMutationOptions(queryClient);
const accept = useMutation({
...accepting,
/*
* Told before the lists are read again, not from the button's own callback: reading them again
* takes an accepted invitation out of the list, and this row with it, and a row that has gone
* hears nothing. Declaring an `onSuccess` over the spread replaces the factory's, so it is
* called here, by hand.
*/
onSuccess: async (...args) => {
onAccepted?.({ ...invitation, status: "accepted" });
await accepting.onSuccess?.(...args);
},
});
const decline = useMutation(declineInvitationMutationOptions(queryClient));
const switching = useSwitchOrganization();
const current = useCurrentOrganizationId();
const busy = accept.isPending || decline.isPending;
const failure = accept.error ?? decline.error;
const { name } = invitation.organization;

return (
<>
<Item size="sm">
<ItemMedia variant="icon">
<IconBuilding />
</ItemMedia>
<ItemContent className="min-w-48">
<ItemTitle>{name}</ItemTitle>
<ItemDescription className="line-clamp-none">
{receivedInvitationLine(invitation)}
</ItemDescription>
</ItemContent>
{invitation.status === "pending" ? (
<ItemActions>
<Button
aria-label={`Decline invitation to ${name}`}
disabled={busy}
onClick={() => {
accept.reset();
decline.mutate(invitation.id);
}}
size="sm"
variant="outline"
>
{decline.isPending ? "Declining…" : "Decline"}
</Button>
<Button
aria-label={`Accept invitation to ${name}`}
disabled={busy}
onClick={() => {
decline.reset();
accept.mutate(invitation.id);
}}
size="sm"
>
{accept.isPending ? "Accepting…" : "Accept"}
</Button>
</ItemActions>
) : invitation.status === "accepted" &&
invitation.organization.id !== current ? (
<ItemActions className="min-w-0">
<Button
className="max-w-full"
disabled={switching.pending}
onClick={() => switching.run(invitation.organization.id)}
size="sm"
>
<span className="truncate">Switch to {name}</span>
</Button>
</ItemActions>
) : null}
</Item>
{failure ? (
<p className="px-4 pb-3 text-destructive text-sm" role="alert">
{failure.message}
</p>
) : null}
</>
);
}

/**
* The invitations waiting for the person, whichever organization they are working in.
*
* One they accept leaves the server's list, so it is kept here as accepted until they leave the
* page: the row is where the switch to the organization they just joined is offered.
*/
export function InvitationsPage() {
const invitations = useQuery(receivedInvitationsQueryOptions());
const [accepted, setAccepted] = useState<ReceivedInvitation[]>([]);
const listed = invitations.data ?? [];
const rows = [
...accepted.filter((one) => !listed.some((other) => other.id === one.id)),
...listed,
];

return (
<PageShell
description="Accept an invitation to join an organization. You keep working where you are until you switch."
title="Invitations"
>
{invitations.isPending ? null : invitations.error ? (
<p className="text-destructive text-sm" role="alert">
{invitations.error.message}
</p>
) : rows.length === 0 ? (
<PageEmpty icon={IconMail} title="No invitations">
When somebody invites you to an organization, it shows here.
</PageEmpty>
) : (
<PageRows>
{rows.map((invitation, index) => (
<Fragment key={invitation.id}>
<InvitationRow
invitation={invitation}
onAccepted={(joined) =>
setAccepted((before) => [
joined,
...before.filter((one) => one.id !== joined.id),
])
}
/>
{index !== rows.length - 1 && <Separator />}
</Fragment>
))}
</PageRows>
)}
</PageShell>
);
}

/**
* The page an invitation's link opens: that one invitation, in whatever state it is in. One the
* server does not find for this person is said so, with the one thing to check.
*/
export function InvitationPage({ invitationId }: { invitationId: string }) {
const invitation = useQuery(receivedInvitationQueryOptions(invitationId));

return (
<PageShell
backButton={{ label: "Invitations", linkProps: { to: "/invitations" } }}
title="Invitation"
>
{invitation.isPending ? null : invitation.error ? (
<p className="text-destructive text-sm" role="alert">
{invitation.error.message}
</p>
) : invitation.data === null ? (
<PageEmpty icon={IconMailOff} title="Invitation not found">
Check that you're signed in with the address it was sent to.
</PageEmpty>
) : (
<PageRows>
<InvitationRow invitation={invitation.data} />
</PageRows>
)}
</PageShell>
);
}
47 changes: 43 additions & 4 deletions app/src/components/organizations/organization-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { IconBuilding, IconPlus } from "@tabler/icons-react";
import {
IconBuilding,
IconMail,
IconPlus,
IconSettings,
IconUserCircle,
} from "@tabler/icons-react";
import { Link } from "@tanstack/react-router";
import {
DropdownMenuGroup,
DropdownMenuItem,
Expand All @@ -12,19 +19,23 @@ import { cn } from "@/lib/utils";

/**
* The person's organizations at the top of the account menu: the one they are working in checked,
* the others one click away, and New organization for somebody who may create one.
* the others one click away, its settings, the invitations waiting for their answer, and New
* organization for somebody who may create one.
*
* Drawn only when there is something to switch to or create (`useOrganizationChoices`), so for
* Drawn only where OpenBot lists the person's organizations (`useOrganizationChoices`), so for
* everybody else the menu is the one it always was. The rows take the menu's own item spacing from
* `itemClassName`, and a long name is cut short where the menu is as narrow as the sidebar.
*/
export function OrganizationMenuItems({
choices,
invitationsWaiting,
itemClassName,
onNew,
switching,
}: {
choices: OwnOrganizations;
/** How many invitations wait for the person's answer. The entry is drawn only when some do. */
invitationsWaiting: number;
itemClassName: string;
/** Open the New organization dialog, which lives outside the menu so it outlasts it. */
onNew: () => void;
Expand Down Expand Up @@ -53,11 +64,39 @@ export function OrganizationMenuItems({
key={organization.id}
value={organization.id}
>
<IconBuilding />
{/* The person's own organization carries a person's mark; one they share, a building. */}
{organization.personal ? <IconUserCircle /> : <IconBuilding />}
<span className="min-w-0 truncate">{organization.name}</span>
</DropdownMenuRadioItem>
))}
</DropdownMenuRadioGroup>
{choices.organizations.length > 0 ? (
<DropdownMenuItem
className={itemClassName}
nativeButton={false}
render={<Link to="/settings/organization" />}
>
<IconSettings />
Organization settings
</DropdownMenuItem>
) : null}
{invitationsWaiting > 0 ? (
<DropdownMenuItem
className={itemClassName}
nativeButton={false}
render={<Link to="/invitations" />}
>
<IconMail />
Invitations
<span
className="ml-auto pl-3 text-muted-foreground text-xs tabular-nums"
data-slot="invitations-waiting"
>
<span aria-hidden="true">{invitationsWaiting}</span>
<span className="sr-only">, {invitationsWaiting} waiting</span>
</span>
</DropdownMenuItem>
) : null}
{choices.canCreate ? (
<DropdownMenuItem className={itemClassName} onClick={onNew}>
<IconPlus />
Expand Down
Loading
Loading