From 97d74e84befe96a8fd5d2609e9fca9152afc7124 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 7 Aug 2026 18:03:38 -0400 Subject: [PATCH] fix: Missing ip on events created during account provisioning (#13334) --- server/commands/accountProvisioner.test.ts | 37 +++++++++++++++++++++- server/commands/accountProvisioner.ts | 5 +-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/server/commands/accountProvisioner.test.ts b/server/commands/accountProvisioner.test.ts index d9fc58f410..dc135c850b 100644 --- a/server/commands/accountProvisioner.test.ts +++ b/server/commands/accountProvisioner.test.ts @@ -1,7 +1,7 @@ import { faker } from "@faker-js/faker"; import { randomUUID } from "node:crypto"; import { errToString } from "@shared/utils/error"; -import { TeamDomain } from "@server/models"; +import { Event, TeamDomain } from "@server/models"; import Collection from "@server/models/Collection"; import UserAuthentication from "@server/models/UserAuthentication"; import { buildUser, buildTeam, buildAdmin } from "@server/test/factories"; @@ -57,6 +57,41 @@ describe("accountProvisioner", () => { expect(collectionCount).toEqual(1); }); + it("should record the request ip on onboarding events", async () => { + const { team } = await accountProvisioner(ctx, { + user: { + name: "Jenny Tester", + email: faker.internet.email(), + avatarUrl: faker.image.avatar(), + }, + team: { + name: "New workspace", + avatarUrl: faker.image.avatar(), + subdomain: faker.internet.domainWord(), + }, + authenticationProvider: { + name: "google", + providerId: faker.internet.domainName(), + }, + authentication: { + providerId: randomUUID(), + accessToken: "123", + scopes: ["read"], + }, + }); + + const events = await Event.findAll({ + where: { + teamId: team.id, + name: ["collections.create", "documents.create"], + }, + }); + expect(events.length).toBeGreaterThan(0); + events.forEach((event) => { + expect(event.ip).toEqual(ip); + }); + }); + it("should update existing user and authentication", async () => { const existingTeam = await buildTeam(); const providers = await existingTeam.$get("authenticationProviders"); diff --git a/server/commands/accountProvisioner.ts b/server/commands/accountProvisioner.ts index 55671e7e6e..80db75d6e2 100644 --- a/server/commands/accountProvisioner.ts +++ b/server/commands/accountProvisioner.ts @@ -285,9 +285,10 @@ async function provisionFirstCollection( ) { await sequelize.transaction(async (transaction) => { const context = createContext({ - ...ctx, - transaction, user, + authType: ctx.context.auth?.type, + ip: ctx.context.ip, + transaction, }); const collection = await Collection.createWithCtx(context, {