Skip to content

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

Go

fix(permissions): deny guests in role-gated helpers and hide Delete issue from them (MUL-9877) (#11213)

Jiayuan Zhange72ec96cdbc1
diff --git a/packages/core/agents/use-workspace-agent-availability.ts b/packages/core/agents/use-workspace-agent-availability.ts
index ff093e4e2d..1444a97c2a 100644
--- a/packages/core/agents/use-workspace-agent-availability.ts
+++ b/packages/core/agents/use-workspace-agent-availability.ts
@@ -44,11 +44,7 @@ export function useWorkspaceAgentAvailability(): WorkspaceAgentAvailability {
if (!agentsFetched || !membersFetched) return "loading";
- const rawRole = members?.find((m) => m.user_id === userId)?.role;
- const role =
- rawRole === "owner" || rawRole === "admin" || rawRole === "member"
- ? rawRole
- : null;
+ const role = members?.find((m) => m.user_id === userId)?.role ?? null;
const hasVisibleAgent = (agents ?? []).some(
(a) =>
diff --git a/packages/core/docs/deletion-permissions.ts b/packages/core/docs/deletion-permissions.ts
index a0bd9634ea..b4cf0eebea 100644
--- a/packages/core/docs/deletion-permissions.ts
+++ b/packages/core/docs/deletion-permissions.ts
@@ -3,14 +3,14 @@ import type { Agent, MemberRole } from "../types";
// Mirrors the server rule (requireDocDeletion). The server stays
// authoritative; this only decides whether delete is offered. Docs and
// folders share the rule: owners and admins delete anything, members delete
-// what they or an agent they own created.
+// what they or an agent they own created. Guests have no docs at all.
export function canDeleteDoc(
item: { createdByType: "member" | "agent"; createdById: string },
userId: string | null,
role: MemberRole | null,
agents: readonly Pick<Agent, "id" | "owner_id">[],
): boolean {
- if (!userId || !role) return false;
+ if (!userId || !role || role === "guest") return false;
if (role === "owner" || role === "admin") return true;
if (item.createdByType === "member") return item.createdById === userId;
return agents.some(
diff --git a/packages/core/issue-views/queries.ts b/packages/core/issue-views/queries.ts
index 64d50e38d8..e434a0c900 100644
--- a/packages/core/issue-views/queries.ts
+++ b/packages/core/issue-views/queries.ts
@@ -56,14 +56,15 @@ export function issueViewDetailOptions(wsId: string, id: string) {
/**
* Client-side mirror of the server's canManageIssueView: the owner, or a
* workspace owner/admin for views shared to the workspace. Drives which
- * affordances render — the server re-checks on every write.
+ * affordances render — the server re-checks on every write. A guest has no
+ * saved views, so it manages none, even one it made as a member.
*/
export function canManageIssueView(
view: { owner_id: string; visibility: string },
userId: string | null,
role: string | null | undefined,
): boolean {
- if (!userId) return false;
+ if (!userId || role === "guest") return false;
if (view.owner_id === userId) return true;
return view.visibility === "workspace" && (role === "owner" || role === "admin");
}
diff --git a/packages/core/issues/deletion-permissions.ts b/packages/core/issues/deletion-permissions.ts
index 48e28df705..be8283deab 100644
--- a/packages/core/issues/deletion-permissions.ts
+++ b/packages/core/issues/deletion-permissions.ts
@@ -1,14 +1,15 @@
import type { Agent, Issue, MemberRole } from "../types";
// Mirrors the server rule. The server stays authoritative; this only decides
-// whether delete affordances are offered.
+// whether delete affordances are offered. A guest deletes nothing, not even an
+// issue it created before it became a guest.
export function canDeleteIssue(
issue: Pick<Issue, "creator_type" | "creator_id">,
userId: string | null,
role: MemberRole | null,
agents: readonly Pick<Agent, "id" | "owner_id">[],
): boolean {
- if (!userId || !role) return false;
+ if (!userId || !role || role === "guest") return false;
if (role === "owner" || role === "admin") return true;
if (issue.creator_type === "member") return issue.creator_id === userId;
return (
diff --git a/packages/core/issues/use-issue-deletion.ts b/packages/core/issues/use-issue-deletion.ts
index 41d01a3bef..f2e5fff532 100644
--- a/packages/core/issues/use-issue-deletion.ts
+++ b/packages/core/issues/use-issue-deletion.ts
@@ -14,5 +14,8 @@ export function useIssueDeletion(wsId: string) {
});
return {
canDelete: (issue: Issue) => canDeleteIssue(issue, userId, role, agents),
+ // A guest can delete no issue at all, so menus leave the entry out
+ // instead of showing it disabled.
+ offersDelete: role !== "guest",
};
}
diff --git a/packages/core/permissions/guest-deny.test.ts b/packages/core/permissions/guest-deny.test.ts
new file mode 100644
index 0000000000..8a75c9f6bb
--- /dev/null
+++ b/packages/core/permissions/guest-deny.test.ts
@@ -0,0 +1,82 @@
+// @vitest-environment node
+import { describe, expect, it } from "vitest";
+import type { Agent, Comment, MemberRole, RuntimeDevice, Skill } from "../types";
+import { canDeleteDoc } from "../docs/deletion-permissions";
+import { canManageIssueView } from "../issue-views/queries";
+import { canDeleteIssue } from "../issues/deletion-permissions";
+import { canChangeProjectLead, canManageProjectAccess } from "../projects/access";
+import { canDeleteProject } from "../projects/deletion-permissions";
+import * as rules from "./rules";
+
+// Guests (MUL-9420) are deny-by-default: every role-gated helper must refuse a
+// guest, including on what the guest created or owned before it was made a
+// guest. Each case pairs the guest with the role that IS allowed on the same
+// fixture, so a case can't pass by never reaching the creator/owner branch.
+// A new role-gated helper belongs in this table.
+
+const ME = "user-me";
+const OTHER = "user-other";
+
+const myAgent = { id: "agt_mine", owner_id: ME } as Agent;
+const agents = [myAgent];
+const ownedAgent = {
+ ...myAgent,
+ permission_mode: "public_to",
+ invocation_targets: [{ target_type: "workspace", target_id: null }],
+} as Agent;
+const mySkill = { id: "skl_1", created_by: ME } as Skill;
+const myRuntime = { id: "rt_1", owner_id: ME } as RuntimeDevice;
+const ledProject = { lead_type: "member", lead_id: ME, visibility: "private" } as const;
+const openProject = { lead_type: null, lead_id: null, visibility: "workspace" } as const;
+
+type Case = [name: string, allowedAs: MemberRole, check: (role: MemberRole) => boolean];
+
+const cases: Case[] = [
+ ["canDeleteIssue (own issue)", "member", (role) => canDeleteIssue({ creator_type: "member", creator_id: ME }, ME, role, agents)],
+ ["canDeleteIssue (own agent's issue)", "member", (role) => canDeleteIssue({ creator_type: "agent", creator_id: myAgent.id }, ME, role, agents)],
+ ["canDeleteDoc (own doc)", "member", (role) => canDeleteDoc({ createdByType: "member", createdById: ME }, ME, role, agents)],
+ ["canDeleteDoc (own agent's doc)", "member", (role) => canDeleteDoc({ createdByType: "agent", createdById: myAgent.id }, ME, role, agents)],
+ ["canDeleteProject (own project)", "member", (role) => canDeleteProject({ creator_type: "member", creator_id: ME }, ME, role, agents)],
+ ["canManageProjectAccess (lead of a private project)", "member", (role) => canManageProjectAccess(ledProject, ME, role, ME)],
+ ["canChangeProjectLead (workspace-visible project)", "member", (role) => canChangeProjectLead(openProject, ME, role, null)],
+ ["canChangeProjectLead (lead of a private project)", "member", (role) => canChangeProjectLead(ledProject, ME, role, ME)],
+ ["canManageIssueView (own view)", "member", (role) => canManageIssueView({ owner_id: ME, visibility: "workspace" }, ME, role)],
+ ["canEditAgent (own agent)", "member", (role) => rules.canEditAgent(myAgent, { userId: ME, role }).allowed],
+ ["canAssignAgentToIssue (own agent)", "member", (role) => rules.canAssignAgentToIssue(ownedAgent, { userId: ME, role }).allowed],
+ ["canAssignAgentToIssue (workspace-shared agent)", "member", (role) => rules.canAssignAgentToIssue(ownedAgent, { userId: OTHER, role }).allowed],
+ ["canEditSkill (own skill)", "member", (role) => rules.canEditSkill(mySkill, { userId: ME, role }).allowed],
+ ["canDeleteSkill (own skill)", "member", (role) => rules.canDeleteSkill(mySkill, { userId: ME, role }).allowed],
+ ["canDeleteRuntime (own runtime)", "member", (role) => rules.canDeleteRuntime(myRuntime, { userId: ME, role }).allowed],
+ ["canUpdateWorkspaceSettings", "admin", (role) => rules.canUpdateWorkspaceSettings({ userId: ME, role }).allowed],
+ ["canDeleteWorkspace", "owner", (role) => rules.canDeleteWorkspace({ userId: ME, role }).allowed],
+ ["canManageMembers", "admin", (role) => rules.canManageMembers({ userId: ME, role }).allowed],
+ ["canChangeMemberRole", "admin", (role) => rules.canChangeMemberRole({ role: "member" }, 1, { userId: ME, role }).allowed],
+];
+
+// Routes the server's guest allowlist lets through, so a guest may pass.
+const GUEST_ALLOWED_RULES = new Set(["canEditComment", "canDeleteComment"]);
+
+describe("guest deny-by-default", () => {
+ it.each(cases)("%s denies a guest", (_name, allowedAs, check) => {
+ expect(check(allowedAs)).toBe(true);
+ expect(check("guest")).toBe(false);
+ });
+
+ it("covers every rule in rules.ts", () => {
+ const covered = new Set(cases.map(([name]) => name.split(" ")[0]));
+ const missing = Object.keys(rules).filter(
+ (name) => name.startsWith("can") && !covered.has(name) && !GUEST_ALLOWED_RULES.has(name),
+ );
+ expect(missing).toEqual([]);
+ });
+
+ it("lets a guest edit and delete only its own comments", () => {
+ const mine = { author_type: "member", author_id: ME } as Comment;
+ const theirs = { author_type: "member", author_id: OTHER } as Comment;
+ const guest = { userId: ME, role: "guest" } as const;
+ expect(rules.canEditComment(mine, guest).allowed).toBe(true);
+ expect(rules.canDeleteComment(mine, guest).allowed).toBe(true);
+ expect(rules.canEditComment(theirs, guest).allowed).toBe(false);
+ expect(rules.canDeleteComment(theirs, guest).allowed).toBe(false);
+ });
+});
diff --git a/packages/core/permissions/rules.ts b/packages/core/permissions/rules.ts
index 94640fdb9f..0cb37b9337 100644
--- a/packages/core/permissions/rules.ts
+++ b/packages/core/permissions/rules.ts
@@ -17,11 +17,19 @@ import { ALLOW, deny, type Decision, type PermissionContext } from "./types";
* Returning a `Decision` (not a boolean) lets every surface — disabled state,
* tooltip, banner copy — read the same `reason` and stay consistent without
* sprinkling copy through the view layer.
+ *
+ * Guests (MUL-9420) are deny-by-default, like the server's route allowlist in
+ * `server/internal/middleware/guest.go`: a rule allows a guest only for what
+ * that list lets through, even on a resource the guest created or owned
+ * before it became a guest. Add every new rule to the guest table in
+ * `guest-deny.test.ts`.
*/
const isAdminLike = (role: MemberRole | null) =>
role === "owner" || role === "admin";
+const guestDenied = (message: string) => deny("guest_role", message);
+
// ---- Agents ----------------------------------------------------------------
/**
@@ -33,6 +41,7 @@ export function canEditAgent(agent: Agent, ctx: PermissionContext): Decision {
if (ctx.userId === null) {
return deny("not_authenticated", "Sign in to edit this agent.");
}
+ if (ctx.role === "guest") return guestDenied("Guests can't edit agents.");
if (isAdminLike(ctx.role)) return ALLOW;
if (agent.owner_id !== null && agent.owner_id === ctx.userId) return ALLOW;
return deny(
@@ -61,6 +70,8 @@ export function canAssignAgentToIssue(
if (ctx.userId === null) {
return deny("not_authenticated", "Sign in to assign agents.");
}
+ // Guests never run agents, not even one they owned as a member.
+ if (ctx.role === "guest") return guestDenied("Guests can't assign work to agents.");
// The owner may always invoke their own agent, regardless of mode.
if (agent.owner_id !== null && agent.owner_id === ctx.userId) {
@@ -108,6 +119,7 @@ export function canEditSkill(skill: Skill, ctx: PermissionContext): Decision {
if (ctx.userId === null) {
return deny("not_authenticated", "Sign in to edit this skill.");
}
+ if (ctx.role === "guest") return guestDenied("Guests can't edit skills.");
if (isAdminLike(ctx.role)) return ALLOW;
if (skill.created_by !== null && skill.created_by === ctx.userId) {
return ALLOW;
@@ -124,6 +136,9 @@ export function canDeleteSkill(skill: Skill, ctx: PermissionContext): Decision {
// ---- Comments --------------------------------------------------------------
+// A guest may edit and delete its own comments: the server lets those routes
+// through and the handler allows only the author.
+
export function canEditComment(
comment: Comment,
ctx: PermissionContext,
@@ -173,6 +188,7 @@ export function canDeleteRuntime(
if (ctx.userId === null) {
return deny("not_authenticated", "Sign in to delete runtimes.");
}
+ if (ctx.role === "guest") return guestDenied("Guests can't delete runtimes.");
if (isAdminLike(ctx.role)) return ALLOW;
if (runtime.owner_id !== null && runtime.owner_id === ctx.userId) {
return ALLOW;
diff --git a/packages/core/permissions/types.ts b/packages/core/permissions/types.ts
index 2eff452fde..013765a61e 100644
--- a/packages/core/permissions/types.ts
+++ b/packages/core/permissions/types.ts
@@ -22,6 +22,7 @@ export type DecisionReason =
| "allowed"
| "not_authenticated"
| "not_member"
+ | "guest_role"
| "not_owner_role"
| "not_admin_role"
| "not_resource_owner"
diff --git a/packages/core/projects/access.ts b/packages/core/projects/access.ts
index d7c40c1448..accc0ac277 100644
--- a/packages/core/projects/access.ts
+++ b/packages/core/projects/access.ts
@@ -33,12 +33,14 @@ export function canManageProjectAccess(
// Changing the lead of a private project can change who manages its access,
// so only access managers may; elsewhere the lead stays an ordinary field.
+// A guest edits no project, so it sets no lead either.
export function canChangeProjectLead(
project: Pick<Project, "lead_type" | "lead_id" | "visibility">,
userId: string | null | undefined,
role: string | null | undefined,
managerId: string | null | undefined,
): boolean {
+ if (role === "guest") return false;
return project.visibility !== "private" || canManageProjectAccess(project, userId, role, managerId);
}
diff --git a/packages/ui/components/common/capability-banner.tsx b/packages/ui/components/common/capability-banner.tsx
index f21a08a4ba..30df56e8ac 100644
--- a/packages/ui/components/common/capability-banner.tsx
+++ b/packages/ui/components/common/capability-banner.tsx
@@ -7,6 +7,7 @@ type Reason =
| "allowed"
| "not_authenticated"
| "not_member"
+ | "guest_role"
| "not_owner_role"
| "not_admin_role"
| "not_resource_owner"
@@ -67,6 +68,8 @@ function getCopy(reason: Reason, noun: string, ownerName?: string): string {
return `Sign in to edit this ${noun}.`;
case "not_member":
return `Join this workspace to edit this ${noun}.`;
+ case "guest_role":
+ return `View only — guests can't edit this ${noun}.`;
case "not_owner_role":
return `View only — only the workspace owner can manage this ${noun}.`;
case "not_admin_role":
diff --git a/packages/views/issues/actions/__tests__/issue-actions-menu.test.tsx b/packages/views/issues/actions/__tests__/issue-actions-menu.test.tsx
index 5fdf761417..59bbad9858 100644
--- a/packages/views/issues/actions/__tests__/issue-actions-menu.test.tsx
+++ b/packages/views/issues/actions/__tests__/issue-actions-menu.test.tsx
@@ -14,9 +14,9 @@ const TEST_RESOURCES = { en: { common: enCommon, issues: enIssues } };
// Mocks — same pattern as the issue-detail test suite.
// ---------------------------------------------------------------------------
-const deletionPolicy = vi.hoisted(() => ({ allowed: true }));
+const deletionPolicy = vi.hoisted(() => ({ allowed: true, offered: true }));
vi.mock("@multica/core/issues/use-issue-deletion", () => ({
- useIssueDeletion: () => ({ canDelete: () => deletionPolicy.allowed }),
+ useIssueDeletion: () => ({ canDelete: () => deletionPolicy.allowed, offersDelete: deletionPolicy.offered }),
}));
vi.mock("@multica/core/hooks", () => ({
@@ -213,6 +213,7 @@ beforeEach(() => {
useAssigneePicksStore.setState({ byScope: {} });
platform.desktop = false;
deletionPolicy.allowed = true;
+ deletionPolicy.offered = true;
mockOpenModal.mockReset();
openInNewTabMock.mockReset();
openInDesktopMock.mockReset();
@@ -391,6 +392,15 @@ describe("IssueActionsDropdown", () => {
expect(mockOpenModal).not.toHaveBeenCalled();
});
+ it("leaves Delete issue out for a viewer who can delete nothing (a guest)", async () => {
+ deletionPolicy.allowed = false;
+ deletionPolicy.offered = false;
+ render(wrap(<IssueActionsDropdown issue={mockIssue} trigger={<button data-testid="trigger">Menu</button>} />));
+ fireEvent.click(screen.getByTestId("trigger"));
+ expect(await screen.findByText("Copy link")).toBeInTheDocument();
+ expect(screen.queryByText("Delete issue")).not.toBeInTheDocument();
+ });
+
it("clicking Delete issue opens the delete-confirm modal", async () => {
render(
wrap(
diff --git a/packages/views/issues/actions/issue-actions-menu-items.tsx b/packages/views/issues/actions/issue-actions-menu-items.tsx
index 88c3a5cf75..0b60112ad4 100644
--- a/packages/views/issues/actions/issue-actions-menu-items.tsx
+++ b/packages/views/issues/actions/issue-actions-menu-items.tsx
@@ -107,7 +107,7 @@ export function IssueActionsMenuItems({
const locale = useLocale();
const formatDate = (date: string) => formatDateOnly(date, { month: "short", day: "numeric" }, locale);
const wsId = useWorkspaceId();
- const { canDelete } = useIssueDeletion(wsId);
+ const { canDelete, offersDelete } = useIssueDeletion(wsId);
const sidebar = variant === "sidebar";
const statusLabel = useStatusLabel(wsId);
// Only the statuses the issue's workflow allows; entering a step that hands
@@ -507,17 +507,21 @@ export function IssueActionsMenuItems({
person chose it, never on the plugin's own initiative. */}
<PluginModalMenuItems issueId={issue.id} Item={P.Item} />
- <P.Separator />
+ {offersDelete && (
+ <>
+ <P.Separator />
- <P.Item
- disabled={!canDelete(issue)}
- title={!canDelete(issue) ? t(($) => $.batch.delete_restricted) : undefined}
- variant="destructive"
- onClick={() => openDeleteConfirm({ onDeletedFallbackPath })}
- >
- <Trash2 className="h-3.5 w-3.5" />
- {t(($) => $.actions.delete_issue)}
- </P.Item>
+ <P.Item
+ disabled={!canDelete(issue)}
+ title={!canDelete(issue) ? t(($) => $.batch.delete_restricted) : undefined}
+ variant="destructive"
+ onClick={() => openDeleteConfirm({ onDeletedFallbackPath })}
+ >
+ <Trash2 className="h-3.5 w-3.5" />
+ {t(($) => $.actions.delete_issue)}
+ </P.Item>
+ </>
+ )}
</>
)}
</>
diff --git a/packages/views/issues/components/batch-action-toolbar.confirm.test.tsx b/packages/views/issues/components/batch-action-toolbar.confirm.test.tsx
index bdc9ac6897..d09847c861 100644
--- a/packages/views/issues/components/batch-action-toolbar.confirm.test.tsx
+++ b/packages/views/issues/components/batch-action-toolbar.confirm.test.tsx
@@ -16,7 +16,7 @@ const selection = vi.hoisted(() => ({
}));
const deletionPolicy = vi.hoisted(() => ({ allowed: true }));
vi.mock("@multica/core/issues/use-issue-deletion", () => ({
- useIssueDeletion: () => ({ canDelete: () => deletionPolicy.allowed }),
+ useIssueDeletion: () => ({ canDelete: () => deletionPolicy.allowed, offersDelete: true }),
}));
vi.mock("@multica/core/issues/stores/selection-store", () => ({
diff --git a/packages/views/issues/components/batch-action-toolbar.menu.test.tsx b/packages/views/issues/components/batch-action-toolbar.menu.test.tsx
index 5216985486..8caa9b54dd 100644
--- a/packages/views/issues/components/batch-action-toolbar.menu.test.tsx
+++ b/packages/views/issues/components/batch-action-toolbar.menu.test.tsx
@@ -14,7 +14,7 @@ vi.mock("@multica/core/issues/stores/selection-store", () => ({
useIssueSelectionStore: (selector: (s: typeof selection) => unknown) => selector(selection),
}));
vi.mock("@multica/core/issues/use-issue-deletion", () => ({
- useIssueDeletion: () => ({ canDelete: () => true }),
+ useIssueDeletion: () => ({ canDelete: () => true, offersDelete: true }),
}));
vi.mock("@multica/core/issues/mutations", () => ({
useBatchUpdateIssues: () => ({ mutateAsync: vi.fn(), isPending: false }),
diff --git a/packages/views/issues/components/batch-action-toolbar.properties.test.tsx b/packages/views/issues/components/batch-action-toolbar.properties.test.tsx
index 1d485152bb..b3816a1345 100644
--- a/packages/views/issues/components/batch-action-toolbar.properties.test.tsx
+++ b/packages/views/issues/components/batch-action-toolbar.properties.test.tsx
@@ -14,7 +14,7 @@ vi.mock("@multica/core/issues/stores/selection-store", () => ({
useIssueSelectionStore: (selector: (s: typeof selection) => unknown) => selector(selection),
}));
vi.mock("@multica/core/issues/use-issue-deletion", () => ({
- useIssueDeletion: () => ({ canDelete: () => true }),
+ useIssueDeletion: () => ({ canDelete: () => true, offersDelete: true }),
}));
vi.mock("@multica/core/issues/mutations", () => ({
useBatchUpdateIssues: () => ({ mutateAsync: batchUpdate, isPending: false }),
diff --git a/packages/views/issues/components/batch-action-toolbar.test.tsx b/packages/views/issues/components/batch-action-toolbar.test.tsx
index 7fcb583104..bce3ff36bf 100644
--- a/packages/views/issues/components/batch-action-toolbar.test.tsx
+++ b/packages/views/issues/components/batch-action-toolbar.test.tsx
@@ -13,7 +13,7 @@ const selection = vi.hoisted(() => ({
const deletionPolicy = vi.hoisted(() => ({ allowed: true }));
vi.mock("@multica/core/issues/use-issue-deletion", () => ({
- useIssueDeletion: () => ({ canDelete: () => deletionPolicy.allowed }),
+ useIssueDeletion: () => ({ canDelete: () => deletionPolicy.allowed, offersDelete: true }),
}));
vi.mock("@multica/core/issues/stores/selection-store", () => ({
diff --git a/packages/views/issues/components/batch-action-toolbar.tsx b/packages/views/issues/components/batch-action-toolbar.tsx
index 32b6daefaa..d8add8ebf9 100644
--- a/packages/views/issues/components/batch-action-toolbar.tsx
+++ b/packages/views/issues/components/batch-action-toolbar.tsx
@@ -117,7 +117,7 @@ export function BatchActionToolbar({
return first && selectedIssues.every((i) => i.project_id === first) ? first : null;
}, [selectedIssues]);
const wsId = useWorkspaceId();
- const { canDelete } = useIssueDeletion(wsId);
+ const { canDelete, offersDelete } = useIssueDeletion(wsId);
const canDeleteSelection = selectedIssues.every(canDelete);
const { workflows } = useIssueWorkflows(wsId);
const { data: projects } = useQuery({ ...projectListOptions(wsId), enabled: count > 0 && !sharedProjectId });
@@ -291,6 +291,7 @@ export function BatchActionToolbar({
projectId: sharedProjectId,
allowedStatuses,
disabled: loading,
+ offersDelete,
canDelete: canDeleteSelection,
onStatus: (status: string) => handleBatchStatus({ status }),
onAssignee: handleBatchAssignee,
diff --git a/packages/views/issues/components/batch-menu-items.test.tsx b/packages/views/issues/components/batch-menu-items.test.tsx
index 7ba3ba2850..aef962fbb2 100644
--- a/packages/views/issues/components/batch-menu-items.test.tsx
+++ b/packages/views/issues/components/batch-menu-items.test.tsx
@@ -28,7 +28,7 @@ function issue(id: string, notes?: string): Issue {
return { id, identifier: id, properties: notes === undefined ? {} : { notes } } as Issue;
}
-function renderMenu(issues: Issue[]) {
+function renderMenu(issues: Issue[], { offersDelete = true } = {}) {
const onProperties = vi.fn();
const onEditor = vi.fn();
renderWithI18n(
@@ -42,6 +42,7 @@ function renderMenu(issues: Issue[]) {
projectId={null}
allowedStatuses={null}
disabled={false}
+ offersDelete={offersDelete}
canDelete
onStatus={vi.fn()}
onAssignee={vi.fn()}
@@ -82,3 +83,16 @@ describe("BatchMenuItems custom properties", () => {
expect(screen.queryByRole("menuitem", { name: /Clear/ })).not.toBeInTheDocument();
});
});
+
+describe("BatchMenuItems delete", () => {
+ it("offers delete to a viewer who may delete issues", () => {
+ renderMenu([issue("a"), issue("b")]);
+ expect(screen.getByRole("menuitem", { name: "Delete 2 issues" })).toBeInTheDocument();
+ });
+
+ it("leaves delete out for a viewer who can delete nothing (a guest)", () => {
+ renderMenu([issue("a"), issue("b")], { offersDelete: false });
+ expect(screen.getByRole("menuitem", { name: "Copy links" })).toBeInTheDocument();
+ expect(screen.queryByRole("menuitem", { name: /Delete/ })).not.toBeInTheDocument();
+ });
+});
diff --git a/packages/views/issues/components/batch-menu-items.tsx b/packages/views/issues/components/batch-menu-items.tsx
index 71d3dac4a0..ee9c6c85c5 100644
--- a/packages/views/issues/components/batch-menu-items.tsx
+++ b/packages/views/issues/components/batch-menu-items.tsx
@@ -77,6 +77,8 @@ interface BatchMenuItemsProps {
projectId: string | null;
allowedStatuses: ReadonlySet<string> | null;
disabled: boolean;
+ /** False for a viewer who can delete no issue at all (a guest): the entry is left out. */
+ offersDelete: boolean;
canDelete: boolean;
onStatus: (status: string) => void;
onAssignee: (updates: Partial<UpdateIssueRequest>) => void;
@@ -98,6 +100,7 @@ export function BatchMenuItems({
projectId,
allowedStatuses,
disabled,
+ offersDelete,
canDelete,
onStatus,
onAssignee,
@@ -299,16 +302,20 @@ export function BatchMenuItems({
{tLayout(($) => $.collection.clear_selection)}
</P.Item>
)}
- <P.Separator />
- <P.Item
- variant="destructive"
- disabled={disabled || !canDelete}
- title={!canDelete ? t(($) => $.batch.delete_restricted) : undefined}
- onClick={onDelete}
- >
- <Trash2 className="h-3.5 w-3.5" />
- {t(($) => $.batch.delete_count, { count })}
- </P.Item>
+ {offersDelete && (
+ <>
+ <P.Separator />
+ <P.Item
+ variant="destructive"
+ disabled={disabled || !canDelete}
+ title={!canDelete ? t(($) => $.batch.delete_restricted) : undefined}
+ onClick={onDelete}
+ >
+ <Trash2 className="h-3.5 w-3.5" />
+ {t(($) => $.batch.delete_count, { count })}
+ </P.Item>
+ </>
+ )}
</>
);
}
diff --git a/packages/views/issues/components/pickers/assignee-picker.hidden.test.tsx b/packages/views/issues/components/pickers/assignee-picker.hidden.test.tsx
index db28deaed7..2b9a6d8a2e 100644
--- a/packages/views/issues/components/pickers/assignee-picker.hidden.test.tsx
+++ b/packages/views/issues/components/pickers/assignee-picker.hidden.test.tsx
@@ -1,13 +1,14 @@
// The assignee picker lists only actors the current user can actually pick:
// agents they may invoke that have a runtime, and squads whose leader is one.
-import { describe, expect, it, vi } from "vitest";
+import { afterEach, describe, expect, it, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { I18nProvider } from "@multica/core/i18n/react";
import enIssues from "../../../locales/en/issues.json";
import { useAssigneePicksStore } from "@multica/core/issues/stores/assignee-picks-store";
-import { AssigneePicker } from "./assignee-picker";
+import { AssigneePicker, canAssignAgent } from "./assignee-picker";
const MEMBERS = [{ user_id: "user-1", name: "Ada Lovelace", role: "member" }];
+const MEMBER_GRANT = [{ target_type: "member", target_id: "user-1" }];
const WORKSPACE_GRANT = [{ target_type: "workspace", target_id: "workspace-1" }];
const AGENTS = [
// Workspace-shared, has a runtime: pickable.
@@ -16,6 +17,8 @@ const AGENTS = [
{ id: "agent-mine", name: "Mine", owner_id: "user-1", permission_mode: "private", invocation_targets: [], runtime_id: "rt-1", archived_at: null, visibility: "private" },
// Someone else's private agent: hidden.
{ id: "agent-theirs", name: "Theirs", owner_id: "user-2", permission_mode: "private", invocation_targets: [], runtime_id: "rt-1", archived_at: null, visibility: "private" },
+ // Granted to this user alone: pickable.
+ { id: "agent-granted", name: "Granted", owner_id: "user-2", permission_mode: "public_to", invocation_targets: MEMBER_GRANT, runtime_id: "rt-1", archived_at: null, visibility: "private" },
// Shared but no runtime: hidden.
{ id: "agent-unbound", name: "Unbound", owner_id: "user-2", permission_mode: "public_to", invocation_targets: WORKSPACE_GRANT, runtime_id: null, archived_at: null, visibility: "workspace" },
];
@@ -76,23 +79,31 @@ function rowsIn(label: string): string[] {
);
}
+function renderPicker() {
+ render(
+ <I18nProvider locale="en" resources={{ en: { issues: enIssues } }}>
+ <AssigneePicker
+ assigneeType={null}
+ assigneeId={null}
+ onUpdate={() => {}}
+ open
+ onOpenChange={() => {}}
+ />
+ </I18nProvider>,
+ );
+}
+
describe("AssigneePicker unpickable actors", () => {
+ afterEach(() => {
+ MEMBERS[0]!.role = "member";
+ });
+
it("hides agents and squads the user cannot assign, including from Recent", async () => {
useAssigneePicksStore.setState({ byScope: { "user-1:workspace-1": PICKS } });
- render(
- <I18nProvider locale="en" resources={{ en: { issues: enIssues } }}>
- <AssigneePicker
- assigneeType={null}
- assigneeId={null}
- onUpdate={() => {}}
- open
- onOpenChange={() => {}}
- />
- </I18nProvider>,
- );
+ renderPicker();
await screen.findByText("Agents");
- expect(rowsIn("Agents")).toEqual(["Shared", "Mine"]);
+ expect(rowsIn("Agents")).toEqual(["Shared", "Mine", "Granted"]);
expect(rowsIn("Squads")).toEqual(["Runnable Squad"]);
expect(rowsIn("Recent")).toEqual(["Shared"]);
expect(screen.queryByText("Theirs")).toBeNull();
@@ -100,4 +111,19 @@ describe("AssigneePicker unpickable actors", () => {
expect(screen.queryByText("Stuck Squad")).toBeNull();
expect(screen.queryByText("Private Squad")).toBeNull();
});
+
+ it("offers a guest no agent or squad, not even one it owns or was granted (MUL-9877)", async () => {
+ MEMBERS[0]!.role = "guest";
+ useAssigneePicksStore.setState({ byScope: { "user-1:workspace-1": PICKS } });
+ renderPicker();
+
+ await screen.findByText("Ada Lovelace");
+ for (const name of ["Shared", "Mine", "Granted", "Runnable Squad"]) {
+ expect(screen.queryByText(name)).toBeNull();
+ }
+ for (const agent of AGENTS) {
+ expect(canAssignAgent(agent as never, "user-1", "guest")).toBe(false);
+ }
+ expect(canAssignAgent(AGENTS[1] as never, "user-1", "member")).toBe(true);
+ });
});
diff --git a/packages/views/issues/components/pickers/assignee-picker.tsx b/packages/views/issues/components/pickers/assignee-picker.tsx
index d58c059b4d..f51a1e5fe5 100644
--- a/packages/views/issues/components/pickers/assignee-picker.tsx
+++ b/packages/views/issues/components/pickers/assignee-picker.tsx
@@ -2,7 +2,7 @@
import { useMemo, useState } from "react";
import { Lock, UserMinus } from "@multica/ui/icons";
-import type { Agent, IssueAssigneeType, MemberWithUser, Squad, UpdateIssueRequest } from "@multica/core/types";
+import type { Agent, IssueAssigneeType, MemberRole, MemberWithUser, Squad, UpdateIssueRequest } from "@multica/core/types";
import { useQuery } from "@tanstack/react-query";
import { useAuthStore } from "@multica/core/auth";
import { isAgentRuntimeBound } from "@multica/core/agents";
@@ -36,12 +36,16 @@ export function canAssignAgent(
): boolean {
return canAssignAgentToIssue(agent, {
userId: userId ?? null,
- role: memberRole === "owner" || memberRole === "admin" || memberRole === "member"
- ? memberRole
- : null,
+ role: toMemberRole(memberRole),
}).allowed;
}
+// Keeps "guest": the rules refuse a guest outright, while an unknown role
+// would fall through to the owner and member-grant checks.
+function toMemberRole(role: string | undefined): MemberRole | null {
+ return role === "owner" || role === "admin" || role === "member" || role === "guest" ? role : null;
+}
+
interface AssigneePickerProps {
assigneeType: IssueAssigneeType | null;
assigneeId: string | null;
@@ -245,10 +249,7 @@ function useAssigneeChoices(filter: string) {
// have a runtime, and squads whose leader is such an agent (the server
// checks the leader's invoke permission). Anything else would be a row
// that can't be clicked, or a pick the server rejects.
- const role =
- memberRole === "owner" || memberRole === "admin" || memberRole === "member"
- ? memberRole
- : null;
+ const role = toMemberRole(memberRole);
const assignableAgents = agents.filter(
(a) =>
!a.archived_at &&
diff --git a/packages/views/search/commands/issue-commands.tsx b/packages/views/search/commands/issue-commands.tsx
index c7441eb584..11aecff460 100644
--- a/packages/views/search/commands/issue-commands.tsx
+++ b/packages/views/search/commands/issue-commands.tsx
@@ -34,6 +34,7 @@ import {
issueTimelineOptions,
} from "@multica/core/issues/queries";
import { useRetryIssueRun, useToggleIssueSubscriber } from "@multica/core/issues/mutations";
+import { useIssueDeletion } from "@multica/core/issues/use-issue-deletion";
import { useCommentCollapseStore, useResolvedExpandStore } from "@multica/core/issues/stores";
import { quickActionListOptions } from "@multica/core/quick-actions";
import type { AgentTask, Issue } from "@multica/core/types";
@@ -85,6 +86,8 @@ export function useIssueCommandGroup(
});
const toggleSubscriber = useToggleIssueSubscriber(singleId);
const retryRun = useRetryIssueRun(singleId);
+ const { canDelete } = useIssueDeletion(wsId);
+ const deletable = !!target && (target.kind === "single" ? canDelete(target.issue) : target.issues.every(canDelete));
return useMemo(() => {
if (!target) return null;
@@ -310,26 +313,28 @@ export function useIssueCommandGroup(
.catch(() => {});
},
},
- {
+ );
+ if (deletable) {
+ commands.push({
id: "issue-delete",
label: t(($) => $.issue.delete),
icon: Trash2,
keywords: ["delete", "remove", "删除"],
destructive: true,
run: () => actions.openDeleteConfirm({ onDeletedFallbackPath }),
- },
- );
+ });
+ }
} else if (target.kind === "batch") {
- commands.push(
- {
- id: "issue-parent",
- label: t(($) => $.issue.set_parent),
- icon: Network,
- keywords: ["parent", "sub", "父任务"],
- page: { type: "issue-parent", target },
- crumb,
- },
- {
+ commands.push({
+ id: "issue-parent",
+ label: t(($) => $.issue.set_parent),
+ icon: Network,
+ keywords: ["parent", "sub", "父任务"],
+ page: { type: "issue-parent", target },
+ crumb,
+ });
+ if (deletable) {
+ commands.push({
id: "issue-delete",
label: t(($) => $.issue.delete_selected, { count: target.issues.length }),
icon: Trash2,
@@ -341,8 +346,8 @@ export function useIssueCommandGroup(
issues: target.issues,
clearSelection: target.clearSelection,
}),
- },
- );
+ });
+ }
}
return {
@@ -361,6 +366,7 @@ export function useIssueCommandGroup(
}, [
actions,
activeQuickActions.length,
+ deletable,
onDeletedFallbackPath,
palette,
queryClient,
diff --git a/packages/views/search/search-command.test.tsx b/packages/views/search/search-command.test.tsx
index 05cdd84235..a0b96589d3 100644
--- a/packages/views/search/search-command.test.tsx
+++ b/packages/views/search/search-command.test.tsx
@@ -1169,6 +1169,34 @@ describe("SearchCommand", () => {
);
});
+ it("offers Delete issue on an issue the viewer created", async () => {
+ const user = userEvent.setup();
+ renderSearch();
+ await user.type(input(), "delete");
+ await waitFor(() => expect(renderedValues()).toContain("command:context-issue:issue-delete"));
+ });
+
+ it("drops Delete issue on someone else's issue", async () => {
+ act(() => {
+ for (const token of registered.splice(0)) useCommandBarContextStore.getState().unregister(token);
+ });
+ registerContext({ kind: "issue", issue: { ...issue, creator_id: "user-other" } });
+ const user = userEvent.setup();
+ renderSearch();
+ await user.type(input(), "delete");
+
+ expect(renderedValues()).not.toContain("command:context-issue:issue-delete");
+ });
+
+ it("drops Delete issue for a guest, even on an issue it created (MUL-9877)", async () => {
+ seed(memberListOptions("ws-test"), [{ ...makeMember(ME, "Me Myself", "[email protected]"), role: "guest" }]);
+ const user = userEvent.setup();
+ renderSearch();
+ await user.type(input(), "delete");
+
+ expect(renderedValues()).not.toContain("command:context-issue:issue-delete");
+ });
+
it("hides issue commands once the page unregisters", () => {
act(() => {
for (const token of registered.splice(0)) useCommandBarContextStore.getState().unregister(token);
diff --git a/packages/views/skills/hooks/use-can-edit-skill.ts b/packages/views/skills/hooks/use-can-edit-skill.ts
index 5dcb7cad4a..0abfc79e26 100644
--- a/packages/views/skills/hooks/use-can-edit-skill.ts
+++ b/packages/views/skills/hooks/use-can-edit-skill.ts
@@ -37,6 +37,7 @@ export function canEditSkill(
skill: SkillSummary,
opts: { userId: string | null; role: MemberRole | null },
): boolean {
+ if (opts.role === "guest") return false;
if (opts.role === "admin" || opts.role === "owner") return true;
return skill.created_by === opts.userId;
}