⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
fix(api): suggest only people the team takes an invite for (#720)
Croff051fcd06ddd4
diff --git a/apps/api/AGENTS.md b/apps/api/AGENTS.mdindex b4132cd4..e34c3d57 100644--- a/apps/api/AGENTS.md+++ b/apps/api/AGENTS.md@@ -181,6 +181,7 @@ Enforced declaratively through macros, never imperative calls in handlers.(`invites/email-policy.ts`, 400 `EMAIL_DOMAIN_NOT_ALLOWED`): by default, one with anaccount always and one without only if it could register. A build that lets aworkspace keep domains of its own calls `setInviteEmailPolicy` with a check against them.+ The invite dialog's suggestions (`.../invites/candidates`) leave out whom it refuses.`members/` removes (last owner protected).- The member list of a project is governed by its role matrix **or** by the team thatowns it: `memberAdmin: ["members_manage", "<action>"]` passes an owner or manager ofdiff --git a/apps/api/src/modules/invites/__tests__/integration/invite-candidates.test.ts b/apps/api/src/modules/invites/__tests__/integration/invite-candidates.test.tsindex 36f682a1..9d3f5ca0 100644--- a/apps/api/src/modules/invites/__tests__/integration/invite-candidates.test.ts+++ b/apps/api/src/modules/invites/__tests__/integration/invite-candidates.test.ts@@ -1,4 +1,5 @@-import { describe, it, expect, beforeEach } from 'bun:test';+import { describe, it, expect, beforeEach, afterEach } from 'bun:test';+import { setInviteEmailPolicy } from '#modules/invites/email-policy';import { authedApi, createProject, type Api } from '#tests/helpers/app';import { createAgent } from '#tests/helpers/agents';import { signUpTestUser } from '#tests/helpers/auth';@@ -41,6 +42,10 @@ describe('invite candidates — GET /teams/:teamId/invites/candidates', () => {await resetDb();});+ afterEach(() => {+ setInviteEmailPolicy();+ });+it('is refused while the instance has the search off, which is the default', async () => {const owner = await setupOwner(false);await signUpTestUser({ name: 'Nina New', email: '[email protected]' });@@ -87,6 +92,18 @@ describe('invite candidates — GET /teams/:teamId/invites/candidates', () => {expect(emails((await search(owner.api, owner.teamId, 'olivia')).data)).toEqual([]);});+ it('leaves out the people the invite policy refuses', async () => {+ const owner = await setupOwner();+ for (let i = 1; i <= 9; i++) {+ await signUpTestUser({ name: `Crowd ${i}`, email: `crowd-${i}@outside.test` });+ }+ await signUpTestUser({ name: 'Crowd Inside', email: '[email protected]' });+ setInviteEmailPolicy(async (_teamId, email) => email.endsWith('@inside.test'));++ const res = await search(owner.api, owner.teamId, 'crowd');+ expect(emails(res.data)).toEqual(['[email protected]']);+ });+it('answers with at most 8 people', async () => {const owner = await setupOwner();for (let i = 1; i <= 9; i++) {diff --git a/apps/api/src/modules/invites/service.ts b/apps/api/src/modules/invites/service.tsindex 343513bc..de7140cb 100644--- a/apps/api/src/modules/invites/service.ts+++ b/apps/api/src/modules/invites/service.ts@@ -351,14 +351,18 @@ export async function listTeamInvites(teamId: number, issuerId: string): Promise}const INVITE_CANDIDATE_LIMIT = 8;+// The matches read to find them, since the invite policy may refuse some: a search whose+// first matches it mostly refuses suggests fewer.+const INVITE_CANDIDATE_SCAN = 40;-// The whole instance is searched: an invitee is not in the team yet.+// The whole instance is searched: an invitee is not in the team yet. Only people the team+// would take an invite for are suggested.export async function listInviteCandidates(teamId: number, search: string) {if (!(await getAuthSettings()).inviteSearch) {throw new HttpError(403, 'Searching people is turned off on this instance');}const pattern = likePattern(search);- return db+ const matches = await db.select({ userId: user.id, name: user.name, email: user.email, image: user.image }).from(user).where(@@ -379,7 +383,13 @@ export async function listInviteCandidates(teamId: number, search: string) {),).orderBy(asc(user.name), asc(user.email))- .limit(INVITE_CANDIDATE_LIMIT);+ .limit(INVITE_CANDIDATE_SCAN);+ const candidates: typeof matches = [];+ for (const match of matches) {+ if (candidates.length === INVITE_CANDIDATE_LIMIT) break;+ if (await isInviteEmailAllowed(teamId, match.email, true)) candidates.push(match);+ }+ return candidates;}// Removes an invite of the given project. Returns true when one existed. Used to