mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
fix(mothership): scope mothership block tool permissions to the executing user (#4843)
This commit is contained in:
@@ -222,4 +222,37 @@ describe('runCopilotLifecycle', () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('propagates payload userPermission into the generated execution context', async () => {
|
||||
let capturedExecContext: ExecutionContext | undefined
|
||||
mockGetEffectiveDecryptedEnv.mockResolvedValueOnce({})
|
||||
mockRunStreamLoop.mockImplementationOnce(
|
||||
async (
|
||||
_fetchUrl: string,
|
||||
_fetchOptions: RequestInit,
|
||||
_context: StreamingContext,
|
||||
execContext: ExecutionContext
|
||||
): Promise<void> => {
|
||||
capturedExecContext = execContext
|
||||
}
|
||||
)
|
||||
|
||||
await runCopilotLifecycle(
|
||||
{ message: 'hello', messageId: 'stream-1', userPermission: 'write' },
|
||||
{
|
||||
userId: 'user-1',
|
||||
workspaceId: 'ws-1',
|
||||
chatId: 'chat-1',
|
||||
}
|
||||
)
|
||||
|
||||
expect(capturedExecContext).toEqual(
|
||||
expect.objectContaining({
|
||||
userId: 'user-1',
|
||||
workspaceId: 'ws-1',
|
||||
chatId: 'chat-1',
|
||||
userPermission: 'write',
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -472,6 +472,8 @@ async function buildExecutionContext(
|
||||
const userTimezone =
|
||||
typeof requestPayload?.userTimezone === 'string' ? requestPayload.userTimezone : undefined
|
||||
const requestMode = typeof requestPayload?.mode === 'string' ? requestPayload.mode : undefined
|
||||
const userPermission =
|
||||
typeof requestPayload?.userPermission === 'string' ? requestPayload.userPermission : undefined
|
||||
|
||||
let execContext: ExecutionContext
|
||||
if (workflowId) {
|
||||
@@ -490,6 +492,7 @@ async function buildExecutionContext(
|
||||
if (userTimezone) execContext.userTimezone = userTimezone
|
||||
execContext.copilotToolExecution = true
|
||||
if (requestMode) execContext.requestMode = requestMode
|
||||
if (userPermission) execContext.userPermission = userPermission
|
||||
execContext.messageId =
|
||||
typeof requestPayload?.messageId === 'string' ? requestPayload.messageId : undefined
|
||||
execContext.executionId = executionId
|
||||
|
||||
Reference in New Issue
Block a user