Fix/#7197/Change custom populate state to own service (#7204)

* Fix/#7197/Change custom populate state to own service

To avoid issue with population we change the service of state user to there own service call "fetchState", also to keep a separate customization

Signed-off-by: Juan David <juand.business@gmail.com>

* specific service for fetch  authenticated user

Signed-off-by: Juan David <juand.business@gmail.com>

* Update comment

Signed-off-by: Juan David <juand.business@gmail.com>

* Add some comments

Signed-off-by: Juan David <juand.business@gmail.com>
This commit is contained in:
Juan David Landazabal 2020-07-28 10:18:18 +03:00 committed by GitHub
parent 16b91851db
commit 55f576bd1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -16,8 +16,10 @@ module.exports = async (ctx, next) => {
throw new Error('Invalid token: Token did not contain required fields');
}
ctx.state.user = await strapi.plugins['users-permissions'].services.user.fetch({ id });
// fetch authenticated user
ctx.state.user = await strapi.plugins[
'users-permissions'
].services.user.fetchAuthenticatedUser(id);
} catch (err) {
return handleErrors(ctx, err, 'unauthorized');
}

View File

@ -61,10 +61,18 @@ module.exports = {
* Promise to fetch a/an user.
* @return {Promise}
*/
fetch(params, populate = ['role']) {
fetch(params, populate) {
return strapi.query('user', 'users-permissions').findOne(params, populate);
},
/**
* Promise to fetch authenticated user.
* @return {Promise}
*/
fetchAuthenticatedUser(id) {
return strapi.query('user', 'users-permissions').findOne({ id }, ['roles']);
},
/**
* Promise to fetch all users.
* @return {Promise}