⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(api): clear project limits for new owners
Andrejb38c7d5de5f4
diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.tsindex 6ed1035dd..55e9b1c5e 100644--- a/apps/api/src/auth.ts+++ b/apps/api/src/auth.ts@@ -48,6 +48,7 @@ import { publishEvent } from "./events";import { applyInvitationProjectAccess } from "./project-access/apply-invitation-project-access";import { resolveInvitationProjectAccess } from "./project-access/resolve-invitation-project-access";import { clearMemberProjectAccess } from "./project-access/clear-member-project-access";+import { isOwnerRole } from "./project-access/is-owner-role";import clearEmailVerificationOnAdminChange from "./user/controllers/clear-email-verification-on-admin-change";import deleteAccountData from "./user/controllers/delete-account-data";import prepareAdminUserRemoval from "./user/controllers/prepare-admin-user-removal";@@ -563,6 +564,19 @@ export const auth = betterAuth({beforeAcceptInvitation: async ({ invitation, user }) => {await applyInvitationProjectAccess(invitation, user.id);},+ afterUpdateMemberRole: async ({ member }) => {+ if (!isOwnerRole(member.role)) return;+ await clearMemberProjectAccess(member.organizationId, member.userId)+ .then(() =>+ publishEvent("project_access.updated", {+ workspaceId: member.organizationId,+ userId: member.userId,+ }),+ )+ .catch((error) => {+ console.error("Project access cleanup failed:", error);+ });+ },afterAddMember: async ({ member }) => {if (member?.organizationId) {void syncWorkspaceSeats(member.organizationId).catch((error) => {diff --git a/tests/api-integration/project-access-management.test.ts b/tests/api-integration/project-access-management.test.tsindex 807a046a0..aa5ab7894 100644--- a/tests/api-integration/project-access-management.test.ts+++ b/tests/api-integration/project-access-management.test.ts@@ -326,6 +326,50 @@ describe("invitations with project access", () => {);});+ it("clears a member's project limit when they become an owner", async () => {+ const ctx = await createInvitationWorkspace();+ const invited = await ctx.ownerRequest("/auth/organization/invite-member", {+ method: "POST",+ body: {+ organizationId: ctx.workspaceId,+ email: "[email protected]",+ role: "member",+ projectAccess: "selected",+ projectIds: [ctx.alpha.id],+ },+ });+ const invitation = (await invited.json()) as { id: string };+ const invitee = await signUpWithSession(ctx.app, {+ email: "[email protected]",+ name: "Lead",+ });+ await projectAccessApi({ cookie: invitee.cookies })(+ "/auth/organization/accept-invitation",+ { method: "POST", body: { invitationId: invitation.id } },+ );+ const [membership] = await db+ .select({ id: schema.workspaceUserTable.id })+ .from(schema.workspaceUserTable)+ .where(eq(schema.workspaceUserTable.userId, invitee.userId));++ const promoted = await ctx.ownerRequest(+ "/auth/organization/update-member-role",+ {+ method: "POST",+ body: {+ organizationId: ctx.workspaceId,+ memberId: membership?.id,+ role: "owner",+ },+ },+ );++ expect(promoted.status).toBe(200);+ expect(await readMemberAccessRows(ctx.workspaceId, invitee.userId)).toEqual(+ { rules: [], grants: [] },+ );+ });+it("gives every project to an invitation without a selection", async () => {const ctx = await createInvitationWorkspace();