Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(inbox): list a guest's notifications in its Work panel (MUL-9855) (#11195)

Jiayuan Zhang29f9b9d3484b
diff --git a/packages/core/issues/queries.ts b/packages/core/issues/queries.ts
index f8d8bf7ffa..1ffbeb7fef 100644
--- a/packages/core/issues/queries.ts
+++ b/packages/core/issues/queries.ts
@@ -691,20 +691,22 @@ export async function fetchIssueByRef(qc: QueryClient, wsId: string, ref: string
* parallel. With an `identifier`, the issue is fetched under the key an
* identifier URL resolves through and mirrored to its UUID, so a link to that
* URL warming the same issue shares the request. prefetchQuery honours each
- * query's staleTime: a warm entry costs nothing.
+ * query's staleTime: a warm entry costs nothing. `runs: false` leaves out the
+ * runs, for a viewer whose issue page shows none (a guest).
*/
export async function prefetchIssuePage(
qc: QueryClient,
wsId: string,
issueId: string,
identifier?: string | null,
+ { runs = true }: { runs?: boolean } = {},
): Promise<void> {
await Promise.all([
identifier
? fetchIssueByRef(qc, wsId, identifier).catch(() => undefined)
: qc.prefetchQuery(issueDetailOptions(wsId, issueId)),
qc.prefetchQuery(issueTimelineOptions(issueId)),
- qc.prefetchQuery(issueTasksOptions(issueId)),
+ runs && qc.prefetchQuery(issueTasksOptions(issueId)),
qc.prefetchQuery(childIssuesOptions(wsId, issueId)),
]);
}
diff --git a/packages/views/inbox/components/inbox-page.tsx b/packages/views/inbox/components/inbox-page.tsx
index e512c0f6f8..fdd0f3b41a 100644
--- a/packages/views/inbox/components/inbox-page.tsx
+++ b/packages/views/inbox/components/inbox-page.tsx
@@ -772,8 +772,8 @@ export function InboxPage() {
// The archive is a second list of the same page, so the title doubles as
// the switch between the two instead of costing a row of its own. Reused in
- // the desktop empty-detail header so guests (whose sidebar has no Inbox menu)
- // and collapsed-list layouts keep the same switcher.
+ // the desktop empty-detail header so collapsed-list layouts keep the same
+ // switcher.
const viewSwitcher = (
<DropdownMenu>
<DropdownMenuTrigger className="-ml-1.5 mr-1.5 flex min-w-0 items-center gap-1 rounded-md px-1.5 py-0.5 outline-none transition-colors hover:bg-accent/60 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring aria-expanded:bg-accent/60">
diff --git a/packages/views/inbox/components/use-inbox-issue-prefetch.test.tsx b/packages/views/inbox/components/use-inbox-issue-prefetch.test.tsx
index 9e9ff7a3c9..6daeddfe9d 100644
--- a/packages/views/inbox/components/use-inbox-issue-prefetch.test.tsx
+++ b/packages/views/inbox/components/use-inbox-issue-prefetch.test.tsx
@@ -8,7 +8,9 @@ import type { InboxItem } from "@multica/core/types";
import { useInboxIssuePrefetch } from "./use-inbox-issue-prefetch";
const prefetchRoute = vi.fn();
+const viewer = vi.hoisted(() => ({ guest: false }));
vi.mock("../../navigation", () => ({ useNavigation: () => ({ prefetch: prefetchRoute }) }));
+vi.mock("@multica/core/permissions", () => ({ useIsGuest: () => viewer.guest }));
vi.mock("@multica/core/api", () => ({
api: {
getIssue: vi.fn(async (ref: string) => {
@@ -40,6 +42,7 @@ describe("useInboxIssuePrefetch", () => {
afterEach(() => {
vi.useRealTimers();
vi.clearAllMocks();
+ viewer.guest = false;
});
it("warms the first unread notifications' issues once the list is idle", async () => {
@@ -70,6 +73,17 @@ describe("useInboxIssuePrefetch", () => {
expect(vi.mocked(api.listTimeline).mock.calls.map(([id]) => id)).toEqual(["a", "e"]);
});
+ it("leaves out the runs for a guest, whose issue page has none", async () => {
+ viewer.guest = true;
+ const { hook } = setup([row("a")]);
+ await act(async () => { await vi.advanceTimersByTimeAsync(1000); });
+ await act(async () => { await hook.result.current(row("e", true)); });
+
+ expect(vi.mocked(api.listTimeline).mock.calls.map(([id]) => id)).toEqual(["a", "e"]);
+ expect(vi.mocked(api.listChildIssues).mock.calls.map(([id]) => id)).toEqual(["a", "e"]);
+ expect(api.listTasksByIssue).not.toHaveBeenCalled();
+ });
+
it("does not restart when realtime replaces the same rows", async () => {
const { hook } = setup([row("a")]);
hook.rerender({ items: [row("a")] });
diff --git a/packages/views/inbox/components/use-inbox-issue-prefetch.ts b/packages/views/inbox/components/use-inbox-issue-prefetch.ts
index 87a9073e99..47e64ee963 100644
--- a/packages/views/inbox/components/use-inbox-issue-prefetch.ts
+++ b/packages/views/inbox/components/use-inbox-issue-prefetch.ts
@@ -3,6 +3,7 @@
import { useCallback, useEffect, useMemo } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { prefetchIssuePage } from "@multica/core/issues/queries";
+import { useIsGuest } from "@multica/core/permissions";
import type { InboxItem } from "@multica/core/types";
import { useNavigation } from "../../navigation";
@@ -22,15 +23,17 @@ export function useInboxIssuePrefetch(
) {
const qc = useQueryClient();
const { prefetch: prefetchRoute } = useNavigation();
+ // A guest's issue page shows no runs, and the server refuses it them.
+ const guest = useIsGuest(wsId);
const prefetchRow = useCallback(
(item: InboxItem) => {
if (!wsId || !item.issue_id) return Promise.resolve();
- return prefetchIssuePage(qc, wsId, item.issue_id, item.issue_identifier).catch(() => {
+ return prefetchIssuePage(qc, wsId, item.issue_id, item.issue_identifier, { runs: !guest }).catch(() => {
// A failed warm-up is the page's own first request again, retried there.
});
},
- [qc, wsId],
+ [qc, wsId, guest],
);
const idleTargets = useMemo(
diff --git a/packages/views/layout/panels/guest-work-panel.test.tsx b/packages/views/layout/panels/guest-work-panel.test.tsx
new file mode 100644
index 0000000000..8a5a4ed883
--- /dev/null
+++ b/packages/views/layout/panels/guest-work-panel.test.tsx
@@ -0,0 +1,149 @@
+import { useState, type ReactNode } from "react";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { fireEvent, screen, waitFor, within } from "@testing-library/react";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { agentTaskSnapshotOptions } from "@multica/core/agents";
+import { inboxListOptions } from "@multica/core/inbox/queries";
+import { useInboxSelectionStore } from "@multica/core/inbox/selection-store";
+import { useSidebarTreeStore } from "@multica/core/issues/stores/sidebar-tree-store";
+import { projectListOptions } from "@multica/core/projects/queries";
+import type { InboxItem, Issue, Project } from "@multica/core/types";
+import { renderWithI18n } from "../../test/i18n";
+import { NavigationProvider, type NavigationAdapter } from "../../navigation";
+import { GuestWorkPanel } from "./guest-work-panel";
+
+const apiMock = vi.hoisted(() => ({ getIssue: vi.fn() }));
+
+vi.mock("@multica/core/api", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@multica/core/api")>()),
+ api: apiMock,
+}));
+vi.mock("../../issues/components/status-icon", () => ({ StatusIcon: () => <span /> }));
+vi.mock("../../common/actor-avatar", () => ({ ActorAvatar: () => null }));
+vi.mock("@multica/ui/components/common/tooltip-hint", () => ({
+ TooltipHint: ({ children }: { children: ReactNode }) => <>{children}</>,
+}));
+vi.mock("@multica/core/paths", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("@multica/core/paths")>();
+ return {
+ ...actual,
+ useWorkspacePaths: () => actual.paths.workspace("acme"),
+ useCurrentWorkspace: () => ({ id: "ws-1", name: "Acme" }),
+ };
+});
+vi.mock("@multica/core/permissions", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@multica/core/permissions")>()),
+ useIsGuest: () => true,
+}));
+vi.mock("@multica/core/hooks", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@multica/core/hooks")>()),
+ useWorkspaceId: () => "ws-1",
+}));
+vi.mock("@multica/core/issue-statuses/hooks", async () => {
+ const { buildIssueStatusCatalog } = await import("@multica/core/issue-statuses/queries");
+ return { useIssueStatuses: () => buildIssueStatusCatalog([]) };
+});
+
+const ISSUE = {
+ id: "0a3f0a8e-6a52-4c1e-9f5e-1b2c3d4e5f60",
+ identifier: "MUL-1",
+ title: "Review the brief",
+ status: "todo",
+} as Issue;
+// An Inbox row's link also reads out who did what, after the title.
+const INBOX_ROW_NAME = new RegExp(`^${ISSUE.title}`);
+
+const PROJECT = {
+ id: "5d4c3b2a-1f0e-4d9c-8b7a-6f5e4d3c2b1a",
+ title: "Launch",
+ status: "in_progress",
+ issue_count: 0,
+ done_count: 0,
+ created_at: "",
+ updated_at: "",
+} as unknown as Project;
+
+const NOTIFICATION: InboxItem = {
+ id: `inbox-${ISSUE.id}`,
+ workspace_id: "ws-1",
+ recipient_type: "member",
+ recipient_id: "guest-1",
+ actor_type: "member",
+ actor_id: "member-1",
+ type: "mentioned",
+ severity: "info",
+ issue_id: ISSUE.id,
+ title: ISSUE.title,
+ body: null,
+ issue_status: ISSUE.status,
+ issue_priority: "none",
+ read: false,
+ archived: false,
+ created_at: "2026-11-10T08:00:00Z",
+ details: null,
+};
+
+function renderPanel(initialPath: string, inbox: InboxItem[]) {
+ const qc = new QueryClient({ defaultOptions: { queries: { staleTime: Infinity, retry: false } } });
+ qc.setQueryData(inboxListOptions("ws-1").queryKey, inbox);
+ qc.setQueryData(projectListOptions("ws-1").queryKey, { projects: [PROJECT], total: 1 });
+ qc.setQueryData(agentTaskSnapshotOptions("ws-1").queryKey, []);
+
+ function Harness() {
+ const [pathname, setPathname] = useState(initialPath);
+ const adapter: NavigationAdapter = {
+ push: (path) => setPathname(new URL(path, "http://x").pathname),
+ replace: setPathname,
+ back: vi.fn(),
+ pathname,
+ searchParams: new URLSearchParams(),
+ hash: "",
+ getShareableUrl: (path) => path,
+ };
+ return (
+ <NavigationProvider value={adapter}>
+ <GuestWorkPanel />
+ <output data-testid="pathname">{pathname}</output>
+ </NavigationProvider>
+ );
+ }
+
+ renderWithI18n(
+ <QueryClientProvider client={qc}>
+ <Harness />
+ </QueryClientProvider>,
+ );
+}
+
+const inInbox = () => document.querySelector('[data-sidebar-list="inbox"]') as HTMLElement;
+
+beforeEach(() => {
+ useSidebarTreeStore.setState({ inboxCollapsed: false });
+ useInboxSelectionStore.setState({
+ sidebarIssueByWorkspace: {},
+ sidebarTabIssuesByWorkspace: {},
+ heldRows: {},
+ leftRowKeyByWorkspace: {},
+ });
+ // The issue page never finishes loading, so the panel cannot lean on it.
+ apiMock.getIssue.mockReturnValue(new Promise<Issue>(() => {}));
+});
+
+describe("GuestWorkPanel", () => {
+ it("lists the guest's notifications beside an Inbox page that shows only the open one", async () => {
+ renderPanel("/acme/inbox", [NOTIFICATION]);
+ const labels = Array.from(document.querySelectorAll("[data-mc='panel-section'] h3")).map((h) => h.textContent);
+ expect(labels).toEqual(["Inbox", "Shared with you"]);
+ expect(await within(inInbox()).findByRole("link", { name: INBOX_ROW_NAME })).toBeInTheDocument();
+ });
+
+ it("opens a notification's issue and keeps its row lit", async () => {
+ renderPanel("/acme/inbox", [NOTIFICATION]);
+ fireEvent.click(await within(inInbox()).findByRole("link", { name: INBOX_ROW_NAME }));
+ expect(screen.getByTestId("pathname")).toHaveTextContent(`/acme/issues/${ISSUE.id}`);
+ expect(useInboxSelectionStore.getState().sidebarIssueByWorkspace["ws-1"]).toBe(ISSUE.id);
+ await waitFor(() =>
+ expect(within(inInbox()).getByRole("link", { name: INBOX_ROW_NAME })).toHaveAttribute("aria-current", "page"),
+ );
+ });
+});
diff --git a/packages/views/layout/panels/guest-work-panel.tsx b/packages/views/layout/panels/guest-work-panel.tsx
index f55cc24357..6240f07a22 100644
--- a/packages/views/layout/panels/guest-work-panel.tsx
+++ b/packages/views/layout/panels/guest-work-panel.tsx
@@ -4,15 +4,21 @@ import { useQuery } from "@tanstack/react-query";
import { Eye } from "@multica/ui/icons";
import { Badge } from "@multica/ui/components/ui/badge";
import { TooltipHint } from "@multica/ui/components/common/tooltip-hint";
-import { useInboxUnreadCount } from "@multica/core/inbox/queries";
+import { useInboxSelectionStore } from "@multica/core/inbox/selection-store";
+import { isIssueUuid } from "@multica/core/issues/canonical-id";
+import { issueDetailOptions } from "@multica/core/issues/queries";
import { useCurrentWorkspace, useWorkspacePaths } from "@multica/core/paths";
import { projectListOptions } from "@multica/core/projects/queries";
import type { Project } from "@multica/core/types";
-import { useNavigation } from "../../navigation";
+import { resolveClickIntent, useNavigation } from "../../navigation";
+import { AutoArchivePromptDialog } from "../../inbox/components/auto-archive-prompt-dialog";
+import { useSidebarInboxIssue } from "../../inbox/components/use-sidebar-inbox-issue";
import { ProjectIcon } from "../../projects/components/project-icon";
import { useT } from "../../i18n";
import { PanelBody, PanelCount, PanelHeader, PanelLink, PanelList, PanelSection, isPathWithin } from "../panel-nav";
import { routeIconForPath } from "../route-icon-components";
+import { INBOX_LIST, InboxSection, useInboxSectionRows } from "./inbox-section";
+import { routeSegment } from "./work-panel";
const EMPTY_PROJECTS: Project[] = [];
@@ -20,22 +26,64 @@ const EMPTY_PROJECTS: Project[] = [];
* The Work panel for a guest (MUL-9420): its Inbox, the issues it takes part
* in, and the projects shared with it. Everything else in the workspace is
* out of a guest's reach, so nothing else is listed.
+ *
+ * The Inbox section is the member one: on a wide screen the Inbox page shows
+ * only the open notification, so its list has to live here (MUL-9855).
*/
export function GuestWorkPanel() {
const { t } = useT("layout");
const p = useWorkspacePaths();
- const { pathname } = useNavigation();
+ const { pathname, searchParams, openInNewTab } = useNavigation();
const workspace = useCurrentWorkspace();
const wsId = workspace?.id;
- const unread = useInboxUnreadCount(wsId);
const { data: projects = EMPTY_PROJECTS } = useQuery({
...projectListOptions(wsId ?? ""),
enabled: !!wsId,
});
const shared = projects.filter((project) => !project.archived_at);
- const InboxIcon = routeIconForPath(p.inbox());
const InvolvedIcon = routeIconForPath(p.myIssues());
+ // Cache read only: the detail page owns resolving the route's issue.
+ const issueSegment = routeSegment(pathname, p.issues());
+ const { data: currentIssue } = useQuery({
+ ...issueDetailOptions(wsId ?? "", issueSegment ?? ""),
+ enabled: false,
+ });
+ const currentIssueId = issueSegment
+ ? (currentIssue?.id ?? (isIssueUuid(issueSegment) ? issueSegment : null))
+ : null;
+ const inbox = useSidebarInboxIssue(wsId, currentIssueId);
+ const inboxOpenKey =
+ pathname === p.inbox()
+ ? searchParams.get("issue")
+ : currentIssueId && inbox.fromInbox
+ ? currentIssueId
+ : null;
+ const inboxRows = useInboxSectionRows(wsId, inboxOpenKey);
+ const inboxClaimsIssue = !!currentIssueId && inbox.fromInbox && !inboxRows.collapsed;
+ const rememberSidebarIssue = useInboxSelectionStore((s) => s.rememberSidebarIssue);
+ const rememberSidebarTabIssue = useInboxSelectionStore((s) => s.rememberSidebarTabIssue);
+ const forgetSidebarTabIssue = useInboxSelectionStore((s) => s.forgetSidebarTabIssue);
+ // An issue opened from an Inbox row belongs to the Inbox, as in the member
+ // panel: its row stays lit and the issue header moves on to the next one.
+ const rememberInboxIssue = (event: React.MouseEvent) => {
+ // A middle click opens a tab; other buttons open nothing.
+ if (event.type === "auxclick" && event.button !== 1) return;
+ const link = (event.target as HTMLElement).closest("a[href]");
+ const segment = link?.getAttribute("data-issue-id");
+ if (!link || !segment || !wsId) return;
+ // An Inbox row's hover card renders in a portal, outside the row's list.
+ const fromInbox =
+ !!link.closest("[data-inbox-card]") || link.closest("[data-sidebar-list]")?.getAttribute("data-sidebar-list") === INBOX_LIST;
+ if (!fromInbox) return;
+ if (resolveClickIntent(event) !== "push" || (event.shiftKey && !openInNewTab)) {
+ if (openInNewTab) rememberSidebarTabIssue(wsId, segment);
+ return;
+ }
+ rememberSidebarIssue(wsId, segment);
+ forgetSidebarTabIssue(wsId, segment);
+ };
+
return (
<>
<PanelHeader title={workspace?.name ?? t(($) => $.spaces.work)}>
@@ -46,15 +94,8 @@ export function GuestWorkPanel() {
</Badge>
</TooltipHint>
</PanelHeader>
- <PanelBody>
+ <PanelBody onClickCapture={rememberInboxIssue} onAuxClickCapture={rememberInboxIssue}>
<PanelList>
- <PanelLink
- href={p.inbox()}
- icon={<InboxIcon />}
- label={t(($) => $.nav.inbox)}
- active={pathname === p.inbox()}
- trailing={<PanelCount value={unread} />}
- />
<PanelLink
href={p.myIssues()}
icon={<InvolvedIcon />}
@@ -62,6 +103,15 @@ export function GuestWorkPanel() {
active={isPathWithin(pathname, p.myIssues())}
/>
</PanelList>
+ {wsId && (
+ <InboxSection
+ wsId={wsId}
+ rows={inboxRows}
+ pathname={pathname}
+ activeIssueId={inboxClaimsIssue ? currentIssueId : null}
+ />
+ )}
+ {wsId && <AutoArchivePromptDialog wsId={wsId} active={!!inboxOpenKey} />}
<PanelSection label={t(($) => $.panels.work.shared_projects)}>
<PanelList>
{shared.map((project) => (
diff --git a/packages/views/layout/panels/inbox-section.test.tsx b/packages/views/layout/panels/inbox-section.test.tsx
index dbc85a14ba..ba595fc9a8 100644
--- a/packages/views/layout/panels/inbox-section.test.tsx
+++ b/packages/views/layout/panels/inbox-section.test.tsx
@@ -44,6 +44,10 @@ vi.mock("@multica/core/paths", async (importOriginal) => {
const actual = await importOriginal<typeof import("@multica/core/paths")>();
return { ...actual, useWorkspacePaths: () => actual.paths.workspace("acme") };
});
+vi.mock("@multica/core/permissions", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@multica/core/permissions")>()),
+ useIsGuest: () => false,
+}));
vi.mock("@multica/core/inbox/queries", async (importOriginal) => ({
...(await importOriginal<typeof import("@multica/core/inbox/queries")>()),
useInboxUnreadCount: () => state.unread,
diff --git a/packages/views/layout/panels/work-panel.tsx b/packages/views/layout/panels/work-panel.tsx
index ae26eaaff1..ef2dbccd22 100644
--- a/packages/views/layout/panels/work-panel.tsx
+++ b/packages/views/layout/panels/work-panel.tsx
@@ -41,7 +41,7 @@ interface ClickedIssue {
* The `{id}` of a `{base}/{id}` route — for `/issues/{id}`, a UUID or an
* identifier like `MUL-123`.
*/
-function routeSegment(pathname: string, base: string): string | null {
+export function routeSegment(pathname: string, base: string): string | null {
if (!pathname.startsWith(base + "/")) return null;
const segment = pathname.slice(base.length + 1).split("/")[0];
return segment ? decodeURIComponent(segment) : null;
diff --git a/server/internal/handler/guest_boundaries_test.go b/server/internal/handler/guest_boundaries_test.go
index ee52e54364..bad1f9747a 100644
--- a/server/internal/handler/guest_boundaries_test.go
+++ b/server/internal/handler/guest_boundaries_test.go
@@ -444,6 +444,75 @@ func TestGuestMayDeleteOwnCommentKeepingReplies(t *testing.T) {
}
}
+// A guest takes back an Unsubscribe & archive from its Inbox, on an issue in
+// its project only.
+func TestGuestUndoesItsUnsubscribe(t *testing.T) {
+ f := newGuestFixture(t)
+ t.Cleanup(func() {
+ dbfx.Exec(t, `DELETE FROM issue_subscriber WHERE issue_id IN ($1, $2)`, f.sharedIssue, f.otherIssue)
+ })
+ dbfx.Exec(t, `INSERT INTO issue_subscriber (issue_id, user_type, user_id, reason) VALUES ($1, 'member', $2, 'commenter')`,
+ f.sharedIssue, f.guest)
+ post := func(h http.HandlerFunc, issue, suffix string) *testutil.Response {
+ t.Helper()
+ return guestRequest(t, h, f.guest, http.MethodPost, "/api/issues/"+issue+suffix, nil, "id", issue)
+ }
+
+ post(testHandler.UnsubscribeFromIssue, f.sharedIssue, "/unsubscribe").Want(http.StatusOK)
+ var body map[string]any
+ post(testHandler.UndoUnsubscribeFromIssue, f.sharedIssue, "/unsubscribe/undo").Want(http.StatusOK).JSON(&body)
+ if body["reason"] != "commenter" {
+ t.Fatalf("guest undo answered %v, want its commenter subscription back", body)
+ }
+ post(testHandler.UndoUnsubscribeFromIssue, f.otherIssue, "/unsubscribe/undo").Want(http.StatusNotFound)
+}
+
+// A guest's Unsubscribe & archive may take the sub-issues too, for itself
+// only, and on an issue in its project only.
+func TestGuestUnsubscribesItselfFromASubtree(t *testing.T) {
+ f := newGuestFixture(t)
+ child := dbfx.Issue(t, f.marker+" child", testutil.Cols{"project_id": f.shared, "parent_issue_id": f.sharedIssue})
+ t.Cleanup(func() {
+ dbfx.Exec(t, `DELETE FROM issue_subscriber WHERE issue_id IN ($1, $2)`, f.sharedIssue, child)
+ })
+ for _, issue := range []string{f.sharedIssue, child} {
+ for _, user := range []string{f.guest, testUserID} {
+ dbfx.Exec(t, `INSERT INTO issue_subscriber (issue_id, user_type, user_id, reason) VALUES ($1, 'member', $2, 'commenter')`, issue, user)
+ }
+ }
+ subscribed := func(issue, user string) bool {
+ t.Helper()
+ var n int
+ dbfx.QueryRow(t, `SELECT count(*) FROM issue_subscriber
+ WHERE issue_id = $1 AND user_type = 'member' AND user_id = $2 AND unsubscribed_at IS NULL`, issue, user).Scan(&n)
+ return n > 0
+ }
+ post := func(issue string, body any) *testutil.Response {
+ t.Helper()
+ return guestRequest(t, testHandler.UnsubscribeFromIssueSubtree, f.guest, http.MethodPost,
+ "/api/issues/"+issue+"/unsubscribe/subtree", body, "id", issue)
+ }
+
+ post(f.sharedIssue, map[string]string{"user_id": testUserID, "user_type": "member"}).Want(http.StatusForbidden)
+ if !subscribed(f.sharedIssue, testUserID) || !subscribed(child, testUserID) {
+ t.Fatal("a guest's subtree unsubscribe took a member's subscriptions")
+ }
+ post(f.otherIssue, nil).Want(http.StatusNotFound)
+ post(f.sharedIssue, nil).Want(http.StatusOK)
+ if subscribed(f.sharedIssue, f.guest) || subscribed(child, f.guest) {
+ t.Fatal("the guest is still subscribed to the tree it left")
+ }
+}
+
+// A guest settles the auto-archive prompt its Inbox shows it.
+func TestGuestResolvesAutoArchivePrompt(t *testing.T) {
+ f := newGuestFixture(t)
+ guestRequest(t, testHandler.ResolveAutoArchivePrompt, f.guest, http.MethodPost,
+ "/api/notification-preferences/auto-archive-prompt",
+ map[string]any{"preferences": map[string]string{"auto_archive_completed": "all"}}).
+ Want(http.StatusOK)
+}
+
// --- Local search after losing access --------------------------------------
func searchChangesAs(t *testing.T, userID, cursor string) *testutil.Response {
diff --git a/server/internal/handler/subscriber.go b/server/internal/handler/subscriber.go
index d0e67b9fc4..1cd84e34cc 100644
--- a/server/internal/handler/subscriber.go
+++ b/server/internal/handler/subscriber.go
@@ -285,6 +285,14 @@ func (h *Handler) unsubscribeFromIssue(w http.ResponseWriter, r *http.Request, s
// (MUL-5483 review round 8).
targetUserID = uuidToString(parseUUID(targetUserID))
+ // A guest leaves a tree for itself only: the tree may reach past its
+ // projects, and other people's subscriptions there are not its to change.
+ if subtree && (targetUserType != callerActorType || targetUserID != uuidToString(parseUUID(callerActorID))) &&
+ h.isGuest(r, workspaceID, requestUserID(r)) {
+ writeError(w, http.StatusForbidden, "guests can only unsubscribe themselves")
+ return
+ }
+
// Every issue this call actually left. The subtree variant reports the whole
// set so each one gets its own broadcast: a client with a CHILD issue open
// never sees the root's event, and would otherwise keep showing a
diff --git a/server/internal/middleware/guest.go b/server/internal/middleware/guest.go
index 4af1f5e5fc..5a2e420bd0 100644
--- a/server/internal/middleware/guest.go
+++ b/server/internal/middleware/guest.go
@@ -52,6 +52,10 @@ var guestRoutes = compileGuestRoutes([]string{
"DELETE /api/issues/*/reactions",
"POST /api/issues/*/subscribe",
"POST /api/issues/*/unsubscribe",
+ // The Inbox's Unsubscribe & archive: its undo, and its choice to leave
+ // the sub-issues too (the caller's own subscriptions only, for a guest).
+ "POST /api/issues/*/unsubscribe/undo",
+ "POST /api/issues/*/unsubscribe/subtree",
"POST /api/issues/*/read",
"POST /api/issues/*/unread",
"PUT /api/comments/*",
@@ -91,6 +95,7 @@ var guestRoutes = compileGuestRoutes([]string{
"GET /api/notification-preferences",
"PATCH /api/notification-preferences",
"PUT /api/notification-preferences",
+ "POST /api/notification-preferences/auto-archive-prompt",
"GET /api/pins",
"POST /api/pins",
"PUT /api/pins/reorder",