Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: merge dev to next #3588

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,14 @@ async function validateReferencedEntries({
/**
* Load all models and use only those used in the input references.
*/
const models = (await context.cms.listModels()).filter(model => {
const entries = referencesByModel.get(model.modelId);
if (!entries || !entries.length) {
return false;
}
return true;
const models = await context.security.withoutAuthorization(async () => {
return (await context.cms.listModels()).filter(model => {
const entries = referencesByModel.get(model.modelId);
if (!entries?.length) {
return false;
}
return true;
});
});

if (!models.length) {
Expand All @@ -302,8 +304,10 @@ async function validateReferencedEntries({
/**
* Load all the entries by their IDs.
*/
const promises = models.map(model => {
return context.cms.getEntriesByIds(model, referencesByModel.get(model.modelId) || []);
const promises = await context.security.withoutAuthorization(async () => {
return models.map(model => {
return context.cms.getEntriesByIds(model, referencesByModel.get(model.modelId) || []);
});
});

const allEntries = await Promise.all(promises).then(res => res.flat());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,24 @@ const remapTemplateValue = (value: any, typeName: string) => {
const createResolver = (
endpointType: ApiEndpoint
): CmsModelFieldToGraphQLCreateResolver<CmsModelDynamicZoneField> => {
return ({ model, models, field, fieldTypePlugins, createFieldResolvers, graphQLType }) => {
const templates = getFieldTemplates(field);

if (!templates.length) {
return false;
}

return ({ model, models, field, fieldTypePlugins, createFieldResolvers }) => {
const resolver = (parent: any) => {
const value = parent[field.fieldId];
if (!value) {
return value;
}

const typeName = `${graphQLType}_${createTypeName(field.fieldId)}`;
// const typeName = `${model.singularApiName}_${createTypeName(field.fieldId)}`;
const typeName = `${model.singularApiName}_${createTypeName(field.fieldId)}`;

if (field.multipleValues && Array.isArray(value)) {
const remappedValues = value.map(v => {
return remapTemplateValue(v, typeName);
});

return remappedValues;
return value.map(v => remapTemplateValue(v, typeName));
}

return remapTemplateValue(value, typeName);
};

const templates = getFieldTemplates(field);

const { templateTypes } = createTypeDefsForTemplates({
models,
field,
Expand All @@ -120,24 +111,17 @@ const createResolver = (
templates
});

const replace = new RegExp(`${model.singularApiName}_`, "g");

const typeResolvers = templateTypes
.map(templateType => {
return templateType.replace(replace, `${graphQLType}_`);
})
.reduce<Record<string, Record<string, GraphQLFieldResolver>>>(
(typeResolvers, templateType, index) => {
return {
...typeResolvers,
...createFieldResolvers({
graphQLType: templateType,
fields: field.settings.templates[index].fields
})
};
},
{}
);
const typeResolvers = templateTypes.reduce<
Record<string, Record<string, GraphQLFieldResolver>>
>((typeResolvers, templateType, index) => {
return {
...typeResolvers,
...createFieldResolvers({
graphQLType: templateType,
fields: field.settings.templates[index].fields
})
};
}, {});

return {
resolver,
Expand Down Expand Up @@ -177,10 +161,6 @@ export const createDynamicZoneField =
read: {
createTypeField({ models, model, field, fieldTypePlugins }) {
const templates = getFieldTemplates(field);
if (!templates.length) {
return null;
}

const unionTypeName = createUnionTypeName(model, field);

const { typeDefs, templateTypes } = createTypeDefsForTemplates({
Expand All @@ -207,11 +187,6 @@ export const createDynamicZoneField =
manage: {
createTypeField({ models, model, field, fieldTypePlugins }) {
const templates = getFieldTemplates(field);

if (!templates.length) {
return null;
}

const unionTypeName = createUnionTypeName(model, field);

const { typeDefs, templateTypes } = createTypeDefsForTemplates({
Expand Down Expand Up @@ -244,10 +219,6 @@ export const createDynamicZoneField =
createInputField({ models, model, field, fieldTypePlugins }) {
const templates = getFieldTemplates(field);

if (!templates.length) {
return null;
}

const { typeDefs, templateTypes } = createTypeDefsForTemplates({
models,
field,
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16520,6 +16520,7 @@ __metadata:
"@webiny/cli": 0.0.0
"@webiny/project-utils": 0.0.0
find-up: ^5.0.0
lodash: ^4.17.21
rimraf: ^3.0.2
typescript: 4.7.4
languageName: unknown
Expand Down