From c5fe153c62eb2aa968d86b218ef8f1cfbb0890ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=BCttner?= <4376726+hanneskuettner@users.noreply.github.com> Date: Fri, 19 Apr 2024 14:20:46 +0200 Subject: [PATCH] Fix caching for marketplace account / type extension listing (#22254) Co-authored-by: Pascal Jufer --- .changeset/smooth-ears-buy.md | 6 +++ api/src/controllers/extensions.ts | 47 ++++++++++++------- .../marketplace/routes/account/account.vue | 2 +- .../marketplace/routes/registry/registry.vue | 6 ++- 4 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 .changeset/smooth-ears-buy.md diff --git a/.changeset/smooth-ears-buy.md b/.changeset/smooth-ears-buy.md new file mode 100644 index 0000000000..ff82f9d388 --- /dev/null +++ b/.changeset/smooth-ears-buy.md @@ -0,0 +1,6 @@ +--- +'@directus/api': patch +'@directus/app': patch +--- + +Fixed a caching issue which could lead to wrong extensions being listed under Marketplace when filtering by type / account diff --git a/api/src/controllers/extensions.ts b/api/src/controllers/extensions.ts index 4e562105e3..6cf76bf7f5 100644 --- a/api/src/controllers/extensions.ts +++ b/api/src/controllers/extensions.ts @@ -1,5 +1,5 @@ import { useEnv } from '@directus/env'; -import { ErrorCode, ForbiddenError, RouteNotFoundError, isDirectusError } from '@directus/errors'; +import { ErrorCode, ForbiddenError, isDirectusError, RouteNotFoundError } from '@directus/errors'; import { EXTENSION_TYPES } from '@directus/extensions'; import { account, @@ -10,8 +10,10 @@ import { type ListOptions, type ListQuery, } from '@directus/extensions-registry'; +import type { FieldFilter } from '@directus/types'; import { isIn } from '@directus/utils'; import express from 'express'; +import { isNil } from 'lodash-es'; import { UUID_REGEX } from '../constants.js'; import { getExtensionManager } from '../extensions/index.js'; import { respond } from '../middleware/respond.js'; @@ -48,36 +50,47 @@ router.get( throw new ForbiddenError(); } - const { search, limit, offset, type, by, sort } = req.query; + const { search, limit, offset, sort, filter } = req.sanitizedQuery; const query: ListQuery = {}; - if (typeof search === 'string') { + if (!isNil(search)) { query.search = search; } - if (typeof limit === 'string') { - query.limit = Number(limit); + if (!isNil(limit)) { + query.limit = limit; } - if (typeof offset === 'string') { - query.offset = Number(offset); + if (!isNil(offset)) { + query.offset = offset; } - if (typeof by === 'string') { - query.by = by; - } + if (filter) { + const getFilterValue = (key: string) => { + const field = (filter as FieldFilter)[key]; + if (!field || !('_eq' in field) || typeof field._eq !== 'string') return; + return field._eq; + }; - if (typeof sort === 'string' && isIn(sort, ['popular', 'recent', 'downloads'] as const)) { - query.sort = sort; - } + const by = getFilterValue('by'); + const type = getFilterValue('type'); - if (typeof type === 'string') { - if (isIn(type, EXTENSION_TYPES) === false) { - throw new ForbiddenError(); + if (by) { + query.by = by; } - query.type = type; + if (type) { + if (isIn(type, EXTENSION_TYPES) === false) { + throw new ForbiddenError(); + } + + query.type = type; + } + } + + if (!isNil(sort) && sort[0] && isIn(sort[0], ['popular', 'recent', 'downloads'] as const)) { + query.sort = sort[0]; } if (env['MARKETPLACE_TRUST'] === 'sandbox') { diff --git a/app/src/modules/settings/routes/marketplace/routes/account/account.vue b/app/src/modules/settings/routes/marketplace/routes/account/account.vue index be8478e4cc..2ce9fffc68 100644 --- a/app/src/modules/settings/routes/marketplace/routes/account/account.vue +++ b/app/src/modules/settings/routes/marketplace/routes/account/account.vue @@ -48,7 +48,7 @@ watchEffect(async () => { params: { limit: perPage, offset: (page.value - 1) * perPage, - by: props.accountId, + filter: { by: { _eq: props.accountId } }, }, }); diff --git a/app/src/modules/settings/routes/marketplace/routes/registry/registry.vue b/app/src/modules/settings/routes/marketplace/routes/registry/registry.vue index 56ff99a21f..308867f456 100644 --- a/app/src/modules/settings/routes/marketplace/routes/registry/registry.vue +++ b/app/src/modules/settings/routes/marketplace/routes/registry/registry.vue @@ -53,7 +53,11 @@ watchEffect(async () => { search: search.value, limit: perPage, offset: (page.value - 1) * perPage, - type: type.value, + filter: { + type: { + _eq: type.value, + }, + }, sort: sort.value, }, });