* Read all collections. Currently doesn't support any query.
()
| 322 | * Read all collections. Currently doesn't support any query. |
| 323 | */ |
| 324 | async readByQuery(): Promise<Collection[]> { |
| 325 | const env = useEnv(); |
| 326 | |
| 327 | const collectionsItemsService = new ItemsService('directus_collections', { |
| 328 | knex: this.knex, |
| 329 | schema: this.schema, |
| 330 | accountability: this.accountability, |
| 331 | }); |
| 332 | |
| 333 | let tablesInDatabase = await this.schemaInspector.tableInfo(); |
| 334 | |
| 335 | let meta = (await collectionsItemsService.readByQuery({ |
| 336 | limit: -1, |
| 337 | })) as BaseCollectionMeta[]; |
| 338 | |
| 339 | meta.push(...systemCollectionRows); |
| 340 | |
| 341 | if (this.accountability && this.accountability.admin !== true) { |
| 342 | const collectionsGroups: { [key: string]: string } = meta.reduce( |
| 343 | (meta, item) => ({ |
| 344 | ...meta, |
| 345 | [item.collection]: item.group, |
| 346 | }), |
| 347 | {}, |
| 348 | ); |
| 349 | |
| 350 | let collectionsYouHavePermissionToRead = await fetchAllowedCollections( |
| 351 | { |
| 352 | accountability: this.accountability, |
| 353 | action: 'read', |
| 354 | }, |
| 355 | { |
| 356 | knex: this.knex, |
| 357 | schema: this.schema, |
| 358 | }, |
| 359 | ); |
| 360 | |
| 361 | for (const collection of collectionsYouHavePermissionToRead) { |
| 362 | const group = collectionsGroups[collection]; |
| 363 | if (group) collectionsYouHavePermissionToRead.push(group); |
| 364 | delete collectionsGroups[collection]; |
| 365 | } |
| 366 | |
| 367 | collectionsYouHavePermissionToRead = [...new Set([...collectionsYouHavePermissionToRead])]; |
| 368 | |
| 369 | tablesInDatabase = tablesInDatabase.filter((table) => { |
| 370 | return collectionsYouHavePermissionToRead.includes(table.name); |
| 371 | }); |
| 372 | |
| 373 | meta = meta.filter((collectionMeta) => { |
| 374 | return collectionsYouHavePermissionToRead.includes(collectionMeta.collection); |
| 375 | }); |
| 376 | } |
| 377 | |
| 378 | const collections: Collection[] = []; |
| 379 | |
| 380 | for (const collectionMeta of meta) { |
| 381 | const collection: Collection = { |
no test coverage detected