From 4f3e6aad6a64f9b5d4e0708d4322b6881e06e15b Mon Sep 17 00:00:00 2001 From: Jim Laurie Date: Mon, 14 May 2018 16:01:09 +0200 Subject: [PATCH 1/4] Disable reserved attributes fix #791 --- .../Form/utils/attributeValidations.js | 28 +++++++++++++++++++ .../admin/src/translations/en.json | 1 + .../admin/src/translations/fr.json | 1 + .../config/queries/bookshelf.js | 4 +-- 4 files changed, 31 insertions(+), 3 deletions(-) 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..fa3d165999 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 @@ -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 (reserved.includes(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..0fd6daaa1c 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 can't be used", "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..025245df30 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 ne peut pas être utilisé", "form.attribute.item.textarea.name": "Nom", "form.attribute.item.date.name": "Nom", diff --git a/packages/strapi-plugin-users-permissions/config/queries/bookshelf.js b/packages/strapi-plugin-users-permissions/config/queries/bookshelf.js index cddafeb77e..80c6565996 100644 --- a/packages/strapi-plugin-users-permissions/config/queries/bookshelf.js +++ b/packages/strapi-plugin-users-permissions/config/queries/bookshelf.js @@ -139,9 +139,7 @@ module.exports = { removePermission: async function (params) { return this - .forge({ - [this.primaryKey]: params[this.primaryKey] || params.id - }) + .where(params) .destroy(); } }; From d3fac43ce5682cd7be74ba89b17534a613bc00fa Mon Sep 17 00:00:00 2001 From: Jim Laurie Date: Mon, 14 May 2018 17:01:51 +0200 Subject: [PATCH 2/4] Add missing comma --- .../admin/src/containers/Form/utils/attributeValidations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fa3d165999..bd3f4cfc42 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 @@ -57,7 +57,7 @@ export default function checkAttributeValidations(errors) { 'validate', 'remove', '_pres', - '_posts' + '_posts', ]; if (reserved.includes(get(this.props.modifiedDataAttribute, 'name'))) { From ba809f61497c97e1d98dc2ba3397ab0613733e61 Mon Sep 17 00:00:00 2001 From: Kamal Bennani Date: Mon, 14 May 2018 20:55:26 +0200 Subject: [PATCH 3/4] correctly access the ref of the given model as param --- packages/strapi-plugin-graphql/services/GraphQL.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) 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. From e082672d539bc9acda86a8cbac772408cc1bab38 Mon Sep 17 00:00:00 2001 From: Jim Laurie Date: Tue, 15 May 2018 17:20:46 +0200 Subject: [PATCH 4/4] Fix feedback PR --- .../admin/src/containers/Form/utils/attributeValidations.js | 4 ++-- .../admin/src/translations/en.json | 2 +- .../admin/src/translations/fr.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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 bd3f4cfc42..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) { @@ -60,7 +60,7 @@ export default function checkAttributeValidations(errors) { '_posts', ]; - if (reserved.includes(get(this.props.modifiedDataAttribute, 'name'))) { + if (includes(reserved, get(this.props.modifiedDataAttribute, 'name'))) { formErrors.push({ name: 'name', errors: [{ id: 'content-type-builder.error.attribute.forbidden' }]}); } 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 0fd6daaa1c..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,7 +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 can't be used", + "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 025245df30..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,7 +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 ne peut pas être utilisé", + "error.attribute.forbidden": "Cet attribut est réservé", "form.attribute.item.textarea.name": "Nom", "form.attribute.item.date.name": "Nom",