diff --git a/packages/strapi-admin/models/Role.settings.json b/packages/strapi-admin/models/Role.settings.json index b96462c30c..592c5a00e5 100644 --- a/packages/strapi-admin/models/Role.settings.json +++ b/packages/strapi-admin/models/Role.settings.json @@ -7,7 +7,7 @@ "attributes": { "name": { "type": "string", - "minLength": 3, + "minLength": 1, "unique": true, "configurable": false, "required": true diff --git a/packages/strapi-admin/models/User.settings.json b/packages/strapi-admin/models/User.settings.json index 69888075c1..44db31a58e 100644 --- a/packages/strapi-admin/models/User.settings.json +++ b/packages/strapi-admin/models/User.settings.json @@ -8,18 +8,20 @@ "firstname": { "type": "string", "unique": false, + "minLength": 1, "configurable": false, "required": false }, "lastname": { "type": "string", "unique": false, + "minLength": 1, "configurable": false, "required": false }, "username": { "type": "string", - "unique": true, + "unique": false, "configurable": false, "required": false }, diff --git a/packages/strapi-connector-bookshelf/lib/mount-models.js b/packages/strapi-connector-bookshelf/lib/mount-models.js index d1af995f33..900b7e2b56 100644 --- a/packages/strapi-connector-bookshelf/lib/mount-models.js +++ b/packages/strapi-connector-bookshelf/lib/mount-models.js @@ -138,11 +138,7 @@ module.exports = ({ models, target }, ctx) => { // Exclude polymorphic association. if (globalName !== '*') { - globalId = details.plugin - ? details.plugin === 'admin' - ? _.get(strapi.admin, `models.${globalName.toLowerCase()}.globalId`) - : _.get(strapi.plugins, `${details.plugin}.models.${globalName.toLowerCase()}.globalId`) - : _.get(strapi.models, `${globalName.toLowerCase()}.globalId`); + globalId = strapi.db.getModel(globalName.toLowerCase(), details.plugin).globalId; } switch (verbose) { diff --git a/packages/strapi-database/lib/database-manager.js b/packages/strapi-database/lib/database-manager.js index 90771ed595..b01e6f996a 100644 --- a/packages/strapi-database/lib/database-manager.js +++ b/packages/strapi-database/lib/database-manager.js @@ -120,6 +120,14 @@ class DatabaseManager { }); } + getModelsByPluginName(pluginName) { + if (!pluginName) { + return strapi.models; + } + + return pluginName === 'admin' ? strapi.admin.models : strapi.plugins[pluginName].models; + } + getReservedNames() { return { models: constants.RESERVED_MODEL_NAMES, diff --git a/packages/strapi-utils/lib/models.js b/packages/strapi-utils/lib/models.js index e355677a4b..708a5a78e2 100644 --- a/packages/strapi-utils/lib/models.js +++ b/packages/strapi-utils/lib/models.js @@ -38,11 +38,7 @@ module.exports = { other: '', }; - const models = attribute.plugin - ? attribute.plugin === 'admin' - ? strapi.admin.models - : strapi.plugins[attribute.plugin].models - : strapi.models; + const models = strapi.db.getModelsByPluginName(attribute.plugin); const pluginModels = Object.values(strapi.plugins).reduce((acc, plugin) => { return acc.concat(Object.values(plugin.models)); @@ -326,15 +322,8 @@ module.exports = { }); if (targetName !== '*') { - if (association.plugin) { - const models = - association.plugin === 'admin' - ? strapi.admin.models - : strapi.plugins[association.plugin].models || {}; - details = _.get(models, [targetName, 'attributes', association.via]); - } else { - details = _.get(strapi.models, [targetName, 'attributes', association.via], {}); - } + const models = strapi.db.getModelsByPluginName(association.plugin); + details = _.get(models, [targetName, 'attributes', association.via], {}); } // Build associations object