diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/utils/attributeValidations.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/utils/attributeValidations.js index 9ca6d5b556..a6feab4cce 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/utils/attributeValidations.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/utils/attributeValidations.js @@ -1,4 +1,4 @@ -import { get, filter, isNumber, size, split, isEmpty, has, map, concat } from 'lodash'; +import { get, filter, isNumber, size, split, isEmpty, has, map, concat, includes } from 'lodash'; export default function checkAttributeValidations(errors) { @@ -36,6 +36,34 @@ export default function checkAttributeValidations(errors) { formErrors.push({ name: 'params.key', errors: [{ id: 'content-type-builder.error.attribute.sameKeyAndName' }]}); } + const reserved = [ + 'id', + 'set', + 'value', + 'emit', + 'on', + 'once', + 'listeners', + 'removeListener', + 'collection', + 'db', + 'isModified', + 'isNew', + 'get', + 'modelName', + 'save', + 'schema', + 'toObject', + 'validate', + 'remove', + '_pres', + '_posts', + ]; + + if (includes(reserved, get(this.props.modifiedDataAttribute, 'name'))) { + formErrors.push({ name: 'name', errors: [{ id: 'content-type-builder.error.attribute.forbidden' }]}); + } + return formErrors; } diff --git a/packages/strapi-plugin-content-type-builder/admin/src/translations/en.json b/packages/strapi-plugin-content-type-builder/admin/src/translations/en.json index ea8f7e7d7a..1a82424a3a 100755 --- a/packages/strapi-plugin-content-type-builder/admin/src/translations/en.json +++ b/packages/strapi-plugin-content-type-builder/admin/src/translations/en.json @@ -43,6 +43,7 @@ "error.attribute.key.taken": "This value already exists", "error.attribute.sameKeyAndName": "Can't be equal", "error.validation.minSupMax": "Can't be superior", + "error.attribute.forbidden": "This attribute name is reserved", "form.attribute.item.textarea.name": "Name", "form.attribute.item.number.name": "Name", diff --git a/packages/strapi-plugin-content-type-builder/admin/src/translations/fr.json b/packages/strapi-plugin-content-type-builder/admin/src/translations/fr.json index e329060df9..1547d65174 100755 --- a/packages/strapi-plugin-content-type-builder/admin/src/translations/fr.json +++ b/packages/strapi-plugin-content-type-builder/admin/src/translations/fr.json @@ -44,6 +44,7 @@ "error.attribute.key.taken": "Cette valeur existe déjà", "error.attribute.sameKeyAndName": "Ne peuvent pas être égaux", "error.validation.minSupMax": "Ne peut pas être plus grand", + "error.attribute.forbidden": "Cet attribut est réservé", "form.attribute.item.textarea.name": "Nom", "form.attribute.item.date.name": "Nom", diff --git a/packages/strapi-plugin-graphql/services/GraphQL.js b/packages/strapi-plugin-graphql/services/GraphQL.js index 08a39d6cb5..55b90b17fb 100644 --- a/packages/strapi-plugin-graphql/services/GraphQL.js +++ b/packages/strapi-plugin-graphql/services/GraphQL.js @@ -544,14 +544,9 @@ module.exports = { if (association.type === 'model') { params.id = obj[association.alias]; } else { - // Get attribute. - const attr = association.plugin ? - strapi.plugins[association.plugin].models[params.model].attributes[association.via]: - strapi.models[params.model].attributes[association.via]; - // Get refering model. - const ref = attr.plugin ? - strapi.plugins[attr.plugin].models[params.model]: + const ref = association.plugin ? + strapi.plugins[association.plugin].models[params.model]: strapi.models[params.model]; // Apply optional arguments to make more precise nested request.