Skip to content

The open-source app everyone uses to manage agents at work

Preserve task assignment grants for joined agents

dotta44fbf8310663
diff --git a/server/src/__tests__/invite-join-grants.test.ts b/server/src/__tests__/invite-join-grants.test.ts
new file mode 100644
index 0000000000..7dd342677f
--- /dev/null
+++ b/server/src/__tests__/invite-join-grants.test.ts
@@ -0,0 +1,57 @@
+import { describe, expect, it } from "vitest";
+import { agentJoinGrantsFromDefaults } from "../routes/access.js";
+
+describe("agentJoinGrantsFromDefaults", () => {
+ it("adds tasks:assign when invite defaults do not specify agent grants", () => {
+ expect(agentJoinGrantsFromDefaults(null)).toEqual([
+ {
+ permissionKey: "tasks:assign",
+ scope: null,
+ },
+ ]);
+ });
+
+ it("preserves invite agent grants and appends tasks:assign", () => {
+ expect(
+ agentJoinGrantsFromDefaults({
+ agent: {
+ grants: [
+ {
+ permissionKey: "agents:create",
+ scope: null,
+ },
+ ],
+ },
+ }),
+ ).toEqual([
+ {
+ permissionKey: "agents:create",
+ scope: null,
+ },
+ {
+ permissionKey: "tasks:assign",
+ scope: null,
+ },
+ ]);
+ });
+
+ it("does not duplicate tasks:assign when invite defaults already include it", () => {
+ expect(
+ agentJoinGrantsFromDefaults({
+ agent: {
+ grants: [
+ {
+ permissionKey: "tasks:assign",
+ scope: { projectId: "project-1" },
+ },
+ ],
+ },
+ }),
+ ).toEqual([
+ {
+ permissionKey: "tasks:assign",
+ scope: { projectId: "project-1" },
+ },
+ ]);
+ });
+});
diff --git a/server/src/routes/access.ts b/server/src/routes/access.ts
index 6d8c5af2c1..7d7dfe2b2b 100644
--- a/server/src/routes/access.ts
+++ b/server/src/routes/access.ts
@@ -1411,6 +1411,25 @@ function grantsFromDefaults(
return result;
}
+export function agentJoinGrantsFromDefaults(
+ defaultsPayload: Record<string, unknown> | null | undefined
+): Array<{
+ permissionKey: (typeof PERMISSION_KEYS)[number];
+ scope: Record<string, unknown> | null;
+}> {
+ const grants = grantsFromDefaults(defaultsPayload, "agent");
+ if (grants.some((grant) => grant.permissionKey === "tasks:assign")) {
+ return grants;
+ }
+ return [
+ ...grants,
+ {
+ permissionKey: "tasks:assign",
+ scope: null
+ }
+ ];
+}
+
type JoinRequestManagerCandidate = {
id: string;
role: string;
@@ -2618,17 +2637,8 @@ export function accessRoutes(
"member",
"active"
);
- await access.setPrincipalPermission(
- companyId,
- "agent",
- created.id,
- "tasks:assign",
- true,
- req.actor.userId ?? null
- );
- const grants = grantsFromDefaults(
- invite.defaultsPayload as Record<string, unknown> | null,
- "agent"
+ const grants = agentJoinGrantsFromDefaults(
+ invite.defaultsPayload as Record<string, unknown> | null
);
await access.setPrincipalGrants(
companyId,