diff --git a/packages/strapi-plugin-content-type-builder/controllers/validation/model-schema.js b/packages/strapi-plugin-content-type-builder/controllers/validation/model-schema.js index 134d6a78f3..69e900b452 100644 --- a/packages/strapi-plugin-content-type-builder/controllers/validation/model-schema.js +++ b/packages/strapi-plugin-content-type-builder/controllers/validation/model-schema.js @@ -31,6 +31,7 @@ const createSchema = (types, relations, { modelType } = {}) => .string() .oneOf(types) .required(), + configurable: yup.boolean().nullable(), ...getTypeShape(attribute, { modelType }), }; diff --git a/packages/strapi-plugin-content-type-builder/controllers/validation/relations.js b/packages/strapi-plugin-content-type-builder/controllers/validation/relations.js index 4bf21ebe3a..e9375af1ed 100644 --- a/packages/strapi-plugin-content-type-builder/controllers/validation/relations.js +++ b/packages/strapi-plugin-content-type-builder/controllers/validation/relations.js @@ -21,6 +21,7 @@ module.exports = (obj, validNatures) => { .oneOf(validNatures) .required(), unique: validators.unique.nullable(), + configurable: yup.boolean().nullable(), dominant: yup.boolean().nullable(), columnName: yup.string().nullable(), targetAttribute: REVERSE_RELATIONS.includes(obj.nature) diff --git a/packages/strapi-plugin-content-type-builder/services/schema-builder/index.js b/packages/strapi-plugin-content-type-builder/services/schema-builder/index.js index 4afa30cfb4..12a343e3e8 100644 --- a/packages/strapi-plugin-content-type-builder/services/schema-builder/index.js +++ b/packages/strapi-plugin-content-type-builder/services/schema-builder/index.js @@ -86,6 +86,8 @@ function createSchemaBuilder({ components, contentTypes }) { return Object.keys(attributes).reduce((acc, key) => { const attribute = attributes[key]; + const { configurable } = attribute; + if (_.has(attribute, 'type')) { if (attribute.type === 'media') { const fileModel = strapi.getModel('file', 'upload'); @@ -97,9 +99,13 @@ function createSchemaBuilder({ components, contentTypes }) { via, plugin: 'upload', required: attribute.required ? true : false, + configurable: configurable === false ? false : undefined, }; } else { - acc[key] = attribute; + acc[key] = { + ...attribute, + configurable: configurable === false ? false : undefined, + }; } return acc; @@ -118,6 +124,7 @@ function createSchemaBuilder({ components, contentTypes }) { const attr = { unique: unique === true ? true : undefined, columnName: columnName || undefined, + configurable: configurable === false ? false : undefined, }; if (!this.contentTypes.has(target)) { diff --git a/packages/strapi-plugin-content-type-builder/utils/attributes.js b/packages/strapi-plugin-content-type-builder/utils/attributes.js index 47349a8ee3..08459acbab 100644 --- a/packages/strapi-plugin-content-type-builder/utils/attributes.js +++ b/packages/strapi-plugin-content-type-builder/utils/attributes.js @@ -60,7 +60,7 @@ const formatAttribute = (key, attribute, { model }) => { const relation = (model.associations || []).find( assoc => assoc.alias === key ); - const { plugin } = attribute; + const { plugin, configurable } = attribute; let targetEntity = attribute.model || attribute.collection; if (plugin === 'upload' && targetEntity === 'file') { @@ -68,6 +68,7 @@ const formatAttribute = (key, attribute, { model }) => { type: 'media', multiple: attribute.collection ? true : false, required: attribute.required ? true : false, + configurable: configurable === false ? false : undefined, }; } else { return { @@ -77,6 +78,7 @@ const formatAttribute = (key, attribute, { model }) => { dominant: attribute.dominant ? true : false, targetAttribute: attribute.via || undefined, columnName: attribute.columnName || undefined, + configurable: configurable === false ? false : undefined, targetColumnName: _.get( strapi.getModel(targetEntity, plugin), ['attributes', attribute.via, 'columnName'],