fix(medusa): Allowed properties expand (#4600)

What:
The expand allowed properties should allow all the segments whereas the allowed fields should be specific
This commit is contained in:
Adrien de Peretti
2023-07-25 14:37:44 +00:00
committed by GitHub
parent f12299deb1
commit 9129ca08a7
7 changed files with 86 additions and 71 deletions
@@ -11,6 +11,7 @@ import { BaseEntity } from "../../interfaces"
import { FindConfig, QueryConfig, RequestQueryFields } from "../../types/common"
import { omit } from "lodash"
import { removeUndefinedProperties } from "../../utils"
import { buildSelects, objectToStringPath } from "@medusajs/utils"
/**
* Middleware that transform the query input for the admin end points
@@ -151,7 +152,7 @@ function getStoreAllowedProperties<TEntity extends BaseEntity>(
? [...(validated.expand?.split(",") || []), ...includeKeys]
: queryConfig?.allowedRelations || []
allowed.push(...fields, ...expand)
allowed.push(...fields, ...objectToStringPath(buildSelects(expand)))
return allowed
}
@@ -180,7 +181,7 @@ function getAllowedProperties<TEntity extends BaseEntity>(
? [...(validated.expand?.split(",") || []), ...includeKeys]
: queryConfig?.defaultRelations || []
allowed.push(...fields, ...expand)
allowed.push(...fields, ...objectToStringPath(buildSelects(expand)))
return allowed as string[]
}
@@ -50,7 +50,7 @@ describe("GET /admin/orders", () => {
}
),
// TODO [MEDUSA_FF_SALES_CHANNELS]: Remove when sales channel flag is removed entirely
relations: [...defaultAdminOrdersRelations, "sales_channel"],
relations: [...defaultAdminOrdersRelations, "sales_channel"].sort(),
},
{
includes: undefined,
@@ -72,7 +72,7 @@ export default async (req, res) => {
order = cleanResponseData(order, req.allowedProperties)
res.json({ order: cleanResponseData(order, []) })
res.json({ order: order })
}
export class AdminGetOrdersOrderParams extends FindParams {}
@@ -56,16 +56,16 @@ describe("GET /admin/products/:id", () => {
"metadata",
],
relations: [
"variants",
"variants.prices",
"variants.options",
"profiles",
"collection",
"images",
"options",
"profiles",
"sales_channels",
"tags",
"type",
"collection",
"sales_channels",
"variants",
"variants.options",
"variants.prices",
],
}
)