Skip to content

Commit

Permalink
fix(api-headless-cms): load all models and entries in ref field mappi…
Browse files Browse the repository at this point in the history
…ng (#3567)
  • Loading branch information
brunozoric committed Oct 3, 2023
1 parent acd3e6b commit 8ac4546
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,14 @@ export const referenceFieldsMapping = async (params: Params): Promise<Record<str
/**
* Load all models and use only those that are used in reference.
*/
const models = (await context.cms.listModels()).filter(model => {
const entries = referencesByModel[model.modelId];
if (!Array.isArray(entries) || entries.length === 0) {
return false;
}
return true;
const models = await context.security.withoutAuthorization(async () => {
return (await context.cms.listModels()).filter(model => {
const entries = referencesByModel[model.modelId];
if (!Array.isArray(entries) || entries.length === 0) {
return false;
}
return true;
});
});
/**
* Check for any model existence, just in case.
Expand All @@ -230,8 +232,10 @@ export const referenceFieldsMapping = async (params: Params): Promise<Record<str
/**
* Load all the entries by their ID
*/
const promises = models.map(model => {
return context.cms.getEntriesByIds(model, referencesByModel[model.modelId]);
const promises = await context.security.withoutAuthorization(async () => {
return models.map(model => {
return context.cms.getEntriesByIds(model, referencesByModel[model.modelId]);
});
});

const results = await Promise.all(promises);
Expand Down

0 comments on commit 8ac4546

Please sign in to comment.