( organizationIds: string[] | undefined, userId: string, )
| 371 | }; |
| 372 | |
| 373 | export const workspacePermissionsByOrganization = ( |
| 374 | organizationIds: string[] | undefined, |
| 375 | userId: string, |
| 376 | ) => { |
| 377 | return { |
| 378 | enabled: Boolean(organizationIds), |
| 379 | queryKey: [ |
| 380 | "workspaces", |
| 381 | [...(organizationIds ?? []).sort()], |
| 382 | "permissions", |
| 383 | ], |
| 384 | queryFn: async () => { |
| 385 | const prefixedChecks = (organizationIds ?? []).flatMap((orgId) => |
| 386 | Object.entries(workspacePermissionChecks(orgId, userId)).map( |
| 387 | ([key, val]) => [`${orgId}.${key}`, val], |
| 388 | ), |
| 389 | ); |
| 390 | |
| 391 | const response = await API.checkAuthorization({ |
| 392 | checks: Object.fromEntries(prefixedChecks), |
| 393 | }); |
| 394 | |
| 395 | return Object.entries(response).reduce( |
| 396 | (acc, [key, value]) => { |
| 397 | const index = key.indexOf("."); |
| 398 | const orgId = key.substring(0, index); |
| 399 | const perm = key.substring(index + 1); |
| 400 | if (!acc[orgId]) { |
| 401 | acc[orgId] = {}; |
| 402 | } |
| 403 | acc[orgId][perm as WorkspacePermissionName] = value; |
| 404 | return acc; |
| 405 | }, |
| 406 | {} as Record<string, Partial<WorkspacePermissions>>, |
| 407 | ) as Record<string, WorkspacePermissions>; |
| 408 | }, |
| 409 | } satisfies UseQueryOptions<Record<string, WorkspacePermissions>>; |
| 410 | }; |
| 411 | |
| 412 | const getOrganizationIdpSyncClaimFieldValuesKey = ( |
| 413 | organization: string, |
no test coverage detected