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

Function authorizeCopilotChatRow

apps/sim/lib/copilot/chat/lifecycle.ts:116–153  ·  view source on GitHub ↗
(
  chat: T | undefined,
  chatId: string,
  userId: string
)

Source from the content-addressed store, hash-verified

114 Pick<typeof copilotChats.$inferSelect, 'model' | 'planArtifact' | 'config'>
115
116async function authorizeCopilotChatRow<T extends CopilotChatAuthRow>(
117 chat: T | undefined,
118 chatId: string,
119 userId: string
120): Promise<T | null> {
121 if (!chat) {
122 logger.warn('Copilot chat not found or not owned by user', { chatId, userId })
123 return null
124 }
125
126 if (chat.workflowId) {
127 const authorization = await authorizeWorkflowByWorkspacePermission({
128 workflowId: chat.workflowId,
129 userId,
130 action: 'read',
131 })
132 if (!authorization.allowed || !authorization.workflow) {
133 logger.warn('Copilot chat workflow not authorized for user', {
134 chatId,
135 userId,
136 workflowId: chat.workflowId,
137 })
138 return null
139 }
140 } else if (chat.workspaceId) {
141 const access = await checkWorkspaceAccess(chat.workspaceId, userId)
142 if (!access.exists || !access.hasAccess) {
143 logger.warn('Copilot chat workspace not accessible to user', {
144 chatId,
145 userId,
146 workspaceId: chat.workspaceId,
147 })
148 return null
149 }
150 }
151
152 return chat
153}
154
155/**
156 * Verify a copilot chat exists, is owned by the user, and the user has access

Calls 3

checkWorkspaceAccessFunction · 0.90
warnMethod · 0.65

Tested by

no test coverage detected