Skip to content

Commit ab766f5

Browse files
committed
fix(files): distinguish non-member from read-only in workspace-save skip log
Splits the workspace-save skip branch so non-members (permission === null) log 'user is not a workspace member' instead of the misleading 'lacks write permission'. Adds a test covering the null case so the relaxed behavior (vs. the prior route's hard 'File not found') is explicit.
1 parent 13cf392 commit ab766f5

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

apps/sim/lib/uploads/contexts/workspace/fetch-external-url.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,23 @@ describe('fetchExternalUrlToWorkspace', () => {
148148
expect(mockUploadWorkspaceFile).not.toHaveBeenCalled()
149149
})
150150

151+
it('returns parsed bytes but skips save when user is not a workspace member', async () => {
152+
inputValidationMockFns.mockSecureFetchWithPinnedIP.mockResolvedValue(
153+
makeResponse('bytes', 'text/plain')
154+
)
155+
permissionsMockFns.mockGetUserEntityPermissions.mockResolvedValue(null)
156+
157+
const result = await fetchExternalUrlToWorkspace({
158+
url: 'https://example.com/file.txt',
159+
userId: 'user-1',
160+
workspaceId: 'workspace-1',
161+
})
162+
163+
expect(result.buffer.toString()).toBe('bytes')
164+
expect(result.savedWorkspaceFile).toBeUndefined()
165+
expect(mockUploadWorkspaceFile).not.toHaveBeenCalled()
166+
})
167+
151168
it('returns the saved workspace file when permission allows save', async () => {
152169
inputValidationMockFns.mockSecureFetchWithPinnedIP.mockResolvedValue(
153170
makeResponse('bytes', 'text/plain')

apps/sim/lib/uploads/contexts/workspace/fetch-external-url.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ export async function fetchExternalUrlToWorkspace(
137137
saveError,
138138
})
139139
}
140+
} else if (permission === null) {
141+
logger.warn('Skipping workspace save: user is not a workspace member', {
142+
userId,
143+
workspaceId,
144+
})
140145
} else {
141146
logger.warn('Skipping workspace save: user lacks write permission', {
142147
userId,

0 commit comments

Comments
 (0)