From 03195550aa568751e48d805e9bb2f5c9c902a3ed Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Tue, 13 Mar 2018 09:28:17 +0100 Subject: [PATCH 1/4] Fix edit user --- .../admin/src/containers/EditPage/saga.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/EditPage/saga.js b/packages/strapi-plugin-content-manager/admin/src/containers/EditPage/saga.js index 8d3d365796..ff4e297eb4 100644 --- a/packages/strapi-plugin-content-manager/admin/src/containers/EditPage/saga.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/EditPage/saga.js @@ -84,8 +84,8 @@ export function* submit() { return acc; }, new FormData()); - - const id = isCreating ? '' : record.id; + + const id = isCreating ? '' : record.id || record._id; const params = { source }; // Change the request helper default headers so we can pass a FormData const headers = { From 3c1ec201550bdd24680363f46fc1ba2e50ac74f1 Mon Sep 17 00:00:00 2001 From: Jim Laurie Date: Tue, 13 Mar 2018 15:57:41 +0100 Subject: [PATCH 2/4] Fix form data update user --- .../config/policies/routing.js | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/strapi-plugin-content-manager/config/policies/routing.js b/packages/strapi-plugin-content-manager/config/policies/routing.js index bb204f0fff..f0a50968be 100644 --- a/packages/strapi-plugin-content-manager/config/policies/routing.js +++ b/packages/strapi-plugin-content-manager/config/policies/routing.js @@ -8,7 +8,40 @@ module.exports = async (ctx, next) => { if (controller && action) { // Redirect to specific controller. - return await strapi.plugins[source].controllers[controller.toLowerCase()][action](ctx); + if (ctx.request.body.hasOwnProperty('fields') && ctx.request.body.hasOwnProperty('files')) { + const {files, fields} = _.cloneDeep(ctx.request.body); + + const fileAttributes = _.get(strapi.plugins, [source, 'models', ctx.params.model, 'associations'], []).filter(association => { + return association[association.type] === 'file' && association.via === 'related'; + }).reduce((acc, association) => { + acc.push(association.alias); + return acc; + }, []); + + ctx.request.body = _.omit(fields, fileAttributes); + + await strapi.plugins[source].controllers[controller.toLowerCase()][action](ctx); + const resBody = _.cloneDeep(ctx.body); + + Object.keys(files).map(async field => { + ctx.request.body = { + files: { + files: files[field] + }, + fields: { + refId: resBody.id || resBody._id, + ref: ctx.params.model, + source, + field + } + }; + + await strapi.plugins.upload.controllers.upload.upload(ctx); + }); + return ctx.send(resBody); + } else { + return await strapi.plugins[source].controllers[controller.toLowerCase()][action](ctx); + } } } From 2f4635bf4cd74814b2378aa32e7af3cf763e6bfa Mon Sep 17 00:00:00 2001 From: Jim Laurie Date: Thu, 15 Mar 2018 11:51:40 +0100 Subject: [PATCH 3/4] Fix PR feedback --- .../config/policies/routing.js | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/strapi-plugin-content-manager/config/policies/routing.js b/packages/strapi-plugin-content-manager/config/policies/routing.js index f0a50968be..d098fc6c4b 100644 --- a/packages/strapi-plugin-content-manager/config/policies/routing.js +++ b/packages/strapi-plugin-content-manager/config/policies/routing.js @@ -9,21 +9,30 @@ module.exports = async (ctx, next) => { if (controller && action) { // Redirect to specific controller. if (ctx.request.body.hasOwnProperty('fields') && ctx.request.body.hasOwnProperty('files')) { - const {files, fields} = _.cloneDeep(ctx.request.body); + let {files, fields} = _.cloneDeep(ctx.request.body); + + const parser = (value) => { + try { + value = JSON.parse(value); + } catch (e) { + // Silent. + } + + return _.isArray(value) ? value.map(obj => parser(obj)) : value; + }; + + fields = Object.keys(fields).reduce((acc, current) => { + acc[current] = parser(fields[current]); - const fileAttributes = _.get(strapi.plugins, [source, 'models', ctx.params.model, 'associations'], []).filter(association => { - return association[association.type] === 'file' && association.via === 'related'; - }).reduce((acc, association) => { - acc.push(association.alias); return acc; - }, []); + }, {}); - ctx.request.body = _.omit(fields, fileAttributes); + ctx.request.body = fields; await strapi.plugins[source].controllers[controller.toLowerCase()][action](ctx); const resBody = _.cloneDeep(ctx.body); - Object.keys(files).map(async field => { + await Promise.all(Object.keys(files).map(async field => { ctx.request.body = { files: { files: files[field] @@ -36,12 +45,13 @@ module.exports = async (ctx, next) => { } }; - await strapi.plugins.upload.controllers.upload.upload(ctx); - }); + return strapi.plugins.upload.controllers.upload.upload(ctx); + })); + return ctx.send(resBody); - } else { - return await strapi.plugins[source].controllers[controller.toLowerCase()][action](ctx); } + + return await strapi.plugins[source].controllers[controller.toLowerCase()][action](ctx); } } From 54af44901b1d311169f8bb2349542681cafdea68 Mon Sep 17 00:00:00 2001 From: Jim Laurie Date: Thu, 15 Mar 2018 12:01:10 +0100 Subject: [PATCH 4/4] Remove useless clone object --- .../config/policies/routing.js | 4 ++-- .../models/Role.settings.json | 5 ++--- .../models/User.settings.json | 10 ++++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/strapi-plugin-content-manager/config/policies/routing.js b/packages/strapi-plugin-content-manager/config/policies/routing.js index d098fc6c4b..fd484994e9 100644 --- a/packages/strapi-plugin-content-manager/config/policies/routing.js +++ b/packages/strapi-plugin-content-manager/config/policies/routing.js @@ -9,7 +9,7 @@ module.exports = async (ctx, next) => { if (controller && action) { // Redirect to specific controller. if (ctx.request.body.hasOwnProperty('fields') && ctx.request.body.hasOwnProperty('files')) { - let {files, fields} = _.cloneDeep(ctx.request.body); + let {files, fields} = ctx.request.body; const parser = (value) => { try { @@ -30,7 +30,7 @@ module.exports = async (ctx, next) => { ctx.request.body = fields; await strapi.plugins[source].controllers[controller.toLowerCase()][action](ctx); - const resBody = _.cloneDeep(ctx.body); + const resBody = ctx.body; await Promise.all(Object.keys(files).map(async field => { ctx.request.body = { diff --git a/packages/strapi-plugin-users-permissions/models/Role.settings.json b/packages/strapi-plugin-users-permissions/models/Role.settings.json index cdb41d5235..66fa504376 100644 --- a/packages/strapi-plugin-users-permissions/models/Role.settings.json +++ b/packages/strapi-plugin-users-permissions/models/Role.settings.json @@ -23,8 +23,7 @@ "users": { "collection": "user", "via": "role", - "plugin": "users-permissions", - "configurable": false + "plugin": "users-permissions" }, "permissions": { "collection": "permission", @@ -33,4 +32,4 @@ "configurable": false } } -} +} \ No newline at end of file diff --git a/packages/strapi-plugin-users-permissions/models/User.settings.json b/packages/strapi-plugin-users-permissions/models/User.settings.json index 99479b1cba..a5a45e2eb4 100644 --- a/packages/strapi-plugin-users-permissions/models/User.settings.json +++ b/packages/strapi-plugin-users-permissions/models/User.settings.json @@ -38,6 +38,12 @@ "via": "users", "plugin": "users-permissions", "configurable": false + }, + "picture": { + "collection": "file", + "via": "related", + "plugin": "upload" } - } -} + }, + "collectionName": "users-permissions_user" +} \ No newline at end of file