From 807bda3dcb962fd8fc7cea7c4327ed900f65685a Mon Sep 17 00:00:00 2001 From: Brainslug Date: Tue, 13 Dec 2022 15:05:14 +0100 Subject: [PATCH] Follow up user Roles not loading (#16278) * applied the same role fix too users invite * added same fix when saving permissions * Prevent loading users unecessarily on the permission page * Added proper `deep` query typing * fixed typing for tests * apply similar fix for navigation folder --- api/src/services/items.test.ts | 8 ++++---- app/src/composables/use-item.ts | 10 +++++++--- .../files/components/navigation-folder.vue | 2 ++ .../modules/settings/routes/roles/item/item.vue | 3 ++- .../permissions-detail/permissions-detail.vue | 6 +++++- .../views/private/components/users-invite.vue | 7 ++++++- packages/shared/src/types/query.ts | 16 +++++++++++++++- 7 files changed, 41 insertions(+), 11 deletions(-) diff --git a/api/src/services/items.test.ts b/api/src/services/items.test.ts index a04a01c924..5c7c75d011 100644 --- a/api/src/services/items.test.ts +++ b/api/src/services/items.test.ts @@ -1,4 +1,4 @@ -import { Query } from '@directus/shared/types'; +import { NestedDeepQuery } from '@directus/shared/types'; import knex, { Knex } from 'knex'; import { getTracker, MockClient, Tracker } from 'knex-mock-client'; import { cloneDeep } from 'lodash'; @@ -442,7 +442,7 @@ describe('Integration Tests', () => { }); const response = await itemsService.readOne(rawItems[0].id, { fields: ['id', 'items.*'], - deep: { items: { _filter: { title: { _eq: childItems[0].title } } } as Query }, + deep: { items: { _filter: { title: { _eq: childItems[0].title } } } as NestedDeepQuery }, }); expect(tracker.history.select.length).toBe(2); @@ -532,7 +532,7 @@ describe('Integration Tests', () => { }); const response = await itemsService.readOne(rawItems[0].id, { fields: ['id', 'items.*'], - deep: { items: { _filter: { title: { _eq: childItems[0].title } } } as Query }, + deep: { items: { _filter: { title: { _eq: childItems[0].title } } } as NestedDeepQuery }, }); expect(tracker.history.select.length).toBe(2); @@ -625,7 +625,7 @@ describe('Integration Tests', () => { expect(() => itemsService.readOne(rawItems[0].id, { fields: ['id', 'items.*'], - deep: { items: { _filter: { title: { _eq: childItems[0].title } } } as Query }, + deep: { items: { _filter: { title: { _eq: childItems[0].title } } } as NestedDeepQuery }, }) ).rejects.toThrow("You don't have permission to access this."); expect(tracker.history.select.length).toBe(0); diff --git a/app/src/composables/use-item.ts b/app/src/composables/use-item.ts index 6782966d22..d90b976f4d 100644 --- a/app/src/composables/use-item.ts +++ b/app/src/composables/use-item.ts @@ -14,7 +14,7 @@ import { AxiosResponse } from 'axios'; import { merge } from 'lodash'; import { computed, ComputedRef, Ref, ref, watch } from 'vue'; import { usePermissions } from './use-permissions'; -import { Field, Relation } from '@directus/shared/types'; +import { Field, Query, Relation } from '@directus/shared/types'; import { getDefaultValuesFromFields } from '@/utils/get-default-values-from-fields'; type UsableItem = { @@ -38,7 +38,11 @@ type UsableItem = { validationErrors: Ref; }; -export function useItem(collection: Ref, primaryKey: Ref): UsableItem { +export function useItem( + collection: Ref, + primaryKey: Ref, + query: Query = {} +): UsableItem { const { info: collectionInfo, primaryKeyField } = useCollection(collection); const item = ref | null>(null); const error = ref(null); @@ -103,7 +107,7 @@ export function useItem(collection: Ref, primaryKey: Ref) => ({ text: role.name, diff --git a/packages/shared/src/types/query.ts b/packages/shared/src/types/query.ts index 506ae82d24..d4b2b518ae 100644 --- a/packages/shared/src/types/query.ts +++ b/packages/shared/src/types/query.ts @@ -11,10 +11,24 @@ export type Query = { export?: 'json' | 'csv' | 'xml' | null; group?: string[] | null; aggregate?: Aggregate | null; - deep?: Record | null; + deep?: NestedDeepQuery | null; alias?: Record | null; }; +export type DeepQuery = { + _fields?: string[] | null; + _sort?: string[] | null; + _filter?: Filter | null; + _limit?: number | null; + _offset?: number | null; + _page?: number | null; + _search?: string | null; + _group?: string[] | null; + _aggregate?: Aggregate | null; +}; + +export type NestedDeepQuery = { [field: string]: DeepQuery | NestedDeepQuery }; + /** * Aggregate operation. Contains column name, and the field alias it should be returned as */