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

Function checkChatAccess

apps/sim/app/api/chat/utils.ts:109–141  ·  view source on GitHub ↗
(
  chatId: string,
  userId: string
)

Source from the content-addressed store, hash-verified

107 * Check if user has access to view/edit/delete a specific chat
108 */
109export async function checkChatAccess(
110 chatId: string,
111 userId: string
112): Promise<{ hasAccess: boolean; chat?: any; workspaceId?: string }> {
113 const chatData = await db
114 .select({
115 chat: chat,
116 workflowWorkspaceId: workflow.workspaceId,
117 })
118 .from(chat)
119 .innerJoin(workflow, eq(chat.workflowId, workflow.id))
120 .where(and(eq(chat.id, chatId), isNull(chat.archivedAt)))
121 .limit(1)
122
123 if (chatData.length === 0) {
124 return { hasAccess: false }
125 }
126
127 const { chat: chatRecord, workflowWorkspaceId } = chatData[0]
128 if (!workflowWorkspaceId) {
129 return { hasAccess: false }
130 }
131
132 const authorization = await authorizeWorkflowByWorkspacePermission({
133 workflowId: chatRecord.workflowId,
134 userId,
135 action: 'admin',
136 })
137
138 return authorization.allowed
139 ? { hasAccess: true, chat: chatRecord, workspaceId: workflowWorkspaceId }
140 : { hasAccess: false }
141}
142
143/**
144 * Validates auth for a deployed chat. Thin wrapper over the shared

Callers 2

executeDeployChatFunction · 0.90
route.tsFile · 0.90

Calls 2

eqFunction · 0.50

Tested by

no test coverage detected