MCPcopy Index your code
hub / github.com/simstudioai/sim / resolveUserId

Function resolveUserId

apps/sim/lib/mothership/inbox/executor.ts:329–348  ·  view source on GitHub ↗

* Resolve which user ID to use for execution. * Match sender email to a workspace member, fallback to workspace owner.

(
  senderEmail: string,
  ws: { id: string; ownerId: string }
)

Source from the content-addressed store, hash-verified

327 * Match sender email to a workspace member, fallback to workspace owner.
328 */
329async function resolveUserId(
330 senderEmail: string,
331 ws: { id: string; ownerId: string }
332): Promise<string> {
333 const [matchedUser] = await db
334 .select({ id: user.id })
335 .from(user)
336 .where(sql`lower(${user.email}) = ${senderEmail.toLowerCase()}`)
337 .orderBy(user.createdAt)
338 .limit(1)
339
340 if (matchedUser) {
341 const permission = await getUserEntityPermissions(matchedUser.id, 'workspace', ws.id)
342 if (permission !== null) {
343 return matchedUser.id
344 }
345 }
346
347 return ws.ownerId
348}
349
350/**
351 * Persist the user message and assistant response to the copilot chat.

Callers 1

executeInboxTaskFunction · 0.70

Calls 1

getUserEntityPermissionsFunction · 0.90

Tested by

no test coverage detected