(check: AuthorizationCheck)
| 300 | * check, and returns only those that pass. |
| 301 | */ |
| 302 | export const permittedOrganizations = (check: AuthorizationCheck) => { |
| 303 | return { |
| 304 | queryKey: ["organizations", "permitted", check], |
| 305 | queryFn: async (): Promise<Organization[]> => { |
| 306 | const orgs = await API.getOrganizations(); |
| 307 | const checks = Object.fromEntries( |
| 308 | orgs.map((org) => [ |
| 309 | org.id, |
| 310 | { |
| 311 | ...check, |
| 312 | object: { ...check.object, organization_id: org.id }, |
| 313 | }, |
| 314 | ]), |
| 315 | ); |
| 316 | const permissions = await API.checkAuthorization({ checks }); |
| 317 | return orgs.filter((org) => permissions[org.id]); |
| 318 | }, |
| 319 | }; |
| 320 | }; |
| 321 | |
| 322 | /** |
| 323 | * Fetch permissions for all provided organizations. |
no test coverage detected