Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
fix(invitation): record acceptance in invited workspace (#2663)
Ephraim Duncan56811f46eaf2
diff --git a/packages/services/src/invitation/__tests__/invitation.test.ts b/packages/services/src/invitation/__tests__/invitation.test.tsindex 5d6f4a8a6..75d4cc64f 100644--- a/packages/services/src/invitation/__tests__/invitation.test.ts+++ b/packages/services/src/invitation/__tests__/invitation.test.ts@@ -9,6 +9,7 @@ import {expectAuditRow,makeApiKeyCtx,makeUserCtx,+ readAuditLog,withTestTransaction,} from "../../../test/helpers";import type { ServiceContext } from "../../context";@@ -225,6 +226,37 @@ describe("acceptInvitation", () => {});});+ test("records acceptance only in the invited workspace", async () => {+ await withTestTransaction(async (tx) => {+ const email = `${TEST_PREFIX}-audit-${Date.now()}@example.com`;+ const created = await createInvitation({+ ctx: { ...teamCtx, db: tx },+ input: { email },+ });++ await acceptInvitation({+ ctx: { ...freeCtx, db: tx },+ input: { id: created.id, email },+ });++ await expectAuditRow({+ workspaceId: teamCtx.workspace.id,+ action: "invitation.update",+ entityType: "invitation",+ entityId: created.id,+ actorType: "user",+ db: tx,+ });+ const activeWorkspaceRows = await readAuditLog({+ workspaceId: freeCtx.workspace.id,+ entityType: "invitation",+ entityId: created.id,+ db: tx,+ });+ expect(activeWorkspaceRows).toEqual([]);+ });+ });+test("throws NotFoundError for an unknown or wrong-email invitation", async () => {await withTestTransaction(async (tx) => {await expect(diff --git a/packages/services/src/invitation/accept.ts b/packages/services/src/invitation/accept.tsindex ebb45d105..d8f7c0aad 100644--- a/packages/services/src/invitation/accept.ts+++ b/packages/services/src/invitation/accept.ts@@ -110,18 +110,23 @@ export async function acceptInvitation(args: {if (!existing.workspace) {throw new NotFoundError("workspace", existing.workspaceId);}+ const workspace = selectWorkspaceSchema.parse(existing.workspace);// Strip `token` (email-link capability) from the snapshot; construct the snapshots from the pre-fetched row// to avoid a second SELECT after the UPDATE.const { token: _token, ...before } = existing;- await emitAudit(tx, ctx, {- action: "invitation.update",- entityType: "invitation",- entityId: input.id,- before,- after: { ...before, acceptedAt },- });+ await emitAudit(+ tx,+ { ...ctx, workspace },+ {+ action: "invitation.update",+ entityType: "invitation",+ entityId: input.id,+ before,+ after: { ...before, acceptedAt },+ },+ );- return selectWorkspaceSchema.parse(existing.workspace);+ return workspace;});}